[fix] setting array->n after reading in both graph and sparse_matrix implementations

This commit is contained in:
Al
2015-10-06 19:28:28 -04:00
parent 5a231fb709
commit 1e98932b82
2 changed files with 17 additions and 11 deletions

View File

@@ -110,13 +110,14 @@ graph_t *graph_read(FILE *f) {
goto exit_graph_allocated;
}
g->indptr = indptr;
for (int i = 0; i < len_indptr; i++) {
if (!file_read_uint32(f, indptr->a + i)) {
goto exit_graph_allocated;
}
}
indptr->n = (size_t)len_indptr;
g->indptr = indptr;
uint64_t len_indices;
@@ -129,13 +130,15 @@ graph_t *graph_read(FILE *f) {
goto exit_graph_allocated;
}
g->indices = indices;
for (int i = 0; i < len_indices; i++) {
if (!file_read_uint32(f, indices->a + i)) {
goto exit_graph_allocated;
}
}
indices->n = (size_t)len_indices;
g->indices = indices;
return g;
@@ -155,7 +158,7 @@ bool graph_write(graph_t *self, FILE *f) {
return false;
}
uint64_t len_indptr = self->indptr->n;
uint64_t len_indptr = (uint64_t)self->indptr->n;
if (!file_write_uint64(f, len_indptr)) {
return false;

View File

@@ -284,8 +284,6 @@ sparse_matrix_t *sparse_matrix_read(FILE *f) {
goto exit_sparse_matrix_allocated;
}
sp->indptr = indptr;
for (int i = 0; i < len_indptr; i++) {
if (!file_read_uint32(f, indptr->a + i)) {
printf("indptr\n");
@@ -293,6 +291,9 @@ sparse_matrix_t *sparse_matrix_read(FILE *f) {
}
}
indptr->n = (size_t)len_indptr;
sp->indptr = indptr;
uint64_t len_indices;
if (!file_read_uint64(f, &len_indices)) {
@@ -306,8 +307,6 @@ sparse_matrix_t *sparse_matrix_read(FILE *f) {
goto exit_sparse_matrix_allocated;
}
sp->indices = indices;
for (int i = 0; i < len_indices; i++) {
if (!file_read_uint32(f, indices->a + i)) {
printf("indices\n");
@@ -315,6 +314,9 @@ sparse_matrix_t *sparse_matrix_read(FILE *f) {
}
}
indices->n = (size_t)len_indices;
sp->indices = indices;
uint64_t len_data;
if (!file_read_uint64(f, &len_data)) {
@@ -328,8 +330,6 @@ sparse_matrix_t *sparse_matrix_read(FILE *f) {
goto exit_sparse_matrix_allocated;
}
sp->data = data;
for (int i = 0; i < len_data; i++) {
if (!file_read_double(f, data->a + i)) {
printf("data\n");
@@ -337,6 +337,9 @@ sparse_matrix_t *sparse_matrix_read(FILE *f) {
}
}
data->n = (size_t)len_data;
sp->data = data;
return sp;
exit_sparse_matrix_allocated: