我编写了一个模板函数,它在math_functions.h文件中使用了另外两个模板函数(add&mul):
template <typename Dtype>
Dtype mulvadd(Dtype* pa, Dtype* pb, int size, Dtype c)
{
Dtype result = Dtype(0);
for (int k = 0; k < size; k++)
{
result = add<Dtype>(result, mul<Dtype>(pa[k],pb[k]));
}
result = add<Dtype>(result, c);
return result;
}
int16_t mulv_int16(int16_t* pa, int16_t* pb, int size);
Run Code Online (Sandbox Code Playgroud)
在math_functions.cpp中,我对add&mul有不同的特化,但对于int16_t类型的mulvadd也有特殊化:
#include <stdint.h>
#include <fix16.h>
template<> float add<float>(float a, float b) { return a + b;}
template<> float mul<float>(float a, float b) { return a*b;}
template<> int16_t add<int16_t>(int16_t a, …Run Code Online (Sandbox Code Playgroud)