Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom show function for DynamicSparceVectors #39

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function Base.setindex!(v::DynamicSparseVector, value, key)
return setindex!(v.pma, value, key)
end

Base.show(io::IO, v::DynamicSparseVector) = show(io, v.pma)
Base.filter(f, v::DynamicSparseVector) = filter(f, v.pma)

function Base.:(==)(v1::DynVec, v2::DynVec) where {DynVec<:DynamicSparseVector}
Expand All @@ -107,4 +106,16 @@ function SparseArrays.nonzeros(v::DynamicSparseVector{K,T}) where {K,T}
end
return collection
end
end
end

function Base.show(io::IO, v::DynamicSparseVector{K,T}) where {K,T}
@show(v.pma)
print(io, "[")
for (elmt) in v.pma.array
if !isnothing(elmt)
(k,t) = elmt
print(io, " ($(k),$(t)) ")
end
end
println(io, "]")
end
7 changes: 7 additions & 0 deletions test/unit/display.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function test_vec_display()
I2 = ['a', 'c', 'e']
V2 = [1, 1, 1]
vec = DynamicSparseArrays.dynamicsparsevec(I2, V2)
@show vec
end

7 changes: 6 additions & 1 deletion test/unit/unitests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include("rebalance.jl")
include("comparison.jl")
include("views.jl")
include("spmv.jl")
include("display.jl")

function unit_tests()
@testset "Moves - unit tests" begin
Expand Down Expand Up @@ -50,5 +51,9 @@ function unit_tests()
@testset "Sparse Matrix Vector Multiplication" begin
test_spmv()
end
return

@testset "Sparse vector display" begin
test_vec_display()
end
return
end