From 12a3994199bcf16982a6a3b2477bf6c23a3d610a Mon Sep 17 00:00:00 2001 From: Guillaume Marques Date: Thu, 28 Sep 2023 16:45:43 +0200 Subject: [PATCH] fix show matrix (#49) * fix show matrix * throw --- src/matrix.jl | 23 +++++++++++------------ src/pcsr.jl | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/matrix.jl b/src/matrix.jl index 649e0cf..4f1f869 100644 --- a/src/matrix.jl +++ b/src/matrix.jl @@ -139,17 +139,16 @@ function Base.show(io::IO, matrix::DynamicSparseMatrix{K,L,T}) where {K,L,T} pma = matrix.colmajor.pcsc.pma semaphores = matrix.colmajor.pcsc.semaphores col_keys = matrix.colmajor.col_keys - tmp = 0 + j = nothing for (index, elmt) in enumerate(pma.array) - if index in semaphores - tmp += 1 - print(io, "\n") - else - if !isnothing(elmt) - j = col_keys[tmp] - (i, value) = elmt - println(io, " [$(j), $(i)] = $(value) ") - end - end - end + # TODO: improve performance because a semaphore has a special value so we don't + # need to call findfirst when elmt is not a semaphore. + sem_pos = findfirst(x -> x == index, semaphores) + if !isnothing(sem_pos) + j = col_keys[sem_pos] + elseif !isnothing(elmt) + (i, value) = elmt + println(io, " [$(i), $(j)] = $(value) ") + end + end end \ No newline at end of file diff --git a/src/pcsr.jl b/src/pcsr.jl index b64759b..1126f1b 100644 --- a/src/pcsr.jl +++ b/src/pcsr.jl @@ -204,7 +204,7 @@ end function deletecolumn!(mpcsc::MappedPackedCSC{K,L,T}, col::L) where {K,L,T} col_pos, col_key = find(mpcsc.col_keys, col) - col_key != col && throws(ArgumentError("column $(col) does not exist.")) + col_key != col && throw(ArgumentError("column $(col) does not exist.")) mpcsc.col_keys[col_pos] = nothing deletepartition!(mpcsc.pcsc, col_pos) return true