Float_arraySourceinclude S with type t = Core.floatarray and type float_elt := floatinclude Core.Bin_prot.Binable.S__local with type t := tinclude Bin_prot.Binable.S_only_functions__local with type t := tinclude sig ... endThis function only needs implementation if t exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t afterwards.
include Ppx_compare_lib.Comparable.S__local with type t := tinclude Sexplib0.Sexpable.S__stack with type t := tinclude Sexplib0.Sexpable.Of_sexp with type t := tinclude Sexplib0.Sexpable.Sexp_of__stack with type t := tinclude Core.Binary_searchable.S with type t := t with type elt := floatSee Binary_search.binary_search in binary_search.ml
See Binary_search.binary_search_segmented in binary_search.ml
include Core.Container.S0 with type t := t with type elt := floatinclude sig ... endinclude sig ... enditer must allow exceptions raised in f to escape, terminating the iteration cleanly. The same holds for all functions below taking an f.
Returns true if and only if there exists an element for which the provided function evaluates to true. This is a short-circuiting operation.
Returns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.
Returns the number of elements for which the provided function evaluates to true.
Returns as an option the first element for which f evaluates to true.
val min_elt :
('a : value mod separable) 'p1 'p2. t ->
compare:(float -> (float -> int) @ local) @ local ->
float optionReturns a min (resp. max) element from the collection using the provided compare function. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold so it has the same complexity as fold. Returns None iff the collection is empty.
val sum :
('a : value mod separable) 'sum 'p1 'p2. (module Base.Container.Summable
with type t = 'sum) ->
t ->
f:(float -> 'sum) @ local ->
'sumReturns the sum of f i for all i in the container. The order in which the elements will be summed is unspecified.
val iter_until :
('a : value mod separable) 'p1 'p2 'final. t ->
f:(float -> (unit, 'final) Base.Container.Continue_or_stop.t) @ local ->
finish:(unit -> 'final) @ local ->
'finaliter_until t ~f ~finish is a short-circuiting version of iter. If f returns Stop x the computation ceases and returns x. If f always returns Continue () the final result is computed by finish.
val fold :
('a : value mod separable) 'p1 'p2 'acc. t ->
init:'acc ->
f:('acc -> (float -> 'acc) @ local) @ local ->
'accfold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en are the elements of t.
val fold_result :
('a : value mod separable) 'p1 'p2 'acc 'e. t ->
init:'acc ->
f:('acc -> (float -> ('acc, 'e) result) @ local) @ local ->
('acc, 'e) resultfold_result t ~init ~f is a short-circuiting version of fold that runs in the Result monad. If f returns an Error _, that value is returned without any additional invocations of f.
include sig ... endval fold_until :
('a : value mod separable) 'p1 'p2 'acc 'final. t ->
init:'acc ->
f:
('acc ->
(float ->
('acc, 'final) Base.Container.Continue_or_stop.t) @ local) @ local ->
finish:('acc -> 'final) @ local ->
'finalfold_until t ~init ~f ~finish is a short-circuiting version of fold. If f returns Stop _ the computation ceases and results in that value. If f returns Continue _, the fold will proceed. If f never returns Stop _, the final result is computed by finish.
Example:
type maybe_negative =
| Found_negative of int
| All_nonnegative of { sum : int }
(** [first_neg_or_sum list] returns the first negative number in [list], if any,
otherwise returns the sum of the list. *)
let first_neg_or_sum =
List.fold_until ~init:0
~f:(fun sum x ->
if x < 0
then Stop (Found_negative x)
else Continue (sum + x))
~finish:(fun sum -> All_nonnegative { sum })
;;
let x = first_neg_or_sum [1; 2; 3; 4; 5]
val x : maybe_negative = All_nonnegative {sum = 15}
let y = first_neg_or_sum [1; 2; -3; 4; 5]
val y : maybe_negative = Found_negative -3Checks whether the provided element is there, using equality on elts.
Create a floatarray from a normal array of boxed floats.
Maximum length of a normal array. The maximum length of a float array is max_length/2 on 32-bit machines and max_length on 64-bit machines.
Float_array.get a n returns the element number n of array a. The first element has number 0. The last element has number Float_array.length a - 1.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to (Float_array.length a - 1).
Float_array.set a n x modifies array a in place, replacing element number n with x.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to Float_array.length a - 1.
Unsafe version of get. Can cause arbitrary behavior when used for an out-of-bounds array access.
Unsafe version of set. Can cause arbitrary behavior when used for an out-of-bounds array access.
create ~len x creates an array of length len with the value x populated in each element.
create_local ~len x is like create. It allocates the array on the local stack. The array's elements are still global.
init n ~f creates an array of length n where the ith element (starting at zero) is initialized with f i.
Float_array.make_matrix dimx dimy e returns a two-dimensional array (an array of arrays) with first dimension dimx and second dimension dimy. All the elements of this new matrix are initially physically equal to e.
Raise Invalid_argument if dimx or dimy is negative or greater than Float_array.max_length / 2.
Float_array.append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2.
Like Float_array.append, but concatenates a list of arrays.
Float_array.copy a returns a copy of a, that is, a fresh array containing the same elements as a.
Float_array.fill a ofs len x modifies the array a in place, storing x in elements number ofs to ofs + len - 1.
Raise Invalid_argument "Float_array.fill" if ofs and len do not designate a valid subarray of a.
Float_array.blit v1 o1 v2 o2 len copies len elements from array v1, starting at element number o1, to array v2, starting at element number o2. It works correctly even if v1 and v2 are the same array, and the source and destination chunks overlap.
Raise Invalid_argument "Float_array.blit" if o1 and len do not designate a valid subarray of v1, or if o2 and len do not designate a valid subarray of v2.
The unsafe versions do not bound-check the arguments.
Float_array.of_list l returns a fresh array containing the elements of l.
Float_array.map t ~f applies function f to all the elements of t, and builds an array with the results returned by f: [| f t.(0); f t.(1); ...; f t.(Float_array.length t - 1) |].
folding_map is a version of map that threads an accumulator through calls to f.
Float_array.fold_map is a combination of Float_array.fold and Float_array.map that threads an accumulator through calls to f.
Like Float_array.iter, but the function is applied to the index of the element as first argument, and the element itself as second argument.
Like Float_array.map, but the function is applied to the index of the element as first argument, and the element itself as second argument.
Float_array.fold_right f a ~init computes f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...)), where n is the length of the array a.
All sort functions in this module sort in increasing order by default.
sort uses constant heap space. stable_sort uses linear heap space.
To sort only part of the array, specify pos to be the index to start sorting from and len indicating how many elements to sort.
is_sorted_strictly xs ~compare iff is_sorted xs ~compare and no two consecutive elements in xs are equal according to compare.
transpose in the sense of a matrix transpose. It returns None if the arrays are not all the same length.
filter_opt array returns a float array where None entries are omitted and Some x entries are replaced with x. Note that this changes the index at which elements will appear.
filter_map ~f array maps f over array and filters None out of the results.
Like filter_map but uses Float_array.mapi.
Like for_all, but passes the index as an argument.
Like exists, but passes the index as an argument.
Like count, but passes the index as an argument.
Functions with the 2 suffix raise an exception if the lengths of the two given arrays aren't the same.
for_all2_exn t1 t2 ~f fails if length t1 <> length t2.
exists2_exn t1 t2 ~f fails if length t1 <> length t2.
filter t ~f removes the elements for which f returns false.
Like filter except f also receives the index.
swap arr i j swaps the value at index i with that at index j.
of_list_rev l converts from list then reverses in place.
of_list_map l ~f is the same as of_list (List.map l ~f).
of_list_mapi l ~f is the same as of_list (List.mapi l ~f).
of_list_rev_map l ~f is the same as of_list (List.rev_map l ~f).
of_list_rev_mapi l ~f is the same as of_list (List.rev_mapi l ~f).
Modifies an array in place, applying f to every element of the array
find_exn f t returns the first a in t for which f (get t i) is true. It raises Caml.Not_found or Not_found_s if there is no such a.
Returns the first evaluation of f that returns Some. Raises Caml.Not_found or Not_found_s if f always returns None.
findi t f returns the first index i of t for which f i (get t i) is true
findi_exn t f returns the first index i of t for which f i (get t i) is true. It raises Caml.Not_found or Not_found_s if there is no such element.
find_mapi t f is like find_map but passes the index as an argument.
find_mapi_exn is like find_map_exn but passes the index as an argument.
val find_consecutive_duplicate :
t ->
equal:(float -> float -> bool) ->
(float * float) option @@ portablefind_consecutive_duplicate t ~equal returns the first pair of consecutive elements (a1, a2) in t such that equal a1 a2. They are returned in the same order as they appear in t.
reduce f [a1; ...; an] is Some (f (... (f (f a1 a2) a3) ...) an). Returns None on the empty array.
permute ?random_state t randomly permutes t in place.
permute side-effects random_state by repeated calls to Random.State.int. If random_state is not supplied, permute uses Random.State.default.
random_element ?random_state t is None if t is empty, else it is Some x for some x chosen uniformly at random from t.
random_element side-effects random_state by calling Random.State.int. If random_state is not supplied, random_element uses Random.State.default.
zip is like List.zip, but for arrays.
unzip is like List.unzip, but for arrays.
sorted_copy ar compare returns a shallow copy of ar that is sorted. Similar to List.sort
The input array is copied internally so that future modifications of it do not change the sequence.
The input array is shared with the sequence and modifications of it will result in modification of the sequence.