@@ -771,11 +771,11 @@ minimum(a; kw...) = mapreduce(identity, min, a; kw...)
771
771
# # findmax, findmin, argmax & argmin
772
772
773
773
"""
774
- findmax(f, domain) -> (f(x), x )
774
+ findmax(f, domain) -> (f(x), index )
775
775
776
- Returns a pair of a value in the codomain (outputs of `f`) and the corresponding
777
- value in the `domain` (inputs to `f`) such that `f(x)` is maximised. If there
778
- are multiple maximal points, then the first one will be returned.
776
+ Returns a pair of a value in the codomain (outputs of `f`) and the index of
777
+ the corresponding value in the `domain` (inputs to `f`) such that `f(x)` is maximised.
778
+ If there are multiple maximal points, then the first one will be returned.
779
779
780
780
`domain` must be a non-empty iterable.
781
781
@@ -788,20 +788,20 @@ Values are compared with `isless`.
788
788
789
789
```jldoctest
790
790
julia> findmax(identity, 5:9)
791
- (9, 9 )
791
+ (9, 5 )
792
792
793
793
julia> findmax(-, 1:10)
794
794
(-1, 1)
795
795
796
- julia> findmax(first, [(1, :a), (2 , :b), (2 , :c)])
797
- (2, (2, :b) )
796
+ julia> findmax(first, [(1, :a), (3 , :b), (3 , :c)])
797
+ (3, 2 )
798
798
799
799
julia> findmax(cos, 0:π/2:2π)
800
- (1.0, 0.0 )
800
+ (1.0, 1 )
801
801
```
802
802
"""
803
- findmax (f, domain) = mapfoldl (x -> (f (x ), x ), _rf_findmax, domain)
804
- _rf_findmax ((fm, m ), (fx, x )) = isless (fm, fx) ? (fx, x ) : (fm, m )
803
+ findmax (f, domain) = mapfoldl ( ((k, v),) -> (f (v ), k ), _rf_findmax, pairs ( domain) )
804
+ _rf_findmax ((fm, im ), (fx, ix )) = isless (fm, fx) ? (fx, ix ) : (fm, im )
805
805
806
806
"""
807
807
findmax(itr) -> (x, index)
@@ -829,11 +829,11 @@ findmax(itr) = _findmax(itr, :)
829
829
_findmax (a, :: Colon ) = mapfoldl ( ((k, v),) -> (v, k), _rf_findmax, pairs (a) )
830
830
831
831
"""
832
- findmin(f, domain) -> (f(x), x )
832
+ findmin(f, domain) -> (f(x), index )
833
833
834
- Returns a pair of a value in the codomain (outputs of `f`) and the corresponding
835
- value in the `domain` (inputs to `f`) such that `f(x)` is minimised. If there
836
- are multiple minimal points, then the first one will be returned.
834
+ Returns a pair of a value in the codomain (outputs of `f`) and the index of
835
+ the corresponding value in the `domain` (inputs to `f`) such that `f(x)` is minimised.
836
+ If there are multiple minimal points, then the first one will be returned.
837
837
838
838
`domain` must be a non-empty iterable.
839
839
@@ -846,21 +846,21 @@ are multiple minimal points, then the first one will be returned.
846
846
847
847
```jldoctest
848
848
julia> findmin(identity, 5:9)
849
- (5, 5 )
849
+ (5, 1 )
850
850
851
851
julia> findmin(-, 1:10)
852
852
(-10, 10)
853
853
854
- julia> findmin(first, [(1 , :a), (1 , :b), (2 , :c)])
855
- (1, (1, :a) )
854
+ julia> findmin(first, [(2 , :a), (2 , :b), (3 , :c)])
855
+ (2, 1 )
856
856
857
857
julia> findmin(cos, 0:π/2:2π)
858
- (-1.0, 3.141592653589793 )
858
+ (-1.0, 3)
859
859
```
860
860
861
861
"""
862
- findmin (f, domain) = mapfoldl (x -> (f (x ), x ), _rf_findmin, domain)
863
- _rf_findmin ((fm, m ), (fx, x )) = isgreater (fm, fx) ? (fx, x ) : (fm, m )
862
+ findmin (f, domain) = mapfoldl ( ((k, v),) -> (f (v ), k ), _rf_findmin, pairs ( domain) )
863
+ _rf_findmin ((fm, im ), (fx, ix )) = isgreater (fm, fx) ? (fx, ix ) : (fm, im )
864
864
865
865
"""
866
866
findmin(itr) -> (x, index)
@@ -909,7 +909,7 @@ julia> argmax(cos, 0:π/2:2π)
909
909
0.0
910
910
```
911
911
"""
912
- argmax (f, domain) = findmax (f , domain)[2 ]
912
+ argmax (f, domain) = mapfoldl (x -> ( f (x), x), _rf_findmax , domain)[2 ]
913
913
914
914
"""
915
915
argmax(itr)
@@ -962,7 +962,7 @@ julia> argmin(acos, 0:0.1:1)
962
962
1.0
963
963
```
964
964
"""
965
- argmin (f, domain) = findmin (f , domain)[2 ]
965
+ argmin (f, domain) = mapfoldl (x -> ( f (x), x), _rf_findmin , domain)[2 ]
966
966
967
967
"""
968
968
argmin(itr)
0 commit comments