Packed_float_option.Arrayinclude Core.Bin_prot.Binable.S__local with type t := tinclude Bin_prot.Binable.S_only_functions__local with type t := tinclude sig ... endinclude Sexplib0.Sexpable.S with type t := tinclude Sexplib0.Sexpable.Of_sexp with type t := tinclude Sexplib0.Sexpable.Sexp_of with type t := tinclude Float_array.S with type t := t and type float_elt := eltinclude Core.Bin_prot.Binable.S__local with type t := tinclude Bin_prot.Binable.S_only_functions__local with type t := tval bin_read_t : t Bin_prot.Read.readerval __bin_read_t__ : t Bin_prot.Read.vtag_readerThis 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.
val bin_shape_t : Bin_prot.Shape.tval bin_writer_t : t Bin_prot.Type_class.writerval bin_reader_t : t Bin_prot.Type_class.readerval bin_t : t Bin_prot.Type_class.tinclude Ppx_compare_lib.Comparable.S with type t := tinclude Ppx_compare_lib.Comparable.S__local with type t := tinclude Sexplib0.Sexpable.S with type t := tinclude Sexplib0.Sexpable.Of_sexp with type t := tval t_of_sexp : Sexplib0.Sexp.t -> tinclude Sexplib0.Sexpable.Sexp_of with type t := tval sexp_of_t : t -> Sexplib0.Sexp.tval custom_sexp_of_t : (elt -> Core.Sexp.t) -> t -> Core.Sexp.t @@ portableval custom_t_of_sexp : (Core.Sexp.t -> elt) -> Core.Sexp.t -> t @@ portableinclude Core.Binary_searchable.S with type t := t with type elt := eltSee Binary_search.binary_search in binary_search.ml
val binary_search :
?pos:int ->
?len:int ->
t ->
compare:(elt -> ('key -> int) @ local) @ local ->
([ `Last_strictly_less_than
| `Last_less_than_or_equal_to
| `Last_equal_to
| `First_equal_to
| `First_greater_than_or_equal_to
| `First_strictly_greater_than ] ->
('key ->
int option @ local) @ local) @ localSee Binary_search.binary_search_segmented in binary_search.ml
include Core.Container.S0 with type t := t with type elt := eltinclude sig ... endinclude sig ... endval is_empty : 'a 'p1 'p2. t -> booliter 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.
Returns 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 'sum 'p1 'p2. (module Base.Container.Summable with type t = 'sum) ->
t ->
f:(elt -> '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 'p1 'p2 'final. t ->
f:(elt -> (unit, 'final) Base.Container.Continue_or_stop.t) @ local ->
(finish:(unit -> 'final) @ local ->
'final) @ localiter_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.
fold 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 'p1 'p2 'acc 'e. t ->
init:'acc ->
f:('acc -> (elt -> ('acc, 'e) Result.t) @ local) @ local ->
('acc, 'e) Result.tfold_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.
Returns the first evaluation of f that returns Some, and returns None if there is no such element.
val fold_until :
'a 'p1 'p2 'acc 'final. t ->
init:'acc ->
f:
('acc -> (elt -> ('acc, 'final) Base.Container.Continue_or_stop.t) @ local) @ local ->
(finish:('acc -> 'final) @ local ->
'final) @ localfold_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 -3val length : t @ local -> int @@ portableval empty : t @@ portableThe empty array.
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.
val make_matrix : dimx:int -> dimy:int -> elt -> t Core.Array.t @@ portableFloat_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.
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.
val cartesian_product : t -> t -> (elt * elt) Core.Array.t @@ portableval transpose : t Core.Array.t -> t Core.Array.t option @@ portabletranspose in the sense of a matrix transpose. It returns None if the arrays are not all the same length.
val transpose_exn : t Core.Array.t -> t Core.Array.t @@ portableval filter_opt : elt option Core.Array.t -> t @@ portablefilter_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.
val swap : t -> int -> int -> unit @@ portableswap arr i j swaps the value at index i with that at index j.
val rev_inplace : t -> unit @@ portablerev_inplace t reverses t 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.
find_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.
val permute : ?random_state:Core.Random.State.t -> t -> unit @@ portablepermute ?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.
val random_element :
?random_state:Core.Random.State.t ->
t ->
elt option @@ portablerandom_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.
val random_element_exn :
?random_state:Core.Random.State.t ->
t ->
elt @@ portableval zip : t -> t -> (elt * elt) Core.Array.t option @@ portablezip is like List.zip, but for arrays.
val zip_exn : t -> t -> (elt * elt) Core.Array.t @@ portableval unzip : (elt * elt) Core.Array.t -> t * t @@ portableunzip is like List.unzip, but for arrays.
sorted_copy ar compare returns a shallow copy of ar that is sorted. Similar to List.sort
val to_sequence : t -> elt Core.Sequence.t @@ portableThe input array is copied internally so that future modifications of it do not change the sequence.
val to_sequence_mutable : t -> elt Core.Sequence.t @@ portableThe input array is shared with the sequence and modifications of it will result in modification of the sequence.
module Permissioned :
Float_array.Permissioned
with type permissionless := t
and type float_elt := eltval view_of_float_array_nan_as_none : Float_array.t -> tLike of_float_nan_as_none, except it reinterprets the array. Note that this is a view into the array, and no copy is created.
val view_to_float_array_none_as_nan : t -> Float_array.tLike to_float_none_as_nan, except it reinterprets the array. Note that this is a view into the array, and no copy is created.