Skip to content

Commit

Permalink
recognize Adjoint/Transpose of sparse arrays as sparse (#34266)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored Jan 8, 2020
1 parent 7afbb05 commit 8a19ef8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/SparseArrays/src/abstractsparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ false
"""
issparse(A::AbstractArray) = false
issparse(S::AbstractSparseArray) = true
issparse(S::LinearAlgebra.Adjoint{<:Any,<:AbstractSparseArray}) = true
issparse(S::LinearAlgebra.Transpose{<:Any,<:AbstractSparseArray}) = true

issparse(S::LinearAlgebra.Symmetric{<:Any,<:AbstractSparseMatrix}) = true
issparse(S::LinearAlgebra.Hermitian{<:Any,<:AbstractSparseMatrix}) = true
Expand Down
9 changes: 9 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,8 @@ end
@test issparse(LinearAlgebra.UnitLowerTriangular(m))
@test issparse(UpperTriangular(m))
@test issparse(LinearAlgebra.UnitUpperTriangular(m))
@test issparse(adjoint(m))
@test issparse(transpose(m))
@test issparse(Symmetric(Array(m))) == false
@test issparse(Hermitian(Array(m))) == false
@test issparse(LowerTriangular(Array(m))) == false
Expand All @@ -2054,6 +2056,13 @@ end
@test issparse(LinearAlgebra.UnitUpperTriangular(Array(m))) == false
end

@testset "issparse for sparse vectors #34253" begin
v = sprand(10, 0.5)
@test issparse(v)
@test issparse(v')
@test issparse(transpose(v))
end

@testset "test created type of sprand{T}(::Type{T}, m::Integer, n::Integer, density::AbstractFloat)" begin
m = sprand(Float32, 10, 10, 0.1)
@test eltype(m) == Float32
Expand Down

0 comments on commit 8a19ef8

Please sign in to comment.