Compiles with GNU GCC but not with arduino

Hello, i have a very light question, i just coded some simple stuff with my editor and ran it with GNU GCC compiler it runs no problem and even displays the correct output, lol ;).

However, when i try to verify my sketch on arduino it threw a fit saying:

'a' was not defined in this scope, help would be nice :wink:

I moved array a before setup(){} and it works but now as expected the following error occurs:

cannot convert 'float*' to 'float ()[25]' for argument '1' to 'float dot_product(float ()[25], float*)'

PS: I deleted some numbers from the a[][] matrix because of 9000 characters limit on this website, it is a 25X25

code is

#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);

void setup() {
    pinMode(8,OUTPUT);
   

float a[25][25] = {{0.0012019668520749916, -1.9987980437928745, -3.9989889335962014, -1.9987980440139381, 8.0, 8.001201966852246, -8.000190950917027, 3.9998091305001817, -1.9987981256522025, 4.0, 10.001201966852246, -1.9985164809315392, -1.9987073196535012, -3.9987981254310547, 6.0, 5.999718447684119, 2.210665577259031e-10, 1.9998090796398578, -3.998798043792964, 8.0, 7.999718447684119, -0.00028163405408382564, -0.000472472776042146, -3.9987981254310547, 4.0}
,{-2.000198617890868, -0.00024532568701154305, 3.943182537567764, 5.9997546743172325, -8.719139887530767e-05, -4.00019861789105, -0.056665552025368084, -8.003994911684863, 1.9471712253809066, -4.000087191400265, -2.000198617890868, 9.99991280859075, 5.995964604546767, 7.9470840339773305, 1.9999128086012905, -6.000198617891049, -4.461671592459044e-12, -10.056618844385408, 3.999841865711902, -8.719139887530767e-05, -4.000198617891049, -0.05286925823082601, -0.056817462280675385, 3.947084033977601, -4.000087191400265}
,{-4.285942253635027, 3.714057722589514, -1.168382530803739, 7.714057722589407, -6.285940957208037, -6.285942253635027, 1.1175596993600136, -6.882440249348872, -1.3714932514324142e-06, -6.285940957208037, -4.285942253635027, 3.7140589646816182, 2.8316187389558776, 5.7140576712985105, -4.285940957208047, -8.285942175524617, -2.0, -4.882440277016962, 1.999998679797842, -6.285940957208037, -2.285942175524573, 5.714057773184629, 4.831617547458471, 9.714057671298384, -2.2859409572082687}
,{-2.0349813094195577, 5.965016842889686, 7.257233510827803, -0.03498315711024139, -4.0349813094516085, -4.0349813094198375, -0.707787027443269, -8.707787026506796, 1.9999981513954839, -4.0349813094516085, -2.0349813094195577, 5.96501869054839, 1.2572335117319342, 7.96501684195412, -2.034981309451149, -6.0349813094198606, 0.0, -6.70778517975267, 3.9999981523690935, -4.0349813094516085, -4.0349813094198606, 3.9650186896445656, 3.2572335108277857, 7.96501684195412, -4.0349813094516085}
,{8.22836593742928, 0.22836593733754654, -5.771648770989937, -3.771634061289218, 0.0, 6.228365937430333, -6.000014708000456, 1.9999852933208233, -3.771634061236476, 6.0, 8.22836593742928, -0.0849211771108881, -0.08493588532674058, -1.7716340626105154, 8.0, 4.31328711316961, -2.0000000013737735, -1.470816379749894e-05, -5.771634062662378, 10.0, 6.31328711316961, -1.6867128881500433, -1.6867275963657462, -5.771634062610359, 6.0}
,{8.475735612788093, -3.5242635976279604, -5.5262952528818445, -3.524263597624668, 5.999997076411338, 0.4757356127890937, -6.002030071859117, 5.997969903936958, 0.4757393501820664, 1.9999970763995, 8.475735612788093, -4.000004031812113, -4.0020349195800184, -5.524263573421064, 3.999997076400426, 8.475736721001038, 1.9999999999951212, 3.9979691364441394, -1.5242606740287474, 5.999997076411338, 6.47573672100323, -1.524263254792969, -1.526294142556725, -5.524263573421064, 1.9999970763995}
,{-8.000000411881933, -1.5873280005092412, -1.1773400610977385, -2.801107469869931, -6.0, -6.000000411881902, -1.2939227377922702, -2.9731636352561206, -2.955378920961178, -2.0, -8.000000411881933, 0.04821957327367338, -0.20427603422121535, -0.4317330120032989, -8.0, -4.000000000003863, 3.213779469360672, -1.096900618988936, 0.41267199949077255, -6.0, -6.000000000003863, 1.2038149736541648, 0.9513193661592753, -0.4317330120032989, -2.0}
,{3.9999999386197005, -8.00000006126328, -5.999866108504608, -8.00000006126328, 2.0000000050775637, 5.9999999386446285, -1.999866047118008, 0.00013396011452082243, -7.375394097556103e-08, 2.0000000050775637, 3.9999999386197005, -7.999999995118796, -3.9998660347507453, -10.0000000684963, 5.1346956677040895e-09, 7.999999938644626, 2.0, 8.000133952882607, -2.0000000665329476, 2.0000000050775637, 5.999999938644626, -2.000000068610229, -1.9998661085046383, -6.000000068585451, 2.0000000050775637}
,{-1.8749115382013906, -0.01975638816909277, 0.8845412714562167, 0.10837335866429558, -4.000000000000878, 0.12508846179878724, -4.062184537515016, -2.775376377167057, -0.7332837000836484, -4.000000000000878, -1.8749115382013906, 0.40946689150512217, -3.5900534726167335, -2.0199241243011716, -2.000000000000906, 2.2708713797461813, 3.8718702531671236, -1.9996881002579108, 5.980243611832043, -4.000000000000878, -3.7291286202538187, -5.174046546932169, -5.173566911054162, -2.0199241243011716, -8.000000000000837}
,{4.029920906522504, -3.9700790942848942, -5.969983156759071, -3.970079094285068, 6.029920918819627, 2.0299209065226584, -1.9999040640910672, 2.000096029542421, -4.0000001065221475, 0.029920918819602522, 4.029920906522504, -3.9700790811800015, -3.96998305082904, -1.9700791879189936, 4.029920918819627, 4.029920906522193, -1.9999999999999922, 4.000095936717291, -6.000000013171889, 6.029920918819627, 2.0299209065224266, -1.9700791871112724, -1.9699831567603456, -5.970079187919154, 6.029920918819627}
,{9.998637703460723, -2.0013622948438967, -4.001852241499897, -2.0013622944941174, 8.0, 7.99863770346017, -8.000489903543945, 3.999510059922645, -2.0013622576084535, 4.0, -0.001362296539872782, -2.001520403661127, -2.002010365645162, -4.001362257959004, 6.0, 6.000158106891126, -3.498920439180937e-10, 1.9995100749008572, -4.001362294843738, 8.0, 8.0001581068915, 0.0001581435457899303, -0.00033181843812261306, -4.001362257959004, 4.0}
,{-2.0000845943424315, 9.999915404522888, 3.964932579938217, 5.999915404526037, -8.460640715242439e-05, -4.000084594343546, -0.03498282685516006, -8.00439755386421, 1.969414737948824, -4.000084606406817, -2.0000845943424315, -8.460641249598371e-05, 5.99551784085363, 7.969330131536358, 1.999915393592937, -6.000084594343545, -5.335394894492574e-12, -10.034982825720094, 4.000000011081289, -8.460640715242439e-05, -4.000084594343545, -0.030669867333308058, -0.0350674200674141, 3.969330131536211, -4.000084606406817}
,{-2.4683302917934844, 3.0537685298841395, 1.653871728593556, -0.2914858296734035, -0.3900092950305507, -4.468330291793478, -1.717898361178377, -4.935958130393327, -5.745093478020016, -4.390009295022635, -2.4683302917934844, 5.003452144889003, -0.999145257744781, 0.06836276302435271, 1.6099907049710225, -6.399375022096993, -4.654745640442341, -6.988003169494602, -2.5562221750853626, -0.3900092950305507, -0.39937502210513454, -1.9223640793574834, -1.9249614819907728, 0.06836276302435271, -0.3900092950305507}};

float b[25]={1.440847093130883,
0.8211248474417036,
0.4864520262381797,
0.7435340402106193,
-0.6152339181380717,
-0.315900621543923,
-0.15054762296448168,
-1.8261344467069627,
1.5542846314630068};



  for(int m=0; m<8000; m++){
    if(a[m] >= 0 ){
      digitalWrite(8,HIGH);
      delay(100);
    }
    else{
      digitalWrite(8,LOW);
      delay(100);
    }
  }
  
}

 
void loop() {


  

}


