Skip to content

Commit b41609b

Browse files
authored
Backport a 1.10 implementation for LinearAlgebra.diagind (#23)
* Backport a 1.10 implementation for `LinearAlgebra.diagind` * Bump v0.2.10 * Add missing import
1 parent 3d774aa commit b41609b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseArraysBase"
22
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.9"
4+
version = "0.2.10"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/wrappers.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,20 @@ for type in (:Adjoint, :PermutedDimsArray, :ReshapedArray, :SubArray, :Transpose
162162
end
163163
end
164164

165-
using LinearAlgebra: Diagonal
165+
using LinearAlgebra: LinearAlgebra, Diagonal
166166
@interface ::AbstractArrayInterface storedvalues(D::Diagonal) = LinearAlgebra.diag(D)
167+
168+
# compat with LTS:
169+
@static if VERSION v"1.11"
170+
_diagind = LinearAlgebra.diagind
171+
else
172+
function _diagind(x::Diagonal, ::IndexCartesian)
173+
return view(CartesianIndices(x), LinearAlgebra.diagind(x))
174+
end
175+
end
167176
@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) =
168-
LinearAlgebra.diagind(D, IndexCartesian())
177+
_diagind(D, IndexCartesian())
178+
169179
@interface ::AbstractArrayInterface isstored(D::Diagonal, i::Int, j::Int) =
170180
i == j && Base.checkbounds(Bool, D, i, j)
171181
@interface ::AbstractArrayInterface function getstoredindex(D::Diagonal, i::Int, j::Int)

0 commit comments

Comments
 (0)