加速框架“签名”功能

时间:2015-04-22 17:01:29

标签: ios c floating-point accelerate-framework

我正试图找到一种超快速的方法来获取向量中每个值的符号。我希望在加速框架中找到一个函数来执行此操作,但找不到一个。这是它的作用:

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;
}

1 个答案:

答案 0 :(得分:1)

好的,我想我找到了办法...

vvcopysignf()“复制数组,根据第二个数组设置每个值的符号。”

因此,一种方法是创建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.