C代码可以编译,但是在arduino草图中却没有

时间:2019-05-19 17:24:27

标签: c++ arduino arduino-c++

我有一些可以用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;

}

1 个答案:

答案 0 :(得分: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 );
    }
}
相关问题