File tree Expand file tree Collapse file tree 3 files changed +19
-11
lines changed
Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ Standard library changes
117117
118118* new ` sizehint!(::SparseMatrixCSC, ::Integer) ` method ([ #30676 ] ).
119119* ` cholesky() ` now fully preserves the user-specified permutation. ([ #40560 ] )
120-
120+ * ` issparse ` now applies consistently to all wrapper arrays, including nested, by checking ` issparse ` on the wrapped parent array ( [ # 37644 ] ).
121121
122122#### Dates
123123
Original file line number Diff line number Diff line change @@ -50,17 +50,19 @@ julia> issparse(Array(sv))
5050false
5151```
5252"""
53- issparse (A:: AbstractArray ) = false
53+ function issparse (A:: AbstractArray )
54+ # Handle wrapper arrays: sparse if it is wrapping a sparse array.
55+ # This gets compiled away during specialization.
56+ p = parent (A)
57+ if p === A
58+ # have reached top of wrapping without finding a sparse array, assume it is not.
59+ return false
60+ else
61+ return issparse (p)
62+ end
63+ end
64+ issparse (A:: DenseArray ) = false
5465issparse (S:: AbstractSparseArray ) = true
55- issparse (S:: LinearAlgebra.Adjoint{<:Any,<:AbstractSparseArray} ) = true
56- issparse (S:: LinearAlgebra.Transpose{<:Any,<:AbstractSparseArray} ) = true
57-
58- issparse (S:: LinearAlgebra.Symmetric{<:Any,<:AbstractSparseMatrix} ) = true
59- issparse (S:: LinearAlgebra.Hermitian{<:Any,<:AbstractSparseMatrix} ) = true
60- issparse (S:: LinearAlgebra.LowerTriangular{<:Any,<:AbstractSparseMatrix} ) = true
61- issparse (S:: LinearAlgebra.UnitLowerTriangular{<:Any,<:AbstractSparseMatrix} ) = true
62- issparse (S:: LinearAlgebra.UpperTriangular{<:Any,<:AbstractSparseMatrix} ) = true
63- issparse (S:: LinearAlgebra.UnitUpperTriangular{<:Any,<:AbstractSparseMatrix} ) = true
6466
6567indtype (S:: AbstractSparseArray{<:Any,Ti} ) where {Ti} = Ti
6668
Original file line number Diff line number Diff line change @@ -2165,6 +2165,12 @@ end
21652165 @test issparse (LinearAlgebra. UnitLowerTriangular (Array (m))) == false
21662166 @test issparse (UpperTriangular (Array (m))) == false
21672167 @test issparse (LinearAlgebra. UnitUpperTriangular (Array (m))) == false
2168+ @test issparse (Base. ReshapedArray (m, (20 , 5 ), ()))
2169+ @test issparse (@view m[1 : 3 , :])
2170+
2171+ # greater nesting
2172+ @test issparse (Symmetric (UpperTriangular (m)))
2173+ @test issparse (Symmetric (UpperTriangular (Array (m)))) == false
21682174end
21692175
21702176@testset " issparse for sparse vectors #34253" begin
You can’t perform that action at this time.
0 commit comments