From e58f309b64ffd3c2db64c456860542d7237a000e Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Wed, 21 Dec 2022 12:15:06 +0100 Subject: [PATCH] Allocate correct buffer length in to_hypre_data(::MatrixAssembler) This patch fixes the buffer length in to_hypre_data(::MatrixAssembler). Previously the buffer was always too long, which was not problematic for correctness, but it is unnecessary. This patch also adds some assertions to check the internal consistency of the buffer lengths. --- src/HYPRE.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/HYPRE.jl b/src/HYPRE.jl index c0e706d..e54ab0f 100644 --- a/src/HYPRE.jl +++ b/src/HYPRE.jl @@ -203,6 +203,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSC, ilower, iupper) values[k] = val end end + @assert nrows == length(ncols) == length(rows) return nrows, ncols, rows, cols, values end @@ -233,6 +234,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSR, ilower, iupper) end end @assert nnz == k + @assert nrows == length(ncols) == length(rows) return nrows, ncols, rows, cols, values end @@ -354,6 +356,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSC, r::IndexRange, c::IndexRang values[k] = val end end + @assert nrows == length(ncols) == length(rows) return nrows, ncols, rows, cols, values end @@ -390,6 +393,7 @@ function Internals.to_hypre_data(A::SparseMatrixCSR, r::IndexRange, c::IndexRang end end @assert nnz == k + @assert nrows == length(ncols) == length(rows) return nrows, ncols, rows, cols, values end @@ -633,11 +637,11 @@ end function Internals.to_hypre_data(A::HYPREMatrixAssembler, a::Matrix, I::Vector, J::Vector) size(a, 1) == length(I) || error("mismatching number of rows") - size(a, 2) == length(J) || error("mismatch number of cols") + size(a, 2) == length(J) || error("mismatching number of cols") nrows = HYPRE_Int(length(I)) # Resize cache vectors ncols = resize!(A.ncols, nrows) - rows = resize!(A.rows, length(a)) + rows = resize!(A.rows, nrows) cols = resize!(A.cols, length(a)) values = resize!(A.values, length(a)) # Fill vectors @@ -650,6 +654,7 @@ function Internals.to_hypre_data(A::HYPREMatrixAssembler, a::Matrix, I::Vector, values[idx] = a[i, j] end @assert idx == length(a) + @assert nrows == length(ncols) == length(rows) return nrows, ncols, rows, cols, values end