-
-
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
promote_eltype
does not support objects that do not have elements (such as Types)
#53287
Comments
I'd like this to be exported if it can be done with reasonable effort. If I can promote a Float32 to a Float64 without allocating for the entire Float64, that'd be really cool. I understand that I may be asking the impossible (what if the Float32 is between some other stuff in memory?). @wheeheee, what is your use case for this? |
Nothing spectacular, just type promotion to allocate output arrays, e.g. |
Hmm, neither of those results are particularly satisfying, but it is not particularly supposed to mean anything either, since types are not iterable, they don't have an eltype themselves. It is sort of just an accident that a mixed group here works out this way since code is not supposed to end up here. Perhaps you meant to call |
Note that in either case (with the current method, your method, or the old method), it gets the incorrect result for Types, as it tries to treat them as Types instead of Kinds
In that regard this new method seems most correct, as it actually treats Types as values (returning Any for their promotion). |
promote_eltype
promote_eltype
does not support objects that do not have elements (such as Types)
But types julia> eltype(Vector{Float64})
Float64
julia> eltype(Float64)
Float64 |
The values of those types are defined to have eltypes, but the types themselves do not:
|
Yes, my fix was just wrong. Nevertheless, I think most people expect promote_eltype(v1::T, vs::T...) where {T} = eltype(T) does the latter. Isn't |
I am not sure why people should expect anything of an undocumented function that will never get called with those arguments. Where it is used, it is used to compute the result type of indexing into the object or iterating it. Passing Type arguments doesn't permit those operations. |
I know this function is not exported, but after #51135, this function does not seem to produce the correctly promoted type for some inputs.
Due to the change, my example would try to promote the type
DataType
ofFloat64
withFloat64
, and producesAny
whereFloat64
is expected, which doesn't seem to be the intention of the function.I believe a simple change from the offending line
to this, replacing
T
withv1
, would suffice.The text was updated successfully, but these errors were encountered: