Module Packed_float_option.Array

type elt := float
type t
include Core.Bin_prot.Binable.S__local with type t := t
include Bin_prot.Binable.S_only_functions__local with type t := t
include sig ... end
include Sexplib0.Sexpable.S with type t := t
include Sexplib0.Sexpable.Of_sexp with type t := t
include Sexplib0.Sexpable.Sexp_of with type t := t
include Float_array.S with type t := t and type float_elt := elt
include Core.Bin_prot.Binable.S__local with type t := t
include Bin_prot.Binable.S_only_functions__local with type t := t
include sig ... end
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : t Bin_prot.Read.vtag_reader

This 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.t
val bin_writer_t : t Bin_prot.Type_class.writer
val bin_reader_t : t Bin_prot.Type_class.reader
include Ppx_compare_lib.Comparable.S with type t := t
val compare : t -> t -> int
val globalize : t @ local -> t
include Sexplib0.Sexpable.S with type t := t
include Sexplib0.Sexpable.Of_sexp with type t := t
val t_of_sexp : Sexplib0.Sexp.t -> t
include Sexplib0.Sexpable.Sexp_of with type t := t
val sexp_of_t : t -> Sexplib0.Sexp.t
val custom_sexp_of_t : (elt -> Core.Sexp.t) -> t -> Core.Sexp.t @@ portable
val custom_t_of_sexp : (Core.Sexp.t -> elt) -> Core.Sexp.t -> t @@ portable
include Core.Binary_searchable.S with type t := t with type elt := elt

See Binary_search.binary_search in binary_search.ml

See Binary_search.binary_search_segmented in binary_search.ml

val binary_search_segmented : ?pos:int -> ?len:int -> t -> segment_of:(elt -> [ `Left | `Right ]) @ local -> ([ `Last_on_left | `First_on_right ] -> int option @ local) @ local
include Core.Container.S0 with type t := t with type elt := elt
include sig ... end
include sig ... end
val is_empty : 'a 'p1 'p2. t -> bool
val iter : 'a 'p1 'p2. t -> f:(elt -> unit) @ local -> unit

iter must allow exceptions raised in f to escape, terminating the iteration cleanly. The same holds for all functions below taking an f.

val exists : 'a 'p1 'p2. t -> f:(elt -> bool) @ local -> bool

Returns true if and only if there exists an element for which the provided function evaluates to true. This is a short-circuiting operation.

val for_all : 'a 'p1 'p2. t -> f:(elt -> bool) @ local -> bool

Returns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.

val count : 'a 'p1 'p2. t -> f:(elt -> bool) @ local -> int

Returns the number of elements for which the provided function evaluates to true.

val find : 'a 'p1 'p2. t -> f:(elt -> bool) @ local -> elt Option.t

Returns as an option the first element for which f evaluates to true.

val to_list : 'a 'p1 'p2. t -> elt list
val min_elt : 'a 'p1 'p2. t -> compare:(elt -> (elt -> int) @ local) @ local -> elt Option.t

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 max_elt : 'a 'p1 'p2. t -> compare:(elt -> (elt -> int) @ local) @ local -> elt Option.t
val sum : 'a 'sum 'p1 'p2. (module Base.Container.Summable with type t = 'sum) -> t -> f:(elt -> 'sum) @ local -> 'sum

Returns 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) @ local

iter_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 'p1 'p2 'acc. t -> init:'acc -> f:('acc -> (elt -> 'acc) @ local) @ local -> 'acc

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.t

fold_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.

val find_map : 'a 'p1 'p2 'b. t -> f:(elt -> 'b Option.t) @ local -> 'b Option.t

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) @ local

fold_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 -3
val mem : t -> elt -> bool

Checks whether the provided element is there, using equality on elts.

val to_array : t -> elt array
val length : t @ local -> int @@ portable
val empty : t @@ portable

The empty array.

val of_array : elt array -> t @@ portable

Create a floatarray from a normal array of boxed floats.

val max_length : int @@ portable

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.

val get : t @ local -> (int -> elt) @ local @@ portable

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).

val set : t @ local -> (int -> (elt @ local -> unit) @ local) @ local @@ portable

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.

val unsafe_get : t @ local -> (int -> elt) @ local @@ portable

Unsafe version of get. Can cause arbitrary behavior when used for an out-of-bounds array access.

val unsafe_set : t @ local -> (int -> (elt @ local -> unit) @ local) @ local @@ portable

Unsafe version of set. Can cause arbitrary behavior when used for an out-of-bounds array access.

val create : len:int -> elt -> t @@ portable

create ~len x creates an array of length len with the value x populated in each element.

val create_local : len:int -> elt -> t @ local @@ portable

create_local ~len x is like create. It allocates the array on the local stack. The array's elements are still global.

val init : int -> f:(int -> elt) -> t @@ portable

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 @@ portable

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.

val append : t -> t -> t @@ portable

Float_array.append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2.

val concat : t list -> t @@ portable

Like Float_array.append, but concatenates a list of arrays.

val copy : t @ local -> t @@ portable

Float_array.copy a returns a copy of a, that is, a fresh array containing the same elements as a.

val fill : t -> pos:int -> len:int -> elt -> unit @@ portable

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.

include Core.Blit.S with type t := t
val blit : src:t @ local -> (src_pos:int -> (dst:t @ local -> (dst_pos:int -> (len:int -> unit) @ local) @ local) @ local) @ local
val blito : src:t @ local -> (?src_pos:int -> (?src_len:int -> (dst:t @ local -> (?dst_pos:int -> (unit -> unit) @ local) @ local) @ local) @ local) @ local
val unsafe_blit : src:t @ local -> (src_pos:int -> (dst:t @ local -> (dst_pos:int -> (len:int -> unit) @ local) @ local) @ local) @ local
val sub : t @ local -> (pos:int -> (len:int -> t) @ local) @ local
val subo : ?pos:int -> ?len:int -> t @ local -> t
val of_list : elt list -> t @@ portable

Float_array.of_list l returns a fresh array containing the elements of l.

val map : t -> f:(elt -> elt) -> t @@ portable

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) |].

val folding_map : t -> init:'a -> f:('a -> elt -> 'a * elt) -> t @@ portable

folding_map is a version of map that threads an accumulator through calls to f.

val folding_mapi : t -> init:'a -> f:(int -> 'a -> elt -> 'a * elt) -> t @@ portable
val fold_map : t -> init:'a -> f:('a -> elt -> 'a * elt) -> 'a * t @@ portable

Float_array.fold_map is a combination of Float_array.fold and Float_array.map that threads an accumulator through calls to f.

val fold_mapi : t -> init:'a -> f:(int -> 'a -> elt -> 'a * elt) -> 'a * t @@ portable
val iteri : t -> f:(int -> elt -> unit) -> unit @@ portable

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.

val mapi : t -> f:(int -> elt -> elt) -> t @@ portable

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.

val foldi : t -> init:'a -> f:(int -> 'a -> elt -> 'a) -> 'a @@ portable
val fold_right : t -> f:(elt -> 'a -> 'a) -> init:'a -> 'a @@ portable

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.

val sort : ?pos:int -> ?len:int -> t -> compare:(elt -> elt -> int) -> unit @@ portable

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.

val stable_sort : t -> compare:(elt -> elt -> int) -> unit @@ portable
val is_sorted : t -> compare:(elt -> elt -> int) -> bool @@ portable
val is_sorted_strictly : t -> compare:(elt -> elt -> int) -> bool @@ portable

is_sorted_strictly xs ~compare iff is_sorted xs ~compare and no two consecutive elements in xs are equal according to compare.

val concat_map : t -> f:(elt -> t) -> t @@ portable

Like List.concat_map, List.concat_mapi.

val concat_mapi : t -> f:(int -> elt -> t) -> t @@ portable
val partition_tf : t -> f:(elt -> bool) -> t * t @@ portable
val partitioni_tf : t -> f:(int -> elt -> bool) -> t * t @@ portable
val cartesian_product : t -> t -> (elt * elt) Core.Array.t @@ portable
val transpose : t Core.Array.t -> t Core.Array.t option @@ portable

transpose 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 @@ portable
val filter_opt : elt option Core.Array.t -> t @@ portable

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.

val filter_map : t -> f:(elt -> elt option) -> t @@ portable

filter_map ~f array maps f over array and filters None out of the results.

val filter_mapi : t -> f:(int -> elt -> elt option) -> t @@ portable

Like filter_map but uses Float_array.mapi.

val for_alli : t -> f:(int -> elt -> bool) -> bool @@ portable

Like for_all, but passes the index as an argument.

val existsi : t -> f:(int -> elt -> bool) -> bool @@ portable

Like exists, but passes the index as an argument.

val counti : t -> f:(int -> elt -> bool) -> int @@ portable

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.

val iter2_exn : t -> t -> f:(elt -> elt -> unit) -> unit @@ portable
val map2_exn : t -> t -> f:(elt -> elt -> elt) -> t @@ portable
val fold2_exn : t -> t -> init:'c -> f:('c -> elt -> elt -> 'c) -> 'c @@ portable
val for_all2_exn : t -> t -> f:(elt -> elt -> bool) -> bool @@ portable

for_all2_exn t1 t2 ~f fails if length t1 <> length t2.

val exists2_exn : t -> t -> f:(elt -> elt -> bool) -> bool @@ portable

exists2_exn t1 t2 ~f fails if length t1 <> length t2.

val filter : t -> f:(elt -> bool) -> t @@ portable

filter t ~f removes the elements for which f returns false.

val filteri : t -> f:(int -> elt -> bool) -> t @@ portable

Like filter except f also receives the index.

val swap : t -> int -> int -> unit @@ portable

swap arr i j swaps the value at index i with that at index j.

val rev_inplace : t -> unit @@ portable

rev_inplace t reverses t in place.

val of_list_rev : elt list -> t @@ portable

of_list_rev l converts from list then reverses in place.

val of_list_map : elt list -> f:(elt -> elt) -> t @@ portable

of_list_map l ~f is the same as of_list (List.map l ~f).

val of_list_mapi : elt list -> f:(int -> elt -> elt) -> t @@ portable

of_list_mapi l ~f is the same as of_list (List.mapi l ~f).

val of_list_rev_map : elt list -> f:(elt -> elt) -> t @@ portable

of_list_rev_map l ~f is the same as of_list (List.rev_map l ~f).

val of_list_rev_mapi : elt list -> f:(int -> elt -> elt) -> t @@ portable

of_list_rev_mapi l ~f is the same as of_list (List.rev_mapi l ~f).

val map_inplace : t -> f:(elt -> elt) -> unit @@ portable

Modifies an array in place, applying f to every element of the array

val find_exn : t -> f:(elt -> bool) -> elt @@ portable

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.

val find_map_exn : t -> f:(elt -> 'a option) -> 'a @@ portable

Returns the first evaluation of f that returns Some. Raises Caml.Not_found or Not_found_s if f always returns None.

val findi : t -> f:(int -> elt -> bool) -> (int * elt) option @@ portable

findi t f returns the first index i of t for which f i (get t i) is true

val findi_exn : t -> f:(int -> elt -> bool) -> int * elt @@ portable

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.

val find_mapi : t -> f:(int -> elt -> 'a option) -> 'a option @@ portable

find_mapi t f is like find_map but passes the index as an argument.

val find_mapi_exn : t -> f:(int -> elt -> 'a option) -> 'a @@ portable

find_mapi_exn is like find_map_exn but passes the index as an argument.

val find_consecutive_duplicate : t -> equal:(elt -> elt -> bool) -> (elt * elt) option @@ portable

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.

val reduce : t -> f:(elt -> elt -> elt) -> elt option @@ portable

reduce f [a1; ...; an] is Some (f (... (f (f a1 a2) a3) ...) an). Returns None on the empty array.

val reduce_exn : t -> f:(elt -> elt -> elt) -> elt @@ portable
val permute : ?random_state:Core.Random.State.t -> t -> unit @@ portable

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.

val random_element : ?random_state:Core.Random.State.t -> t -> elt option @@ portable

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.

val random_element_exn : ?random_state:Core.Random.State.t -> t -> elt @@ portable
val zip : t -> t -> (elt * elt) Core.Array.t option @@ portable

zip is like List.zip, but for arrays.

val zip_exn : t -> t -> (elt * elt) Core.Array.t @@ portable
val unzip : (elt * elt) Core.Array.t -> t * t @@ portable

unzip is like List.unzip, but for arrays.

val sorted_copy : t -> compare:(elt -> elt -> int) -> t @@ portable

sorted_copy ar compare returns a shallow copy of ar that is sorted. Similar to List.sort

val last : t -> elt @@ portable
val equal : (elt -> elt -> bool) -> t -> t -> bool @@ portable
val to_sequence : t -> elt Core.Sequence.t @@ portable

The 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 @@ portable

The input array is shared with the sequence and modifications of it will result in modification of the sequence.

val view_of_float_array_nan_as_none : Float_array.t -> t

Like 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.t

Like to_float_none_as_nan, except it reinterprets the array. Note that this is a view into the array, and no copy is created.