Skip to content

Commit

Permalink
Support Diagonal with lazy diag (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
putianyi889 authored Dec 23, 2024
1 parent 93e155d commit e1d4ae3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/EltypeExtensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ for TYP in (Adjoint, Diagonal, Hermitian, Symmetric, SymTridiagonal, Transpose)
@eval _to_eltype(::Type{T}, ::Type{$TYP}) where T = $TYP{T}
@eval _to_eltype(::Type{T}, ::Type{$TYP{S}}) where {T,S} = $TYP{T}
@eval _to_eltype(::Type{T}, ::Type{$TYP{S,M}}) where {T,S,M} = $TYP{T,_to_eltype(T,M)}
@eval convert_eltype(::Type{T}, A::S) where {T,S<:$TYP} = convert(_to_eltype(T, S), A)
if TYP == SymTridiagonal
@eval convert_eltype(::Type{T}, A::SymTridiagonal) where {T} = SymTridiagonal(convert_eltype(T, A.dv), convert_eltype(T, A.ev))
else
@eval convert_eltype(::Type{T}, A::$TYP) where {T} = $TYP(convert_eltype(T, parent(A)))
end
end

@static if VERSION >= v"1.6"
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ end
@testset "#10" begin
@test convert_eltype(Int32, 1:5) === Int32(1):Int32(5)
end

@testset "#31" begin
@test convert_eltype(Float64, Diagonal(1:5)) Diagonal(1.0:5.0)
end
end

@testset "Misc" begin
Expand Down

0 comments on commit e1d4ae3

Please sign in to comment.