vDSP_vclr
次のように使用できますvDSP_vadd
。
int sourceLength = 3;
float* source = (float*)malloc(sourceLength * sizeof(float));
// source is filled with data, let's say [5, 5, 5]
int destinationLength = 10;
float* destination = (float*)malloc(destinationLength * sizeof(float));
// destination is filled with ones so [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
// Prepare the destination array to receive the source array
// by setting its values to 0 in the range [initialIndex, initialIndex + N-1]
int initialIndex = 2;
vDSP_vclr((destination+initialIndex), 1, sourceLength);
// We add source[0, N-1] into destination[initialIndex, initialIndex + N-1]
vDSP_vadd(source, 1, (destination+initialIndex), 1, (destination+initialIndex), 1, sourceLength);
または、もっと簡潔に、ブラッド・ラーソンが言ったように「cblas_scopy」を使用することもできます
// Init source and destination
// We copy source[0, sourceLength] into destination[initialIndex, initialIndex + sourceLength]
cblas_scopy(sourceLength, source, 1, (destination+initialIndex), 1);