I jut started playing around with the maple IDE, and I'm surprised how big the compiled code size is. This program below, which is mostly just floating point arithmetic, compiles to over 19k. This seems very large, and I'm wondering why. On the arduino, for comparison, the same code complies to 3.8k.
I'm on mac os x, with maple IDE 0.0.11. Here's the code:
#define N 3
float A[N][N];
float B[N][N];
void setup(){
pinMode(D0, OUTPUT);
}
void loop(){
populateMatrix((float*)A,N);
digitalWrite(D0,HIGH);
invertMatrix3x3((float*)A, (float*)B);
digitalWrite(D0,LOW);
delay(100);
}
int invertMatrix3x3(float *A, float *B){
float det;
B[0] = (A[4] * A[8]) - (A[5] * A[7]);
B[1] = (A[2] * A[7]) - (A[1] * A[8]);
B[2] = (A[1] * A[5]) - (A[2] * A[4]);
B[3] = (A[5] * A[6]) - (A[3] * A[8]);
B[4] = (A[0] * A[8]) - (A[2] * A[6]);
B[5] = (A[2] * A[3]) - (A[0] * A[5]);
B[6] = (A[3] * A[7]) - (A[4] * A[6]);
B[7] = (A[6] * A[1]) - (A[0] * A[7]);
B[8] = (A[0] * A[4]) - (A[1] * A[3]);
//calculate determinant, using some already calculated values
det = (A[0] * B[0]) + (A[1] * B[3]) + (A[2] * B[6]);
//check if determinant==0
if ( abs(det) < .0001 ){
return 0;
}
det = 1.0/det;
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
B[i*3+j] *= det;
}
}
return 1;
}
void populateMatrix(float *A, int n){
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
A[i*n+j] = (float)random(100) / (float)random(1,100);
}
}
}