From 9fe96e6e2abb363ac79b94454840923cdf92da15 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Mar 2024 16:19:52 +0530 Subject: [PATCH] SparseVector constructors --- src/sparsevector.jl | 1 + test/sparsevector.jl | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index 206a1e06..41498b50 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -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} diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 513028e5..15499e12 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -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