-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Rework type promotion for scalar ∘ array and array ∘ scalar #16055
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
Conversation
👍 To me it seems that the main risk of using |
Yes, I think the number of arguments is a safe criterion for distinguishing. I'm just worried this name re-use makes the code a little harder to understand/maintain. But then again, the whole promotion business is somewhat obscure. Which of the And now for something completely different: |
|
a8d0e00
to
f59038d
Compare
Updated with added |
reshape([ x ^ y for y in Y ], size(Y)) | ||
.^(X::AbstractArray, y::Number ) = | ||
reshape([ x ^ y for x in X ], size(X)) | ||
promote_array_type{S<:Number, A<:AbstractArray}(F, ::Type{S}, ::Type{A}) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have to use @_pure_meta
or could you just use @pure
? You have to use @_pure_meta
early in the bootstrap process before the machinery to support pushmeta!
is available, but I suspect by this point it's in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, @pure
seems to do it. Thanks for the pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad for @pure
, let's hope he doesn't mind emails from Github. (next time use ``` to wrap macros, because otherwise github pings and subscribes users named the same as our macros)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but dammit, ``` and '
do look similar, don't they...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup
LGTM. I restarted the failing builds. When you're ready to have it merged, strip off the RFC and ping again. |
The new promote_array_type is flexible enough so that ./, .\, and .^ for the mixed scalar/array case can be defined like all the other element-wise operations (fixes JuliaLang#14725).
f59038d
to
1124268
Compare
Ready from my side, assuming CI passes. |
A very nice and elegantly-designed fix. Thanks so much for tackling this! |
The first commit is relative direct fix of #14725, rewriting
./
,.\
, and.^
for the mixed scalar/array case to make use ofpromote_eltype_op
.The second commit supersedes the first (I will squash if the end result is deemed good). It rewrites the whole promotion part for mixed scalar/array operations to have all special-casing in the promotion, not in the definition of the operation. To this end
promote_array_type
is rewritten to a two-step procedure. In the first step,promote_array_type
is invoked with the scalar and the array type (not its element type!) in correct order. This is the interface that is used for invoking. However, it just delegates topromote_array_type
giving three types: scalar, array element, and result ofpromote_op
with the arguments in correct order. This is important because (potentially)promote_op(.^, Ta, Tb) != promote_op(.^, Tb, Ta)
. By default, this step returns the promoted type, but here specialization may be used to e.g. ensure thateltype([0.0f0]+1)==Float32
. I am not exactly happy with both steps having the same function name, though, and wonder whether the first step should not simply replacepromote_eltype_op
for this case (I'm not sure about the implied contract ofpromote_eltype_op
). Opinions?