Copying an array using vDSP

I use acceleration view to optimize DSP code. There are several times when I want to copy the contents of one array (or part of an array) to another.

I cannot find a suitable function for this, so instead I did something stupid to multiply the array by 1 (or add 0) and get a copy this way.

float one = 1; float sourceArray = new float[arrayLength]; /////....sourceArray is filled up with data float destArray = new float[arrayLength]; vDSP_vsmul(sourceArray, 1, &one, destArray, 1, arrayLength); 

should there be a better way to do this !? Thanks!

+4
source share
5 answers

What about memcpy ?

 #include <string.h> memcpy(destArray, sourceArray, arrayLength * sizeof(float)); 
+7
source

If you want to use the BLAS part of Accelerate, Jeff Biggus compares cblas_scopy() as faster than even memcpy() .

+6
source

I could think of much worse ways that vDSP_vsmul() ; you can also do vvcopysign() .

+1
source

You can use vDSP_vclr and vDSP_vadd as follows:

 int sourceLength = 3; float* source = (float*)malloc(sourceLength * sizeof(float)); // source is filled with data, let 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); 

Or more concise you can also use 'cblas_scopy' as Brad Larson said

 // Init source and destination // We copy source[0, sourceLength] into destination[initialIndex, initialIndex + sourceLength] cblas_scopy(sourceLength, source, 1, (destination+initialIndex), 1); 
0
source

I think this is the best way to copy.

Copy the contents of the submatrix to another submatrix; the only accuracy. https://developer.apple.com/documentation/accelerate/1449950-vdsp_mmov

 func vDSP_mmov(_ __A: UnsafePointer<Float>, _ __C: UnsafeMutablePointer<Float>, _ __M: vDSP_Length, _ __N: vDSP_Length, _ __TA: vDSP_Length, _ __TC: vDSP_Length) 
0
source

All Articles