float sigmoid(float x)
{
     float exp_value;
     float return_value;

     /*** Exponential calculation ***/
     exp_value = exp((float) -x);

     /*** Final sigmoid value ***/
     return_value = 1 / (1 + exp_value);

     return return_value;
}

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;
    }
}
float dot_p(double k[], float l[]){
  float result = 0.0;
  for (int s = 0; s<25 ; s++){
    result += k[s]*l[s];

  }
  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);

    }

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

    }


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

    return output;

}

How large is a[][] in bytes, and how does that compare with the amount of memory in the Arduino you are using?

How many dimensions does a have?

if(a[m] >= 0 ){

Note that 'a[][]' is defined in the function setup() and is not visible to other functions.

2500 2600 bytes of array?
On the stack?

What are you trying to run this on?

jremington:
How large is the array a in bytes, and how does that compare with the amount of memory in the Arduino you are using?

How many dimensions does a have?

if(a[m] >= 0 ){

it has two dimensions 25 X 25

AWOL:
2500 2600 bytes of array?
On the stack?

What are you trying to run this on?

Sketch uses 1668 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 45 bytes (2%) of dynamic memory, leaving 2003 bytes for local variables. Maximum is 2048 bytes.

UNO

it has two dimensions 25 X 25

So why are you referring to only one in the highlighted expression?

Other than that, you don't see a problem allocating 2600 bytes of RAM on the stack?

I moved array a before setup(){} and it works but now as expected the following error occurs:

DO NOT EDIT your original post, as it makes the following replies very confusing for others to read.

jremington:
DO NOT EDIT your original post, as it makes the following replies very confusing for others to read.

Of course, i am very sorry.

AWOL:
So why are you referring to only one in the highlighted expression?

Other than that, you don't see a problem allocating 2600 bytes of RAM on the stack?

I am trying to get the dot product for 1 row at a time, because thats the way its done in c?

  for(int m=0; m<8000; m++){
    if(a[m] >= 0 ){

'a' is a 25x25 array.
'm' is a for loop index, running from zero to 7999.

What is a[m] supposed to be?

The UNO cannot store an array that size in RAM memory.

Use 2D array indexing to do your calculations.

AWOL:

  for(int m=0; m<8000; m++){

if(a[m] >= 0 ){


'a' is a 25x25 array.
'm' is a for loop index, running from zero to 7999.

What is a[m] supposed to be?

yes that was old code, even when removed it is still displaying

cannot convert 'float*' to 'float ()[25]' for argument '1' to 'float dot_product(float ()[25], float*)'

float dot_product(float v[][25], float u[])
lm[k]= dot_product(a[k],x);

You promised you'd send a 2 D array, and sent only a 1 D

jremington:
The UNO cannot store an array that size in RAM memory.

Use 2D array indexing to do your calculations.

can you elaborate a little bit more, or point me in a direction i can go on?

A Uno has 2048 bytes of RAM for everything: stack, heap, globals.

Reduce the size of your array, or keep it in flash.