read from rb or mtx depending on extension

This commit is contained in:
Sam Hadow 2025-05-14 21:21:45 +02:00
parent 6b1f294d09
commit e128df8724

View File

@ -3,6 +3,7 @@
#include "matrix_operation.h" #include "matrix_operation.h"
#include "sparse_matrix.h" #include "sparse_matrix.h"
#include "read_from_mtx.h" #include "read_from_mtx.h"
#include "read_from_rb.h"
#include "vector.h" #include "vector.h"
#include "power_algorithm.h" #include "power_algorithm.h"
#include "gauss_seidel.h" #include "gauss_seidel.h"
@ -14,7 +15,15 @@ void test_stationary_distribution(const char *path, double epsilon, double alpha
struct timeval tvstart, tvend; struct timeval tvstart, tvend;
gettimeofday(&tvstart, NULL); gettimeofday(&tvstart, NULL);
SparseMatrix *matrix = read_sparse_matrix_from_mtx(path);
SparseMatrix *matrix = NULL;
const char *extension = strrchr(path, '.');
if (extension && strcasecmp(extension, ".rb") == 0) {
matrix = read_sparse_matrix_from_rb(path);
} else {
matrix = read_sparse_matrix_from_mtx(path);
}
convert_to_stochastic(matrix); convert_to_stochastic(matrix);
gettimeofday(&tvend, NULL); gettimeofday(&tvend, NULL);
print_time_diff("Read and convert matrix", &tvstart, &tvend); print_time_diff("Read and convert matrix", &tvstart, &tvend);