Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon committed Sep 19, 2022
1 parent 80f9561 commit bb83120
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ end
SparseMatrixCSC(m, n, colptr::ReadOnly, rowval::ReadOnly, nzval::Vector) =
SparseMatrixCSC(m, n, copy(parent(colptr)), copy(parent(rowval)), nzval)

"""
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, m::Integer, n::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)

"""
Expand Down
5 changes: 5 additions & 0 deletions test/sparsematrix_constructors_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ 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, 2.0], 2, 2)
@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)
end

@testset "concatenation tests" begin
Expand Down
7 changes: 7 additions & 0 deletions test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ end
end
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)
end
end
### Element access

Expand Down

0 comments on commit bb83120

Please sign in to comment.