-
-
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
Generalize broadcast to handle tuples and scalars #16986
Conversation
Were you able to rebuild with this change? The builds all look like they failed to bootstrap. |
The problem was a silly typo. I believe it should work now. |
No. The compiler cannot currently prove that a whole array is constant and won't be mutated. Adding just |
That seems a better idea. I'll see if I can make that work. |
Tuples too? |
This proposal is going to end up a mess of special cases. This should be done with something like |
@@ -199,6 +199,17 @@ promote_rule(::Type{Float64}, ::Type{Float32}) = Float64 | |||
widen(::Type{Float16}) = Float32 | |||
widen(::Type{Float32}) = Float64 | |||
|
|||
promote_op{T<:Union{Float32,Float64}}(::typeof(trunc), ::Type{Signed}, ::Type{T}) = Int |
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.
I don't think you need to do this for numbers. A generic definition like this seems to be enough:
promote_op{R<:Number,S<:Number}(op, ::Type{R}, ::Type{S}) = typeof(op(one(R), one(S)))
I'm currently working on it for PR #16996.
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.
That won't work when one of the arguments is a type, which is the case here.
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.
Sorry, I completely misread that line due to what I was working on at the same time, carry on.
I'm worried about the
Calling something like |
I think most of the code uses |
As Milan said, most of the code that uses A couple of questions more. Should broadcast always return an |
I'd say it should definitely work on tuples, and it should return a tuple like |
AbstractArray
s as scalars in broadcast
31871b3
to
17da30d
Compare
AbstractArray
s as scalars in broadcast59be7fd
to
a4d9436
Compare
1e20142
to
35cd87c
Compare
35cd87c
to
e9b2805
Compare
Ok, I think it should be better now. Can we give it another spin? |
Does a new version of BaseBenchmarks need to be tagged? |
If you are talking about the ones affected by vectorization depwarn then no, it's already updated. There doesn't seem to be any new commit since then either. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
I don't see how this PR could possibly have affected sorting or sparse-transpose performance. @jrevels, are those tests typically "noisy"? |
Those regressions appear within the noise margins I've recently seen elsewhere (for example #17900 (comment), which I could not reproduce locally and did not persist across nanosoldier runs). |
In which case this should be good to merge? |
I locally built and benchmarked this branch against master, and could not reproduce any of the potential regressions the most recent nanosoldier run identified. So if nanosoldier's most recent run was the last remaining concern, this PR should be in good shape. Best! |
|
||
@generated function broadcast_tup{AT,nargs}(f, As::AT, ::Type{Val{nargs}}, n) | ||
quote | ||
ntuple(n -> (@ncall $nargs f i->_broadcast_getindex(As[i], n)), Val{n}) |
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.
this generated function definition is illegal (they may not use closures / inner functions, as that generates a new type and corrupts inference)
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.
should this be reverted then? is that restriction fully documented or enforced?
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.
Note that this is a very strong restriction which includes @threads
(possibly other macros) and comprehensions.
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.
Would changing this to (((@ncall $nargs f i->_broadcast_getindex(As[i], _)) for _ = 1:n)...)
be enough to fix this?
EDIT: No, some of the changes from #18413 are making all variations of fixes I tried, fail.
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.
In the future, I believe we should fix the comprehension issue by introducing sealed anonymous functions (so that they get uniqued based upon their code contents rather than their definition position / gensym-name). But yes, that's currently invalid.
Can this be backported to 0.5? I was getting all excited about the .-syntax, but this kills a fair few of the use cases I have. The workaround (to define |
This would be too big of a behavior change to backport. |
Bummer. But in that case this should either throw a useful error message and/or be added to the 0.5 docs. Currently this is:
and after defining |
These functions were simply renamed in JuliaLang/julia#16986.
This addresses #16966 and should also help a little with
#4883 and#16285.EDITED: Here is a little demo tested locally (also, needs #17389 to work properly)
I just have a question though, can the following be written in a form that would make it pure? Or is it pure? (I have not completely clear the concept of pureness).promote_eltype_op{T}(op, Ts::AbstractArray{DataType}, ::AbstractArray{T}) = typejoin([promote_op(op, S, T) for S in Ts]...)
TODO: