Skip to content

Commit 778d9f3

Browse files
authored
Clarify docs for findmax etc. (#18903)
1 parent ad8cc19 commit 778d9f3

File tree

2 files changed

+76
-8
lines changed

2 files changed

+76
-8
lines changed

base/array.jl

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,12 +1426,21 @@ end
14261426
"""
14271427
findmax(itr) -> (x, index)
14281428
1429-
Returns the maximum element and its index.
1429+
Returns the maximum element of the collection `itr` and its index. If there are multiple
1430+
maximal elements, then the first one will be returned. `NaN` values are ignored, unless
1431+
all elements are `NaN`.
1432+
14301433
The collection must not be empty.
14311434
14321435
```jldoctest
14331436
julia> findmax([8,0.1,-9,pi])
14341437
(8.0,1)
1438+
1439+
julia> findmax([1,7,7,6])
1440+
(7,2)
1441+
1442+
julia> findmax([1,7,7,NaN])
1443+
(7.0,2)
14351444
```
14361445
"""
14371446
function findmax(a)
@@ -1455,12 +1464,21 @@ end
14551464
"""
14561465
findmin(itr) -> (x, index)
14571466
1458-
Returns the minimum element and its index.
1467+
Returns the minimum element of the collection `itr` and its index. If there are multiple
1468+
minimal elements, then the first one will be returned. `NaN` values are ignored, unless
1469+
all elements are `NaN`.
1470+
14591471
The collection must not be empty.
14601472
14611473
```jldoctest
14621474
julia> findmin([8,0.1,-9,pi])
14631475
(-9.0,3)
1476+
1477+
julia> findmin([7,1,1,6])
1478+
(1,2)
1479+
1480+
julia> findmin([7,1,1,NaN])
1481+
(1.0,2)
14641482
```
14651483
"""
14661484
function findmin(a)
@@ -1484,25 +1502,43 @@ end
14841502
"""
14851503
indmax(itr) -> Integer
14861504
1487-
Returns the index of the maximum element in a collection.
1505+
Returns the index of the maximum element in a collection. If there are multiple maximal
1506+
elements, then the first one will be returned. `NaN` values are ignored, unless all
1507+
elements are `NaN`.
1508+
14881509
The collection must not be empty.
14891510
14901511
```jldoctest
14911512
julia> indmax([8,0.1,-9,pi])
14921513
1
1514+
1515+
julia> indmax([1,7,7,6])
1516+
2
1517+
1518+
julia> indmax([1,7,7,NaN])
1519+
2
14931520
```
14941521
"""
14951522
indmax(a) = findmax(a)[2]
14961523

14971524
"""
14981525
indmin(itr) -> Integer
14991526
1500-
Returns the index of the minimum element in a collection.
1527+
Returns the index of the minimum element in a collection. If there are multiple minimal
1528+
elements, then the first one will be returned. `NaN` values are ignored, unless all
1529+
elements are `NaN`.
1530+
15011531
The collection must not be empty.
15021532
15031533
```jldoctest
15041534
julia> indmin([8,0.1,-9,pi])
15051535
3
1536+
1537+
julia> indmin([7,1,1,6])
1538+
2
1539+
1540+
julia> indmin([7,1,1,NaN])
1541+
2
15061542
```
15071543
"""
15081544
indmin(a) = findmin(a)[2]

doc/stdlib/collections.rst

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,35 +405,59 @@ Iterable Collections
405405

406406
.. Docstring generated from Julia source
407407
408-
Returns the index of the maximum element in a collection. The collection must not be empty.
408+
Returns the index of the maximum element in a collection. If there are multiple maximal elements, then the first one will be returned. ``NaN`` values are ignored, unless all elements are ``NaN``\ .
409+
410+
The collection must not be empty.
409411

410412
.. doctest::
411413

412414
julia> indmax([8,0.1,-9,pi])
413415
1
414416

417+
julia> indmax([1,7,7,6])
418+
2
419+
420+
julia> indmax([1,7,7,NaN])
421+
2
422+
415423
.. function:: indmin(itr) -> Integer
416424

417425
.. Docstring generated from Julia source
418426
419-
Returns the index of the minimum element in a collection. The collection must not be empty.
427+
Returns the index of the minimum element in a collection. If there are multiple minimal elements, then the first one will be returned. ``NaN`` values are ignored, unless all elements are ``NaN``\ .
428+
429+
The collection must not be empty.
420430

421431
.. doctest::
422432

423433
julia> indmin([8,0.1,-9,pi])
424434
3
425435

436+
julia> indmin([7,1,1,6])
437+
2
438+
439+
julia> indmin([7,1,1,NaN])
440+
2
441+
426442
.. function:: findmax(itr) -> (x, index)
427443

428444
.. Docstring generated from Julia source
429445
430-
Returns the maximum element and its index. The collection must not be empty.
446+
Returns the maximum element of the collection ``itr`` and its index. If there are multiple maximal elements, then the first one will be returned. ``NaN`` values are ignored, unless all elements are ``NaN``\ .
447+
448+
The collection must not be empty.
431449

432450
.. doctest::
433451

434452
julia> findmax([8,0.1,-9,pi])
435453
(8.0,1)
436454

455+
julia> findmax([1,7,7,6])
456+
(7,2)
457+
458+
julia> findmax([1,7,7,NaN])
459+
(7.0,2)
460+
437461
.. function:: findmax(A, region) -> (maxval, index)
438462

439463
.. Docstring generated from Julia source
@@ -444,13 +468,21 @@ Iterable Collections
444468

445469
.. Docstring generated from Julia source
446470
447-
Returns the minimum element and its index. The collection must not be empty.
471+
Returns the minimum element of the collection ``itr`` and its index. If there are multiple minimal elements, then the first one will be returned. ``NaN`` values are ignored, unless all elements are ``NaN``\ .
472+
473+
The collection must not be empty.
448474

449475
.. doctest::
450476

451477
julia> findmin([8,0.1,-9,pi])
452478
(-9.0,3)
453479

480+
julia> findmin([7,1,1,6])
481+
(1,2)
482+
483+
julia> findmin([7,1,1,NaN])
484+
(1.0,2)
485+
454486
.. function:: findmin(A, region) -> (minval, index)
455487

456488
.. Docstring generated from Julia source

0 commit comments

Comments
 (0)