-
-
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
fix #4883, result type of broadcast
for arbitrary functions
#17172
Conversation
9a9c37c
to
4a9f6d9
Compare
Still doesn't seem fully fixed:
|
That example works with #16995. |
My understanding is that the fix for this shouldn't rely on |
Yes, promote_op has definitions that just guess, or that get the wrong answer, and all those should be removed. We only need a small number of promote_op definitions to keep things like + and * fast, since otherwise we lose some optimizations in that case. |
@JeffBezanson Why do we lose optimizations without |
indexmaps = map(x->newindexer(sz, x), As) | ||
st = start(iter) | ||
I, st = next(iter, st) | ||
val = f([ As[i][newindex(I, indexmaps[i])] for i=1:nargs ]...) |
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.
Doesn't this mean that f
is called twice on the first element of the array? Can we avoid this, e.g. by passing the first element as an extra argument to _broadcast!
?
Calling f
twice is unexpected if you broadcast
a function with side effects. Also, it's undesirable in cases where f
is extremely expensive (e.g. f
solves a huge PDE).
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.
No; the state from next
is passed to _broadcast!
so it can pick up where we left off.
@nalimilan The reason is related to @stevengj 's question above --- we handle the first element outside the main broadcasting loop, and need a reference to the iteration state. Therefore I used a |
@JeffBezanson, with the current
|
Unlucky choice of arguments :)
The first |
Another consequence of that fallback: #17300 (comment) |
Silly demo:
This still uses
promote_eltype_op
, but falls back to the "map" algorithm when that returnsAny
.Reducing the size of this code is a good challenge for the future. The problems are performance, and handling index ranges and iteration order of the output properly in
collect
. Another issue is that you can't use@simd
on awhile
loop.