加速框架 "sign" 函数
Accelerate framework "sign" function
我正在尝试找到一种超快速的方法来获取向量中每个值的符号。我希望在加速框架中找到一个函数来执行此操作,但找不到。这是它会做的事情:
float *inputVector = .... // some audio vector
int length = ...// length of input vector.
float *outputVector = ....// result
for( int i = 0; i<length; i++ )
{
if( inputVector[i] >= 0 ) outputVector[i] = 1;
else outputVector[i] = -1;
}
好的,我想我找到了一个方法...
vvcopysignf() "Copies an array, setting the sign of each value based on a second array."
因此,一种方法是制作一个 1 数组,然后使用此函数根据输入数组更改 1 的符号。
float *ones = ... // a vector filled with 1's
float *input = .... // an input vector
float *output = ... // an output vector
int bufferSize = ... // size of the vectors;
vvcopysignf(output, ones, input, &bufferSize);
//output now is an array of -1s and 1s based the sign of the input.
我正在尝试找到一种超快速的方法来获取向量中每个值的符号。我希望在加速框架中找到一个函数来执行此操作,但找不到。这是它会做的事情:
float *inputVector = .... // some audio vector
int length = ...// length of input vector.
float *outputVector = ....// result
for( int i = 0; i<length; i++ )
{
if( inputVector[i] >= 0 ) outputVector[i] = 1;
else outputVector[i] = -1;
}
好的,我想我找到了一个方法...
vvcopysignf() "Copies an array, setting the sign of each value based on a second array."
因此,一种方法是制作一个 1 数组,然后使用此函数根据输入数组更改 1 的符号。
float *ones = ... // a vector filled with 1's
float *input = .... // an input vector
float *output = ... // an output vector
int bufferSize = ... // size of the vectors;
vvcopysignf(output, ones, input, &bufferSize);
//output now is an array of -1s and 1s based the sign of the input.