Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recognize Adjoint/Transpose of sparse array as sparse #34266

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a test for the sparse matrix adjoint case too, which has the same bug, which I believe this PR should fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ten lines above these. ;-)


@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