gpt4 book ai didi

ios - 加速框架 "sign"函数

转载 作者:行者123 更新时间:2023-11-29 02:05:52 26 4
gpt4 key购买 nike

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

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() “复制一个数组,根据第二个数组设置每个值的符号。”

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

关于ios - 加速框架 "sign"函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com