From b6ce94166bcce7fff4c27b09109192e8f97f85b4 Mon Sep 17 00:00:00 2001 From: Al Date: Thu, 7 Jan 2016 13:19:22 -0500 Subject: [PATCH] [sparse] Only increase size of sparse matrix on finalize row if it needs to be --- src/sparse_matrix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sparse_matrix.c b/src/sparse_matrix.c index 831dee0d..d3fb6510 100644 --- a/src/sparse_matrix.c +++ b/src/sparse_matrix.c @@ -33,6 +33,7 @@ sparse_matrix_t *sparse_matrix_new(void) { return sparse_matrix_new_shape(0, 0); } + void sparse_matrix_destroy(sparse_matrix_t *self) { if (self == NULL) return; @@ -61,7 +62,9 @@ inline void sparse_matrix_clear(sparse_matrix_t *self) { inline void sparse_matrix_finalize_row(sparse_matrix_t *self) { uint32_array_push(self->indptr, (uint32_t)self->indices->n); - self->m++; + if (self->indptr->n > self->m + 1) { + self->m++; + } } inline void sparse_matrix_append(sparse_matrix_t *self, uint32_t col, double val) {