Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying Array Contents with vDSP

I'm using the accelerate framework to optimize my DSP code. There are several times when I want to copy the contents of one array (or portion of an array) to another.

I can't seem to find an appropriate function to do this, so instead I've been doing something kind of silly, which is to multiply the array by 1 (or add 0) and get the copy that 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);

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

like image 891
olynoise Avatar asked Dec 04 '22 12:12

olynoise


2 Answers

If you're willing to use the BLAS portion of Accelerate, Jeff Biggus has benchmarked cblas_scopy() as being faster than even memcpy().

like image 168
Brad Larson Avatar answered Dec 15 '22 12:12

Brad Larson


How about memcpy?

#include <string.h>

memcpy(destArray, sourceArray, arrayLength * sizeof(float));
like image 44
danh Avatar answered Dec 15 '22 11:12

danh