diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..dc9d715 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +gcc test.c lina.c -o test -Wall -Wextra -g \ No newline at end of file diff --git a/lina.c b/lina.c index 8b9c1bd..e122438 100644 --- a/lina.c +++ b/lina.c @@ -1,14 +1,14 @@ +#include // NULL +#include // assert #include "lina.h" // Evaluate the dot product C = A*B where C is of size m by l, A is m by n and B is n by l. // NOTE: C can't be the same pointer of A or B. -void lina_dot(double **A, double **B, double **C, unsigned int m, unsigned int n, unsigned int l){ +void lina_dot(double *A, double *B, double *C, int m, int n, int l){ - //Control for the sanity of the inputs: - //C must point to a different memory than A and B - if(C == A || C == B) - //Implement some Cozis-like-good-way method for error signaling - return; + assert(m >= 0 && n >= 0 && l >= 0); + assert(A != NULL && B != NULL && C != NULL); + assert(A != C && B != C); //Actual dot //Iteration on A's rows @@ -20,14 +20,11 @@ void lina_dot(double **A, double **B, double **C, unsigned int m, unsigned int n for(int k=0; k < l; k++){ //Iteration on the single B collumn for executing the product of sum - for(int j=0; j < n; j++){ - - pos = pos + A[i][j] * B[j][k]; - - } + for(int j=0; j < n; j++) + pos += A[i * n + j] * B[j * l + k]; //The usage of a support variable 'pos' is for safety purpose (non-zero C matrix) - C[i][k] = pos; + C[i*l+k] = pos; } @@ -37,34 +34,34 @@ void lina_dot(double **A, double **B, double **C, unsigned int m, unsigned int n // Evaluate C = A + B where A,B,C are m by n. // NOTE: C can be the same location of A or B. -void lina_add(double **A, double **B, double **C, unsigned int m, unsigned int n){ +void lina_add(double *A, double *B, double *C, int m, int n){ - for(int i=0;i= 0 && n >= 0); + assert(A != NULL && B != NULL && C != NULL); + + for(int i = 0; i < m; i++) - for(int j=0;j= 0 && n >= 0); + assert(A != NULL && B != NULL); - for(int j=0;j +#include "lina.h" + +int main() +{ + fprintf(stderr, "There's nothing here yet..\n"); + return 0; +} \ No newline at end of file