From fb4c984f1560b9900eff7accc1a9521ab35ebdf9 Mon Sep 17 00:00:00 2001 From: Al Date: Mon, 28 Dec 2015 01:20:23 -0500 Subject: [PATCH] [math] sparse_matrix_new_shape --- src/sparse_matrix.c | 12 ++++++++---- src/sparse_matrix.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sparse_matrix.c b/src/sparse_matrix.c index a884ef41..831dee0d 100644 --- a/src/sparse_matrix.c +++ b/src/sparse_matrix.c @@ -1,12 +1,12 @@ #include "sparse_matrix.h" #include "klib/ksort.h" -sparse_matrix_t *sparse_matrix_new(void) { +sparse_matrix_t *sparse_matrix_new_shape(size_t m, size_t n) { sparse_matrix_t *matrix = malloc(sizeof(sparse_matrix_t)); if (matrix == NULL) return NULL; - matrix->m = 0; - matrix->n = 0; - matrix->indptr = uint32_array_new_size(1); + matrix->m = m; + matrix->n = n; + matrix->indptr = uint32_array_new_size(m + 1); if (matrix->indptr == NULL) { goto exit_sparse_matrix_created; } @@ -29,6 +29,10 @@ exit_sparse_matrix_created: return NULL; } +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; diff --git a/src/sparse_matrix.h b/src/sparse_matrix.h index 36ae07a7..f8579833 100644 --- a/src/sparse_matrix.h +++ b/src/sparse_matrix.h @@ -56,6 +56,7 @@ typedef struct { sparse_matrix_t *sparse_matrix_new(void); +sparse_matrix_t *sparse_matrix_new_shape(size_t m, size_t n); void sparse_matrix_destroy(sparse_matrix_t *self); void sparse_matrix_clear(sparse_matrix_t *self);