Skip to content
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

Introduce keyword argument reset for sum! etc. #36332

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

tkf
Copy link
Member

@tkf tkf commented Jun 17, 2020

See #36266 for the discussion. The name of the argument is still discussed in #36266 (reset is a placeholder ATM).

close #36266

@tkf tkf added the domain:fold sum, maximum, reduce, foldl, etc. label Jun 17, 2020
Comment on lines +1009 to +1015
if haskey(kw, :init) # backward compatibility
_kw_reset(kw) && !isempty(A) && fill!(rval, first(A))
fill!(rind, zero(eltype(keys(A))))
elseif _kw_reset(kw)
!isempty(A) && fill!(rval, first(A))
fill!(rind, zero(eltype(keys(A))))
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior init=false was not consistent with other multi-dimensional reducers. So I suggest to fix it.

It was added in #6894 by @timholy but it looks like it was an internal function back then. So, probably the consistency with other reducers and the usability for end-users were not the biggest concern.

Also, I'm not sure if we should keep the backward compatibility branch. But it's rather cheap so why not?

_kw_reset(kw::Iterators.Pairs) = _kw_reset(kw.data)
_kw_reset(::NamedTuple{(), Tuple{}}) = true
_kw_reset(kw::NamedTuple{(:reset,), Tuple{Bool}}) = kw.reset
_kw_reset(kw::NamedTuple{(:init,), Tuple{Bool}}) = kw.init
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we depwarn when init is passed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:fold sum, maximum, reduce, foldl, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Soft-)deprecate init for sum! etc?
1 participant