Skip to content

Support init keyword in sum/prod/maximum/minimum #36188

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

Merged
merged 26 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ed1cfc9
Support `init` keyword in `maximum`/`minimum`
timholy May 11, 2020
a9fd8b8
Add `init` keyword argument to `sum` and `prod`
tkf Jun 8, 2020
16b13d2
Merge remote-tracking branch 'origin/teh/reduce_init' into sum-init
tkf Jun 8, 2020
72d01c0
Test sum and prod
tkf Jun 8, 2020
c3e66a5
Add compat annotations to `minimum` and `maximum`
tkf Jun 8, 2020
31feb69
Tweak docstring signature style
tkf Jun 8, 2020
32e0c99
Fix reflection doctest
tkf Jun 8, 2020
b8a686b
Add a NEWS item
tkf Jun 8, 2020
749e2ce
Fix `sum(::AbstractArray{Bool}; dims)`
tkf Jun 8, 2020
bf551a7
Fix a typo
tkf Jun 8, 2020
e1173cb
Fix sum(::AbstractArray{Bool}) optimization path
tkf Jun 8, 2020
791f93c
Apply suggestions from code review
tkf Jun 8, 2020
2b84499
Reflect the same changes to other docstrings
tkf Jun 8, 2020
2122e0e
Mention how `nothing` is used in the test
tkf Jun 8, 2020
6918213
Demonstrate `init` for `sum` and `prod`
tkf Jun 8, 2020
ea2cc8b
Reflect the same changes to other docstrings (2)
tkf Jun 8, 2020
32d7f93
Use `function noncallable end`
tkf Jun 8, 2020
3e7b09c
Use init=Inf for minimum docstring
tkf Jun 8, 2020
0791d49
Apply suggestions from code review
tkf Jun 9, 2020
923bbd8
Revert: maximum(length, []; init=-1)
tkf Jun 9, 2020
0050d4f
Use typemax(Int64) for minimum(length, []; init=typemax(Int64))
tkf Jun 9, 2020
6951b2c
Yet another example: minimum(tanh, Real[]; init=1.0)
tkf Jun 9, 2020
04c0cc9
Yet another example: maximum(tanh, Real[]; init=-1.0)
tkf Jun 9, 2020
5d952ec
Apply suggestions from code review
tkf Jun 10, 2020
42a0155
A short note on the output bound of tanh
tkf Jun 10, 2020
254a7cb
Use sin instead of tanh
tkf Jun 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ The return type is `Int` for signed integers of less than system word size, and
`UInt` for unsigned integers of less than system word size. For all other
arguments, a common return type is found to which all arguments are promoted.

The value returned for empty `itr` can be specified by `init` which must be the
additive identity. It is unspecified whether `init` is used for non-empty
collections.
The value returned for empty `itr` can be specified by `init`. It must be
the additive identity (i.e. zero) as it is unspecified whether `init` is used
for non-empty collections.

!!! compat "Julia 1.6"
Keyword argument `init` requires Julia 1.6 or later.
Expand Down Expand Up @@ -642,8 +642,9 @@ end
maximum(f, itr; [init])

Returns the largest result of calling function `f` on each element of `itr`.
If provided, `init` must be a neutral element for `max` that will be returned
for empty collections.

If provided, `init` must be a neutral element for `max` (i.e. which is less
than any other element) that will be returned for empty collections.

!!! compat "Julia 1.6"
Keyword argument `init` requires Julia 1.6 or later.
Expand Down
4 changes: 2 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1218,9 +1218,9 @@ See also [`applicable`](@ref).
julia> hasmethod(length, Tuple{Array})
true

julia> f(; orange) = orange;
julia> f(; oranges=0) = oranges;

julia> hasmethod(f, Tuple{}, (:orange,))
julia> hasmethod(f, Tuple{}, (:oranges,))
true

julia> hasmethod(f, Tuple{}, (:apples, :bananas))
Expand Down