Skip to content

Commit

Permalink
only overload diagonal/convert for ≤v1.11-
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Aug 29, 2024
1 parent f6c723c commit 80b50c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,13 @@ for (Typ, funcs, func) in ((:AbstractZeros, :zeros, :zero), (:AbstractOnes, :one
end
end

# temporary patch. should be a PR(#48895) to LinearAlgebra
Diagonal{T}(A::AbstractFillMatrix) where T = Diagonal{T}(diag(A))
function convert(::Type{T}, A::AbstractFillMatrix) where T<:Diagonal
checksquare(A)
isdiag(A) ? T(diag(A)) : throw(InexactError(:convert, T, A))
if VERSION < v"1.11-"
# temporary patch. should be a PR(#48895) to LinearAlgebra
Diagonal{T}(A::AbstractFillMatrix) where T = Diagonal{T}(diag(A))
function convert(::Type{T}, A::AbstractFillMatrix) where T<:Diagonal
checksquare(A)
isdiag(A) ? T(diag(A)) : throw(InexactError(:convert, T, A))
end
end

Base.StepRangeLen(F::AbstractFillVector{T}) where T = StepRangeLen(getindex_value(F), zero(T), length(F))
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2963,6 +2963,8 @@ end
@testset "Diagonal conversion (#389)" begin
@test convert(Diagonal{Int, Vector{Int}}, Zeros(5,5)) isa Diagonal{Int,Vector{Int}}
@test convert(Diagonal{Int, Vector{Int}}, Zeros(5,5)) == zeros(5,5)
@test Diagonal{Int}(Zeros(5,5)) Diagonal(Zeros{Int}(5))
@test Diagonal{Int}(Ones(5,5)) Diagonal(Ones{Int}(5))
end

@testset "sqrt/cbrt" begin
Expand Down

0 comments on commit 80b50c4

Please sign in to comment.