From 096b9d6ec4c993de9f606c97d62f81f2cd41b4e1 Mon Sep 17 00:00:00 2001 From: Guillaume Marques Date: Thu, 28 Sep 2023 16:41:07 +0200 Subject: [PATCH 1/2] fix show matrix --- src/matrix.jl | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 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 From 648eaa4473e3e22401dc892e368e3b99a09e38d1 Mon Sep 17 00:00:00 2001 From: Guillaume Marques Date: Thu, 28 Sep 2023 16:42:11 +0200 Subject: [PATCH 2/2] throw --- src/pcsr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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