#include "matrix.h" #include #include #include #include #include void print_matrix(const ulong row_length, const ulong column_length, const ulong matrix[row_length][column_length]) { for (ulong column_index=0; column_index < column_length; column_index++) { for (ulong row_index=0; row_index < row_length; row_index++) { printf("%lu ", matrix[row_index][column_index]); } puts(""); } } void gemm_basic(const ulong row_length1, const ulong column_length1, const ulong matrix1[row_length1][column_length1], const ulong row_length2, const ulong column_length2, const ulong matrix2[row_length2][column_length2], ulong output_matrix[row_length1][column_length2]) { ulong sum; for (ulong i = 0; i < row_length1; i++) { for (ulong j = 0; j < column_length2; j++) { sum = 0; for (ulong k = 0; k < row_length1; k++) { sum += matrix1[i][k] * matrix2[k][j]; } output_matrix[i][j] = sum; } } } int read_csv(const char *file_name, const ulong row_length, const ulong column_length, ulong output_matrix[row_length][column_length]) { FILE *file_ptr; ulong bufsize = row_length*2+1; // have to account for delimiters char buffer[bufsize]; char *value, *file_line; ulong row_index = 0, column_index = 0; file_ptr = fopen(file_name, "r"); if (file_ptr == NULL) { puts("Unable to open csv"); return 1; } while ((file_line = fgets(buffer, bufsize, file_ptr)) != NULL) { // This shit is just needed and I dont know why file_line[strcspn(file_line, "\n")] = 0; value = strtok(file_line, ";,"); // for some reason there are two NULLs at the end of a line // and I dont wanna increment the column_index if (value == NULL) { continue; } while (value != NULL) { output_matrix[row_index++][column_index] = strtoul(value, NULL, 0); value = strtok(NULL, ";,"); } row_index = 0; column_index++; } fclose(file_ptr); return 0; }