-
-
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
(Soft-)deprecate init
for sum!
etc?
#36266
Comments
Looking at it again, now I'm not so sure about
Alternatively, it also makes sense to rename (cc'ing other people who might be interested in this: @nalimilan @mbauman @JeffBezanson) |
How about |
I think |
Doesn't the keyword argument to |
Right, In Julia 1.5, we'll have Lines 393 to 400 in 13b07fc
Well, I'm OK with I actually think |
Another option is |
I've never used a bang reduction with In some senses, I think a pretty good API would be one in which we defaulted to using the values in the output array and if an Alternatively, we could use a sentinel like If we're going to use a boolean flag, |
In hindsight, it seems like it would be best if the out-of-place accumulators were defined to always increment the target array: if you want to start at zero, pass in a zeroed array. |
|
You could still think of this as filling an identity element — the "maximative" identity is the Edit: in fact, this framing would allow for a non-erroring empty reduction: julia> sum!(fill(NaN, 1,4), ones(0,4))
1×4 Matrix{Float64}:
0.0 0.0 0.0 0.0
julia> maximum!(fill(NaN, 1,4), ones(0,4))
ERROR: BoundsError: attempt to access 0×4 Matrix{Float64} at index [1:1, 1:4] |
Well, I'm a bit ambivalent about using ys .= sin.(xs)
maximum(ys) it's in some sense not desirable to get |
Should we remove the mention of that keyword argument before people start using it? |
Yeah, good point. Now that everyone agrees that rename is the way to go (and converging to |
Is everyone OK with renaming |
Can someone write a sentence explaining what the artist formerly known as |
|
In the context of 0-element reductions:
In the context of 1+-element reductions:
In the context of bang (in-place) reductions, it's really hard. Here's the best I can do:
|
The first two are the ones we're keeping the |
I created a WIP PR for this #36332. I updated the docstring to what it does. I also added a few doctest demos. I guess it'd help the game? Here is the canonical phrase I used in the PR:
( |
One option would be to use the word |
Hm... I'm a bit confused. Do you mean |
No, I mean you'd call Edit: or we could default to |
If the |
@StefanKarpinski's |
Hunh? This is just determining what the output array gets pre-filled with. E.g., function sum!(r, A; init=zeros(size(r)))
if init === r
# do nothing
elseif init isa Bool
# depwarn
else
r .= init
end
# now proceed with reduction in-place using the values in `r` as the first argument
return r
end |
Oh, I misunderstood your proposal. I thought you were suggesting to use |
Wondering about r = sum!(preprocess(), A; reset = false) is much cleaner than r = preprocess()
sum!(r, A; init = r) |
As @timholy pointed out in #35839, the meaning of
init
in in-place multi-dimensional reducers likesum!
andcount!
are incompatible withreduce
etc.Now that
sum(...; init)
#36188 is merged and would be shipped with Julia 1.6, it's a bit concerning thatinit
insum!(r, A; init = false)
andsum(A; init = false)
means something completely different. I think it might make sense to deprecate or "soft-deprecate"init
forsum!
etc. By "soft-deprecate" I mean to add a new keyword argument that hasinit
as the fallback withoutdepwarn
. This new keyword argument would be documented as a preferred way to control the initialization of the destination array. Sincesum!
etc. do not actually documentinit
, going directly to deprecation might be OK. But, since this keyword argument exists for a long time, I'm inclined to treat this as a fully-fledged public API. (This is a bit tricky case because it's unclear if performance-breaking but semantics-preserving change should be treated as non-breaking.)For the actual name of the new keyword argument, how about
sum!(r, A; fill = true)
instead ofsum!(r, A; init = true)
?The text was updated successfully, but these errors were encountered: