我试图switch/case通过其他工具替换结构做同样的事情,但具有更好的性能(更少的执行时间...),我想到的#ifdef方法,但我不知道如何在这种情况下使用它:
float k_function(float *x,float *y,struct svm_model model)
{
int i;
float sum=0.0;
switch(model.model_kernel_type)
{
case LINEAR :
return result1;
case POLY :
return result2;
case RBF :
return result3;
case SIGMOID :
return result4;
default :
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
PS:
typedef enum kernel_type {LINEAR, POLY, RBF, SIGMOID};
Run Code Online (Sandbox Code Playgroud)