Skip to content

Commit 02c2d69

Browse files
committed
Fix for Julia v1.10
1 parent e42a5ed commit 02c2d69

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/abstractblocksparsearray/abstractblocksparsearray.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ function Base.setindex!(a::AbstractBlockSparseArray{<:Any,0}, value, ::Block{0})
6363
return a
6464
end
6565

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+
6679
function Base.setindex!(
6780
a::AbstractBlockSparseArray{<:Any,N}, value, I::Vararg{Block{1},N}
6881
) where {N}
@@ -74,7 +87,12 @@ function Base.setindex!(
7487
),
7588
)
7689
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)
7896
return a
7997
end
8098

src/blocksparsearrayinterface/map.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ function viewblock_or_zeros(a::AbstractArray{<:Any,N}, I::Block{N}) where {N}
4040
return viewblock_or_zeros(a, Tuple(I)...)
4141
end
4242

43+
_convert(::Type{T}, a::AbstractArray) where {T} = convert(T, a)
44+
using LinearAlgebra: Diagonal
45+
_convert(::Type{T}, a::AbstractArray) where {T<:Diagonal} = convert(T, a)
46+
4347
function map_block!(f, a_dest::AbstractArray, I::Block, a_srcs::AbstractArray...)
4448
a_srcs_I = map(a_src -> viewblock_or_zeros(a_src, I), a_srcs)
4549
if isstored(a_dest, I)

0 commit comments

Comments
 (0)