Skip to content

Commit

Permalink
add DynamicSparceVector display (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
najaverzat authored Apr 20, 2023
1 parent 97a0b35 commit d668335
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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

0 comments on commit d668335

Please sign in to comment.