Skip to content

Commit 12a3994

Browse files
authored
fix show matrix (#49)
* fix show matrix * throw
1 parent 09a3c60 commit 12a3994

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/matrix.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,16 @@ function Base.show(io::IO, matrix::DynamicSparseMatrix{K,L,T}) where {K,L,T}
139139
pma = matrix.colmajor.pcsc.pma
140140
semaphores = matrix.colmajor.pcsc.semaphores
141141
col_keys = matrix.colmajor.col_keys
142-
tmp = 0
142+
j = nothing
143143
for (index, elmt) in enumerate(pma.array)
144-
if index in semaphores
145-
tmp += 1
146-
print(io, "\n")
147-
else
148-
if !isnothing(elmt)
149-
j = col_keys[tmp]
150-
(i, value) = elmt
151-
println(io, " [$(j), $(i)] = $(value) ")
152-
end
153-
end
154-
end
144+
# TODO: improve performance because a semaphore has a special value so we don't
145+
# need to call findfirst when elmt is not a semaphore.
146+
sem_pos = findfirst(x -> x == index, semaphores)
147+
if !isnothing(sem_pos)
148+
j = col_keys[sem_pos]
149+
elseif !isnothing(elmt)
150+
(i, value) = elmt
151+
println(io, " [$(i), $(j)] = $(value) ")
152+
end
153+
end
155154
end

src/pcsr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ end
204204

205205
function deletecolumn!(mpcsc::MappedPackedCSC{K,L,T}, col::L) where {K,L,T}
206206
col_pos, col_key = find(mpcsc.col_keys, col)
207-
col_key != col && throws(ArgumentError("column $(col) does not exist."))
207+
col_key != col && throw(ArgumentError("column $(col) does not exist."))
208208
mpcsc.col_keys[col_pos] = nothing
209209
deletepartition!(mpcsc.pcsc, col_pos)
210210
return true

0 commit comments

Comments
 (0)