Skip to content

Commit 6f2ac3c

Browse files
committed
Merge pull request #15179 from pkofod/issparse
Address issparse for specialized matrix types part of #13096
2 parents b92f105 + 5668daf commit 6f2ac3c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

base/sparse/abstractsparse.jl

+7
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ Returns `true` if `S` is sparse, and `false` otherwise.
1313
issparse(A::AbstractArray) = false
1414
issparse(S::AbstractSparseArray) = true
1515

16+
issparse{T, A<:AbstractSparseMatrix}(S::Symmetric{T, A}) = true
17+
issparse{T, A<:AbstractSparseMatrix}(S::Hermitian{T, A}) = true
18+
issparse{T, A<:AbstractSparseMatrix}(S::LowerTriangular{T, A}) = true
19+
issparse{T, A<:AbstractSparseMatrix}(S::LinAlg.UnitLowerTriangular{T, A}) = true
20+
issparse{T, A<:AbstractSparseMatrix}(S::UpperTriangular{T, A}) = true
21+
issparse{T, A<:AbstractSparseMatrix}(S::LinAlg.UnitUpperTriangular{T, A}) = true
22+
1623
indtype{Tv,Ti}(S::AbstractSparseArray{Tv,Ti}) = Ti

test/sparsedir/sparse.jl

+17
Original file line numberDiff line numberDiff line change
@@ -1227,3 +1227,20 @@ end
12271227
# https://groups.google.com/forum/#!topic/julia-dev/QT7qpIpgOaA
12281228
@test sparse([1,1], [1,1], [true, true]) == sparse([1,1], [1,1], [true, true], 1, 1) == fill(true, 1, 1)
12291229
@test sparsevec([1,1], [true, true]) == sparsevec([1,1], [true, true], 1) == fill(true, 1)
1230+
1231+
# issparse for specialized matrix types
1232+
let
1233+
m = sprand(10, 10, 0.1)
1234+
@test issparse(Symmetric(m))
1235+
@test issparse(Hermitian(m))
1236+
@test issparse(LowerTriangular(m))
1237+
@test issparse(LinAlg.UnitLowerTriangular(m))
1238+
@test issparse(UpperTriangular(m))
1239+
@test issparse(LinAlg.UnitUpperTriangular(m))
1240+
@test issparse(Symmetric(full(m))) == false
1241+
@test issparse(Hermitian(full(m))) == false
1242+
@test issparse(LowerTriangular(full(m))) == false
1243+
@test issparse(LinAlg.UnitLowerTriangular(full(m))) == false
1244+
@test issparse(UpperTriangular(full(m))) == false
1245+
@test issparse(LinAlg.UnitUpperTriangular(full(m))) == false
1246+
end

0 commit comments

Comments
 (0)