Skip to content

Commit

Permalink
SparseMatrixCSC constructor with a Tuple of Integers
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 29, 2024
1 parent 78dde4c commit f5abb09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ SparseMatrixCSC(m, n, colptr::ReadOnly, rowval::ReadOnly, nzval::Vector) =

"""
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, m::Integer, n::Integer)
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, (m,n)::NTuple{2,Integer})
Creates an empty sparse matrix with element type `Tv` and integer type `Ti` of size `m × n`.
"""
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, m::Integer, n::Integer) where {Tv, Ti} = spzeros(Tv, Ti, m, n)
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, mn::NTuple{2,Integer}) where {Tv, Ti} = spzeros(Tv, Ti, mn...)

"""
FixedSparseCSC{Tv,Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}
Expand Down
11 changes: 7 additions & 4 deletions test/sparsematrix_constructors_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ end
@test sparse([1, 1, 2, 2, 2], [1, 2, 1, 2, 2], -1.0, 2, 2, *) == sparse([1, 1, 2, 2], [1, 2, 1, 2], [-1.0, -1.0, -1.0, 1.0], 2, 2)
@test sparse(sparse(Int32.(1:5), Int32.(1:5), trues(5))') isa SparseMatrixCSC{Bool,Int32}
# undef initializer
m = SparseMatrixCSC{Float32, Int16}(undef, 3, 4)
@test size(m) == (3, 4)
@test eltype(m) === Float32
@test m == spzeros(3, 4)
sz = (3, 4)
for m in (SparseMatrixCSC{Float32, Int16}(undef, sz...), SparseMatrixCSC{Float32, Int16}(undef, sz),
similar(SparseMatrixCSC{Float32, Int16}, sz))
@test size(m) == sz
@test eltype(m) === Float32
@test m == spzeros(sz...)
end
end

@testset "spzeros for pattern creation (structural zeros)" begin
Expand Down

0 comments on commit f5abb09

Please sign in to comment.