@@ -63,6 +63,19 @@ function Base.setindex!(a::AbstractBlockSparseArray{<:Any,0}, value, ::Block{0})
63
63
return a
64
64
end
65
65
66
+ # Custom `_convert` works around the issue that
67
+ # `convert(::Type{<:Diagonal}, ::AbstractMatrix)` isnt' defined
68
+ # in Julia v1.10 (https://github.com/JuliaLang/julia/pull/48895,
69
+ # https://github.com/JuliaLang/julia/pull/52487).
70
+ # TODO : Delete once we drop support for Julia v1.10.
71
+ _convert (:: Type{T} , a:: AbstractArray ) where {T} = convert (T, a)
72
+ using LinearAlgebra: LinearAlgebra, Diagonal, diag, isdiag
73
+ _construct (T:: Type{<:Diagonal} , a:: AbstractMatrix ) = T (diag (a))
74
+ function _convert (T:: Type{<:Diagonal} , a:: AbstractMatrix )
75
+ LinearAlgebra. checksquare (a)
76
+ return isdiag (a) ? _construct (T, a) : throw (InexactError (:convert , T, a))
77
+ end
78
+
66
79
function Base. setindex! (
67
80
a:: AbstractBlockSparseArray{<:Any,N} , value, I:: Vararg{Block{1},N}
68
81
) where {N}
@@ -74,7 +87,12 @@ function Base.setindex!(
74
87
),
75
88
)
76
89
end
77
- blocks (a)[Int .(I)... ] = value
90
+ # Custom `_convert` works around the issue that
91
+ # `convert(::Type{<:Diagonal}, ::AbstractMatrix)` isnt' defined
92
+ # in Julia v1.10 (https://github.com/JuliaLang/julia/pull/48895,
93
+ # https://github.com/JuliaLang/julia/pull/52487).
94
+ # TODO : Delete once we drop support for Julia v1.10.
95
+ blocks (a)[Int .(I)... ] = _convert (blocktype (a), value)
78
96
return a
79
97
end
80
98
0 commit comments