-1

我有一些用 GNU GCC 编译的 C 代码,但是当我把它放在一个 arduino 草图上时,它说

无法将参数 '1' 的 'const float' 转换为 'float ( )[25]' 到 'float dot_product(float ( )[25], float*)'

在草图中,函数 sigmoid 和 forward 和 dot_p 都已定义,我试图在草图本身上存储一些值,因为我无法将所有值存储在 EEPROM 上,如果你能提供帮助,请提供任何额外的说明

草图如下:

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const float a[25][25] = { A LONG LIST OF NUMBERS arranged in 25X25};

  float b[25]={Another list of numbers};
 void setup() {}

 void loop() {}

 float dot_product(float v[][25], float u[])
{

    for (int j = 0; j< 25; j++){
             float result = 0.0;
    for (int i = 0; i < 25; i++){
        result += u[i]*v[j][i];

    }
    return result;
    }
}
double forward(float x){

    float lm[25];
    double km[25];
    double t=0;
    double output=0;
    for(int i=0; i <25; i++){
        lm[i] = 0;
        km[i] = 0;
    }
    for (int k=0; k<25; k++){
        lm[k]= dot_product(a[k],x);
        /*** THIS IS THE ERROR SOURCE***/


    }

     for (int j=0; j<25;j++){
      km[j] = sigmoid(lm[j]);

    }


    t = dot_p(km,b);
    output = sigmoid(t);

    return output;

}
4

1 回答 1

0

删除所有“不需要”的代码并更正几个小错误后,结果是:

// if you really want 'const', 
// then all references must also be 'const'
float a[25][25];

// the second parameter is from a float value
// not from an array of float values
float dot_product( float v[][25], float u )
{
    // initialize the float variable from a float literal
    // rather than from a double literal
    float result = 0.0f;

    for (int i = 0; i < 25; i++)
    {
        // since the function exits after summing a single
        // row, the 'j' is replaced with 0
        result += u * v[0][i];
    }
    return result;
}


void forward(float x)
{
    float lm = 0.0f;

    for (int k=0; k<25; k++)
    {
        // note: passing address of 'a[k]'
        lm += dot_product( &a[k], x );
    }
}
于 2019-05-19T18:09:56.530 回答