-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Element type of Diagonal{T}
is T
even when typeof(zero(T)) != T
#27494
Comments
Having a type where |
Even worse is that |
Strongly related: https://github.com/JuliaLang/julia/issues/27015 |
Well, that's just wrong – but fixable :). If it needs a ComputedFieldType(:tm:), that is doable these days now. You just need the right incantation!. Here's an example: Line 169 in 917ae8b
|
I think what JuMP is doing is very reasonable (see Discourse link in description). Also related: JuliaLang/LinearAlgebra.jl#497, and actually also JuliaGeometry/Rotations.jl#55. I think @vtjnash's approach would work well on master, now that the 'storage' type parameter is separated from the 'element' type parameter (unlike how it was in 0.6); something like function Diagonal(diag::V) where {T, V<:AbstractVector{T}}
S = promote_type(T, typeof(zero(T)))
new{S, V}(diag)
end |
Diagonal
Diagonal{T}
is T
even when typeof(zero(T)) != T
Sometilmes I feel that On the other hand. removing |
Is it still true that there are Base types for which It looks like some formerly inconsistent matrix |
Yes, e.g. for |
From https://discourse.julialang.org/t/help-creating-a-jump-variable-array/11515/8?u=tkoolen. There are cases where
typeof(zero(T)) != T
, so what should theeltype
ofDiagonal{T}
for suchT
?One option would be to define
Base.eltype(::Type{Diagonal{T}}) where {T} = promote_type(T, typeof(zero(T)))
but this could lead to bugs where the
T
inDiagonal{T}
is assumed to be the element type. Another option is to make it so that theDiagonal
constructor converts the input vector to e.g.Vector{promote_type(T, typeof(zero(T)))}
when necessary.Maybe erroring in the constructor when
typeof(zero(T)) != T
could be another option.The text was updated successfully, but these errors were encountered: