2024-10-04 01:03:39 +02:00
|
|
|
#include <stddef.h>
|
2024-09-26 14:32:20 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2024-10-04 01:03:39 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
void print_matrix(const uint64_t row_length, const uint64_t column_length, const uint64_t matrix[row_length][column_length]) {
|
2024-10-03 12:48:22 +02:00
|
|
|
for (uint64_t column_index=0; column_index < column_length; column_index++) {
|
|
|
|
for (uint64_t row_index=0; row_index < row_length; row_index++) {
|
2024-09-26 14:32:20 +02:00
|
|
|
printf("%lu ", matrix[row_index][column_index]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2024-10-03 12:48:22 +02:00
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
int matrix_multiply_basic(const uint64_t row_length1, const uint64_t column_length1, const uint64_t matrix1[row_length1][column_length1],
|
|
|
|
const uint64_t row_length2, const uint64_t column_length2, const uint64_t matrix2[row_length2][column_length2],
|
2024-10-03 12:48:22 +02:00
|
|
|
uint64_t output_matrix[row_length1][column_length2]) {
|
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
if (row_length1 != column_length2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < row_length1; i++) {
|
|
|
|
for(uint64_t j = 0; j < column_length2; j++) {
|
|
|
|
uint64_t sum = 0;
|
|
|
|
|
|
|
|
for (uint64_t k = 0; k <row_length1; k++) {
|
|
|
|
sum += matrix1[i][k] * matrix2[k][j];
|
|
|
|
}
|
|
|
|
|
|
|
|
output_matrix[i][j] = sum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_csv(const char *file_name, const uint64_t row_length, const uint64_t column_length, uint64_t output_matrix[row_length][column_length]) {
|
|
|
|
FILE *file_ptr;
|
|
|
|
uint32_t bufsize = row_length*2; // have to account for delimiters
|
|
|
|
char file_line[bufsize];
|
|
|
|
|
|
|
|
file_ptr = fopen(file_name, "r");
|
|
|
|
if (file_ptr == NULL) {
|
|
|
|
printf("Unable to open csv\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2024-10-04 01:04:47 +02:00
|
|
|
for (uint64_t column_index = 0; column_index < column_length; column_index++) {
|
2024-10-04 01:03:39 +02:00
|
|
|
printf("row_index: %lu\n", column_index);
|
|
|
|
|
|
|
|
if (fgets(file_line, bufsize, file_ptr) == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
char *bruh = strtok(file_line, ";,");
|
|
|
|
|
2024-10-04 01:04:47 +02:00
|
|
|
for(uint64_t row_index = 0; row_index < row_length; row_index++) {
|
2024-10-04 01:03:39 +02:00
|
|
|
if (bruh == NULL) {
|
|
|
|
printf("Fuck You!!!");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf("column_index: %lu, bruh: %lu\n", row_index, strtoul(bruh, NULL, 0));
|
|
|
|
bruh = strtok(NULL, ";,");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2024-10-04 01:04:47 +02:00
|
|
|
// uint64_t row_index = 0;
|
|
|
|
// uint64_t column_index = 0;
|
2024-10-04 01:03:39 +02:00
|
|
|
// while (fgets(file_line, bufsize, file_ptr)) {
|
|
|
|
// row_index = 0;
|
|
|
|
// char *bruh = strtok(file_line, ";,");
|
|
|
|
//
|
|
|
|
// while (bruh) {
|
|
|
|
// output_matrix[row_index][column_index] = strtoul(bruh, NULL, 0);
|
|
|
|
// printf("column_index: %lu, bruh: %s\n", row_index, bruh);
|
|
|
|
// bruh = strtok(NULL, ";,");
|
|
|
|
// row_index++;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// printf("row_index: %lu\n", column_index);
|
|
|
|
// column_index++;
|
|
|
|
// }
|
|
|
|
|
|
|
|
fclose(file_ptr);
|
2024-10-03 12:48:22 +02:00
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
return 0;
|
2024-10-03 12:48:22 +02:00
|
|
|
}
|