@@ -766,18 +766,12 @@ minimum(a; kw...) = mapreduce(identity, min, a; kw...)
766
766
767
767
"""
768
768
findmax(f, domain) -> (f(x), x)
769
- findmax(f)
770
769
771
770
Returns a pair of a value in the codomain (outputs of `f`) and the corresponding
772
771
value in the `domain` (inputs to `f`) such that `f(x)` is maximised. If there
773
772
are multiple maximal points, then the first one will be returned.
774
773
775
- When `domain` is provided it may be any iterable and must not be empty.
776
-
777
- When `domain` is omitted, `f` must have an implicit domain. In particular, if
778
- `f` is an indexable collection, it is interpreted as a function mapping keys
779
- (domain) to values (codomain), i.e. `findmax(itr)` returns the maximal element
780
- of the collection `itr` and its index.
774
+ `domain` must be a non-empty iterable.
781
775
782
776
Values are compared with `isless`.
783
777
@@ -795,7 +789,21 @@ julia> findmax(first, [(1, :a), (2, :b), (2, :c)])
795
789
796
790
julia> findmax(cos, 0:π/2:2π)
797
791
(1.0, 0.0)
792
+ ```
793
+ """
794
+ findmax (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmax, domain)
795
+ _rf_findmax ((fm, m), (fx, x)) = isless (fm, fx) ? (fx, x) : (fm, m)
796
+
797
+ """
798
+ findmax(itr) -> (x, index)
798
799
800
+ Return the maximal element of the collection `itr` and its index or key.
801
+ If there are multiple maximal elements, then the first one will be returned.
802
+ Values are compared with `isless`.
803
+
804
+ # Examples
805
+
806
+ ```jldoctest
799
807
julia> findmax([8, 0.1, -9, pi])
800
808
(8.0, 1)
801
809
@@ -805,28 +813,18 @@ julia> findmax([1, 7, 7, 6])
805
813
julia> findmax([1, 7, 7, NaN])
806
814
(NaN, 4)
807
815
```
808
-
809
816
"""
810
- findmax (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmax, domain)
811
- _rf_findmax ((fm, m), (fx, x)) = isless (fm, fx) ? (fx, x) : (fm, m)
812
-
813
- findmax (a) = _findmax (a, :)
817
+ findmax (itr) = _findmax (itr, :)
814
818
_findmax (a, :: Colon ) = mapfoldl ( ((k, v),) -> (v, k), _rf_findmax, pairs (a) )
815
819
816
820
"""
817
821
findmin(f, domain) -> (f(x), x)
818
- findmin(f)
819
822
820
823
Returns a pair of a value in the codomain (outputs of `f`) and the corresponding
821
824
value in the `domain` (inputs to `f`) such that `f(x)` is minimised. If there
822
825
are multiple minimal points, then the first one will be returned.
823
826
824
- When `domain` is provided it may be any iterable and must not be empty.
825
-
826
- When `domain` is omitted, `f` must have an implicit domain. In particular, if
827
- `f` is an indexable collection, it is interpreted as a function mapping keys
828
- (domain) to values (codomain), i.e. `findmin(itr)` returns the minimal element
829
- of the collection `itr` and its index.
827
+ `domain` must be a non-empty iterable.
830
828
831
829
`NaN` is treated as less than all other values except `missing`.
832
830
@@ -844,7 +842,22 @@ julia> findmin(first, [(1, :a), (1, :b), (2, :c)])
844
842
845
843
julia> findmin(cos, 0:π/2:2π)
846
844
(-1.0, 3.141592653589793)
845
+ ```
846
+
847
+ """
848
+ findmin (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmin, domain)
849
+ _rf_findmin ((fm, m), (fx, x)) = isgreater (fm, fx) ? (fx, x) : (fm, m)
847
850
851
+ """
852
+ findmin(itr) -> (x, index)
853
+
854
+ Return the minimal element of the collection `itr` and its index or key.
855
+ If there are multiple minimal elements, then the first one will be returned.
856
+ `NaN` is treated as less than all other values except `missing`.
857
+
858
+ # Examples
859
+
860
+ ```jldoctest
848
861
julia> findmin([8, 0.1, -9, pi])
849
862
(-9.0, 3)
850
863
@@ -854,27 +867,17 @@ julia> findmin([1, 7, 7, 6])
854
867
julia> findmin([1, 7, 7, NaN])
855
868
(NaN, 4)
856
869
```
857
-
858
870
"""
859
- findmin (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmin, domain)
860
- _rf_findmin ((fm, m), (fx, x)) = isgreater (fm, fx) ? (fx, x) : (fm, m)
861
-
862
- findmin (a) = _findmin (a, :)
871
+ findmin (itr) = _findmin (itr, :)
863
872
_findmin (a, :: Colon ) = mapfoldl ( ((k, v),) -> (v, k), _rf_findmin, pairs (a) )
864
873
865
874
"""
866
875
argmax(f, domain)
867
- argmax(f)
868
876
869
877
Return a value `x` in the domain of `f` for which `f(x)` is maximised.
870
878
If there are multiple maximal values for `f(x)` then the first one will be found.
871
879
872
- When `domain` is provided it may be any iterable and must not be empty.
873
-
874
- When `domain` is omitted, `f` must have an implicit domain. In particular, if
875
- `f` is an indexable collection, it is interpreted as a function mapping keys
876
- (domain) to values (codomain), i.e. `argmax(itr)` returns the index of the
877
- maximal element in `itr`.
880
+ `domain` must be a non-empty iterable.
878
881
879
882
Values are compared with `isless`.
880
883
@@ -885,7 +888,22 @@ julia> argmax(abs, -10:5)
885
888
886
889
julia> argmax(cos, 0:π/2:2π)
887
890
0.0
891
+ ```
892
+ """
893
+ argmax (f, domain) = findmax (f, domain)[2 ]
888
894
895
+ """
896
+ argmax(itr)
897
+
898
+ Return the index or key of the maximal element in a collection.
899
+ If there are multiple maximal elements, then the first one will be returned.
900
+
901
+ The collection must not be empty.
902
+
903
+ Values are compared with `isless`.
904
+
905
+ # Examples
906
+ ```jldoctest
889
907
julia> argmax([8, 0.1, -9, pi])
890
908
1
891
909
@@ -896,22 +914,15 @@ julia> argmax([1, 7, 7, NaN])
896
914
4
897
915
```
898
916
"""
899
- argmax (f, domain) = findmax (f, domain)[2 ]
900
- argmax (f) = findmax (f)[2 ]
917
+ argmax (itr) = findmax (itr)[2 ]
901
918
902
919
"""
903
920
argmin(f, domain)
904
- argmin(f)
905
921
906
922
Return a value `x` in the domain of `f` for which `f(x)` is minimised.
907
923
If there are multiple minimal values for `f(x)` then the first one will be found.
908
924
909
- When `domain` is provided it may be any iterable and must not be empty.
910
-
911
- When `domain` is omitted, `f` must have an implicit domain. In particular, if
912
- `f` is an indexable collection, it is interpreted as a function mapping keys
913
- (domain) to values (codomain), i.e. `argmin(itr)` returns the index of the
914
- minimal element in `itr`.
925
+ `domain` must be a non-empty iterable.
915
926
916
927
`NaN` is treated as less than all other values except `missing`.
917
928
@@ -926,6 +937,22 @@ julia> argmin(x -> -x^3 + x^2 - 10, -5:5)
926
937
julia> argmin(acos, 0:0.1:1)
927
938
1.0
928
939
940
+ ```
941
+ """
942
+ argmin (f, domain) = findmin (f, domain)[2 ]
943
+
944
+ """
945
+ argmin(itr)
946
+
947
+ Return the index or key of the minimal element in a collection.
948
+ If there are multiple minimal elements, then the first one will be returned.
949
+
950
+ The collection must not be empty.
951
+
952
+ `NaN` is treated as less than all other values except `missing`.
953
+
954
+ # Examples
955
+ ```jldoctest
929
956
julia> argmin([8, 0.1, -9, pi])
930
957
3
931
958
@@ -936,8 +963,7 @@ julia> argmin([7, 1, 1, NaN])
936
963
4
937
964
```
938
965
"""
939
- argmin (f, domain) = findmin (f, domain)[2 ]
940
- argmin (f) = findmin (f)[2 ]
966
+ argmin (itr) = findmin (itr)[2 ]
941
967
942
968
# # all & any
943
969
0 commit comments