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

Document the kind of indices returned by findmin/findmax/argmin/argmax #46705

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Changes from 2 commits
Commits
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
22 changes: 20 additions & 2 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -877,12 +877,15 @@ end
"""
findmax(f, domain) -> (f(x), index)

Return a pair of a value in the codomain (outputs of `f`) and the index of
Return a pair of a value in the codomain (outputs of `f`) and the index or key of
the corresponding value in the `domain` (inputs to `f`) such that `f(x)` is maximised.
If there are multiple maximal points, then the first one will be returned.

`domain` must be a non-empty iterable.

Indices are of the same type as those returned by [`keys(domain)`](@ref)
and [`pairs(domain)`](@ref).
vtjnash marked this conversation as resolved.
Show resolved Hide resolved

Values are compared with `isless`.

!!! compat "Julia 1.7"
Expand Down Expand Up @@ -915,6 +918,9 @@ Return the maximal element of the collection `itr` and its index or key.
If there are multiple maximal elements, then the first one will be returned.
Values are compared with `isless`.

Indices are of the same type as those returned by [`keys(itr)`](@ref)
and [`pairs(itr)`](@ref).

See also: [`findmin`](@ref), [`argmax`](@ref), [`maximum`](@ref).

# Examples
Expand All @@ -936,12 +942,15 @@ _findmax(a, ::Colon) = findmax(identity, a)
"""
findmin(f, domain) -> (f(x), index)

Return a pair of a value in the codomain (outputs of `f`) and the index of
Returns a pair of a value in the codomain (outputs of `f`) and the index or key of
vtjnash marked this conversation as resolved.
Show resolved Hide resolved
the corresponding value in the `domain` (inputs to `f`) such that `f(x)` is minimised.
If there are multiple minimal points, then the first one will be returned.

`domain` must be a non-empty iterable.

Indices are of the same type as those returned by [`keys(domain)`](@ref)
and [`pairs(domain)`](@ref).

`NaN` is treated as less than all other values except `missing`.

!!! compat "Julia 1.7"
Expand Down Expand Up @@ -975,6 +984,9 @@ Return the minimal element of the collection `itr` and its index or key.
If there are multiple minimal elements, then the first one will be returned.
`NaN` is treated as less than all other values except `missing`.

Indices are of the same type as those returned by [`keys(itr)`](@ref)
and [`pairs(itr)`](@ref).

See also: [`findmax`](@ref), [`argmin`](@ref), [`minimum`](@ref).

# Examples
Expand Down Expand Up @@ -1027,6 +1039,9 @@ If there are multiple maximal elements, then the first one will be returned.

The collection must not be empty.

Indices are of the same type as those returned by [`keys(itr)`](@ref)
and [`pairs(itr)`](@ref).

Values are compared with `isless`.

See also: [`argmin`](@ref), [`findmax`](@ref).
Expand Down Expand Up @@ -1082,6 +1097,9 @@ If there are multiple minimal elements, then the first one will be returned.

The collection must not be empty.

Indices are of the same type as those returned by [`keys(itr)`](@ref)
and [`pairs(itr)`](@ref).

`NaN` is treated as less than all other values except `missing`.

See also: [`argmax`](@ref), [`findmin`](@ref).
Expand Down