I want to compute:
result = SUM (c=0,N) { V_ck * U_lc * S_c }
But my 2D matrices are indexed as 1D and stored as column major.
I am trying:
float *A,*B;
int M,N;
A = (float *) malloc( M * N * sizeof(float) );
B = (float *) malloc( M * sizeof(float) );
float *S = (float *)malloc( N * sizeof( float) );
float *U = (float *)malloc( M * M * sizeof( float) );
float *V = (float *)malloc( N * N * sizeof( float) );
float * result = (float *) malloc( M * N * sizeof(float) );
float thesum=0;
for (int k=0; k < M ; k++) {
for (int l=0 ; l < N; l++) {
for ( int c=0; c < N; c++) {
thesum += V[ k+c*N ] * S[c] * U[l*M + k];
result[ k+l*M ]=thesum;
}
}
}
I have one big mistake ,I think in the above,because I need another loop ? in order to do properly the multiplication first and then use the:
for ( int c=0; c < N; c++)
Loop for the summation,right?
And then, do I have to create an array which will hold the multiplication values and then use this array to hold the summation values?
If I were using 2D notation , I would simple use U[l][k]
and so on.
But now,I am confused about how to apply the appropriate indices.
And I want someone to explain me how should I proceed with this.