Skip to content

Commit

Permalink
Final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brucehow committed Sep 24, 2019
1 parent d184c61 commit f9e125c
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 164 deletions.
9 changes: 6 additions & 3 deletions format.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct COO coo_format(int rows, int cols, enum VAR_TYPE type, char *data) {
matrix.cols = cols;
matrix.type = type;
matrix.count = 0;
errno = 0;

// Data reading variables
int len, pos = 0;
Expand Down Expand Up @@ -38,6 +37,7 @@ struct COO coo_format(int rows, int cols, enum VAR_TYPE type, char *data) {

// Zero value filter
if (type == TYPE_INT) {
errno = 0;
int value = strtoimax(val, NULL, 10);
if (errno == EINVAL) {
fprintf(stderr, "Invalid value in matrix data '%s'\n", val);
Expand All @@ -57,6 +57,7 @@ struct COO coo_format(int rows, int cols, enum VAR_TYPE type, char *data) {
matrix.elements[matrix.count++].y = j;
}
} else {
errno = 0;
double value = strtod(val, NULL);
if (errno == ERANGE) {
fprintf(stderr, "matrix: failed to convert scalar value '%s' to double\n", val);
Expand Down Expand Up @@ -99,7 +100,6 @@ struct CSR csr_format(int rows, int cols, enum VAR_TYPE type, char *data) {
matrix.cols = cols;
matrix.count = 0;
matrix.type = type;
errno = 0;

// Data reading variables
int len, pos = 0;
Expand Down Expand Up @@ -128,6 +128,7 @@ struct CSR csr_format(int rows, int cols, enum VAR_TYPE type, char *data) {

// Zero value filter
if (type == TYPE_INT) {
errno = 0;
int value = strtoimax(val, NULL, 10);
if (errno == EINVAL) {
fprintf(stderr, "matrix: invalid value in matrix data '%s'\n", val);
Expand All @@ -148,6 +149,7 @@ struct CSR csr_format(int rows, int cols, enum VAR_TYPE type, char *data) {
matrix.ja[matrix.count++] = j;
}
} else {
errno = 0;
double value = strtod(val, NULL);
if (errno == ERANGE) {
fprintf(stderr, "matrix: failed to convert scalar value '%s' to double\n", val);
Expand Down Expand Up @@ -192,7 +194,6 @@ struct CSC csc_format(int rows, int cols, enum VAR_TYPE type, char *data) {
matrix.cols = cols;
matrix.count = 0;
matrix.type = type;
errno = 0;

// Data reading variables
int len, pos = 0;
Expand Down Expand Up @@ -222,6 +223,7 @@ struct CSC csc_format(int rows, int cols, enum VAR_TYPE type, char *data) {
pos++; // Move to next val

// Zero value filter and conversion
errno = 0;
int value = strtoimax(val, NULL, 10);
if (errno == EINVAL) {
fprintf(stderr, "matrix: invalid value in matrix data '%s'\n", val);
Expand Down Expand Up @@ -275,6 +277,7 @@ struct CSC csc_format(int rows, int cols, enum VAR_TYPE type, char *data) {
val[len] = '\0';
pos++; // Move to next val

errno = 0;
double value = strtod(val, NULL);
if (errno == ERANGE) {
fprintf(stderr, "matrix: failed to convert scalar value '%s' to double\n", val);
Expand Down
6 changes: 3 additions & 3 deletions matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "matrix: the addition routine should only be performed on matrices of identical variable types\n");
exit(EXIT_FAILURE);
}
struct CSR adresult;
struct COO adresult;

gettimeofday(&start, NULL);
if (ad1.type == TYPE_INT) {
Expand All @@ -350,7 +350,7 @@ int main(int argc, char *argv[]) {
}
write_details(output, filename, filename2, rows, cols, routine.type, adresult.type);
if (!silent) {
write_csr_data(output, adresult);
write_coo_data(output, adresult);
}
write_times(output, load_time, routine_time);
printf("matrix: successfully logged results to '%s'\n", output_file);
Expand All @@ -359,7 +359,7 @@ int main(int argc, char *argv[]) {
} else {
write_details(stdout, filename, filename2, rows, cols, routine.type, adresult.type);
if (!silent) {
write_csr_data(stdout, adresult);
write_coo_data(stdout, adresult);
}
write_times(stdout, load_time, routine_time);
}
Expand Down
4 changes: 2 additions & 2 deletions matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extern double trace_f(struct CSR matrix);
* @param matrix2 The second matrix
* @return struct CSR The resulting added matrix
*/
extern struct CSR matrix_addition(struct CSR matrix1, struct CSR matrix2);
extern struct COO matrix_addition(struct CSR matrix1, struct CSR matrix2);

/**
* Performs matrix addition on two given float matrices
Expand All @@ -142,7 +142,7 @@ extern struct CSR matrix_addition(struct CSR matrix1, struct CSR matrix2);
* @param matrix2 The second matrix
* @return struct CSR The resulting added matrix
*/
extern struct CSR matrix_addition_f(struct CSR matrix, struct CSR matrix2);
extern struct COO matrix_addition_f(struct CSR matrix, struct CSR matrix2);

/**
* Transposes a given matrix
Expand Down
Loading

0 comments on commit f9e125c

Please sign in to comment.