Skip to content

Commit

Permalink
SparseVector constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 29, 2024
1 parent f5abb09 commit 9fe96e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SparseVector(n::Integer, nzind::Vector{Ti}, nzval::Vector{Tv}) where {Tv,Ti} =
SparseVector{Tv,Ti}(n, nzind, nzval)

SparseVector{Tv, Ti}(::UndefInitializer, n::Integer) where {Tv, Ti} = SparseVector{Tv, Ti}(n, Ti[], Tv[])
SparseVector{Tv, Ti}(::UndefInitializer, (n,)::Tuple{Integer}) where {Tv, Ti} = SparseVector{Tv, Ti}(n, Ti[], Tv[])

"""
FixedSparseVector{Tv,Ti<:Integer} <: AbstractCompressedVector{Tv,Ti}
Expand Down
12 changes: 8 additions & 4 deletions test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ end
end

@testset "Undef initializer" begin
v = SparseVector{Float32, Int16}(undef, 4)
@test size(v) == (4, )
@test eltype(v) === Float32
@test v == spzeros(Float32, 4)
sz = (4,)
for v in (SparseVector{Float32, Int16}(undef, sz),
SparseVector{Float32, Int16}(undef, sz...),
similar(SparseVector{Float32, Int16}, sz))
@test size(v) == sz
@test eltype(v) === Float32
@test v == spzeros(Float32, sz...)
end
end
end
### Element access
Expand Down

0 comments on commit 9fe96e6

Please sign in to comment.