From 6be338ffd3f3fdcbc273c4284f7f741825eae6c3 Mon Sep 17 00:00:00 2001 From: Emden Gansner Date: Sat, 3 Sep 2016 13:05:16 -0400 Subject: [PATCH] Fix bug in SparseMatrix_copy tries to copy a pattern matrix which does have values. If a matrix is constructed using _from_coordinate_arrays, it calls from_coordinate_arrays_internal with SUM_REPEATED_ALL. The latter function then calls sum_repeated_entries. This causes values to be added to the array Later, if the matrix is passed to make_undirected, this calls symmetrize, which may call _copy. If _copy uses _new, the new array will use the input array's type (pattern) and not create memory values, causing the memcpy to fail. --- lib/sparse/SparseMatrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index d38abe656..c5d37f495 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -2470,7 +2470,7 @@ SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon){ SparseMatrix SparseMatrix_copy(SparseMatrix A){ SparseMatrix B; if (!A) return A; - B = SparseMatrix_new(A->m, A->n, A->nz, A->type, A->format); + B = SparseMatrix_general_new(A->m, A->n, A->nz, A->type, A->size, A->format); MEMCPY(B->ia, A->ia, sizeof(int)*((size_t)(A->m+1))); MEMCPY(B->ja, A->ja, sizeof(int)*((size_t)(A->ia[A->m]))); if (A->a) MEMCPY(B->a, A->a, A->size*((size_t)A->nz)); -- 2.40.0