Skip to content

Commit

Permalink
spzeros tuple construction (#39886)
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon committed Mar 3, 2021
1 parent 79d7683 commit 21762f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,12 @@ function spzeros(::Type{Tv}, ::Type{Ti}, m::Integer, n::Integer) where {Tv, Ti}
((m < 0) || (n < 0)) && throw(ArgumentError("invalid Array dimensions"))
SparseMatrixCSC(m, n, fill(one(Ti), n+1), Vector{Ti}(), Vector{Tv}())
end
# de-splatting variant
# de-splatting variants
function spzeros(::Type{Tv}, ::Type{Ti}, sz::Tuple{Integer,Integer}) where {Tv, Ti}
spzeros(Tv, Ti, sz[1], sz[2])
end
spzeros(::Type{Tv}, sz::Tuple{Integer,Integer}) where {Tv} = spzeros(Tv, Int, sz[1], sz[2])
spzeros(sz::Tuple{Integer,Integer}) = spzeros(Float64, Int, sz[1], sz[2])

import Base._one
function Base._one(unit::T, S::AbstractSparseMatrixCSC) where T
Expand Down
3 changes: 3 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ end

@testset "spzeros de-splatting" begin
@test spzeros(Float64, Int64, (2, 2)) == spzeros(Float64, Int64, 2, 2)
@test spzeros(Float64, Int32, (2, 2)) == spzeros(Float64, Int32, 2, 2)
@test spzeros(Float32, (3, 2)) == spzeros(Float32, Int, 3, 2)
@test spzeros((3, 2)) == spzeros((3, 2)...)
end

@testset "conversion to AbstractMatrix/SparseMatrix of same eltype" begin
Expand Down

0 comments on commit 21762f2

Please sign in to comment.