Utils.Array

This document is auto-generated for Owl’s APIs. #84 entries have been extracted.

Github: {Signature} {Implementation}

Basic functions

val length : 'a array -> int

Refer to OCaml native array.

val get : 'a array -> int -> 'a

Refer to OCaml native array.

val set : 'a array -> int -> 'a -> unit

Refer to OCaml native array.

val make : int -> 'a -> 'a array

Refer to OCaml native array.

val create_float : int -> float array

Refer to OCaml native array.

val init : int -> (int -> 'a) -> 'a array

Refer to OCaml native array.

val make_matrix : int -> int -> 'a -> 'a array array

Refer to OCaml native array.

val append : 'a array -> 'a array -> 'a array

Refer to OCaml native array.

val concat : 'a array list -> 'a array

Refer to OCaml native array.

val sub : 'a array -> int -> int -> 'a array

Refer to OCaml native array.

val copy : 'a array -> 'a array

Refer to OCaml native array.

val fill : 'a array -> int -> int -> 'a -> unit

Refer to OCaml native array.

source code

val blit : 'a array -> int -> 'a array -> int -> int -> unit

Refer to OCaml native array.

val to_list : 'a array -> 'a list

Refer to OCaml native array.

val of_list : 'a list -> 'a array

Refer to OCaml native array.

val iter : ('a -> unit) -> 'a array -> unit

Refer to OCaml native array.

val iteri : (int -> 'a -> unit) -> 'a array -> unit

Refer to OCaml native array.

val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a

Refer to OCaml native array.

val fold_right : ('b -> 'a -> 'a) -> 'b array -> 'a -> 'a

Refer to OCaml native array.

val map2 : ('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array

Refer to OCaml native array.

val for_all : ('a -> bool) -> 'a array -> bool

Refer to OCaml native array.

val exists : ('a -> bool) -> 'a array -> bool

Refer to OCaml native array.

val mem : 'a -> 'a array -> bool

Refer to OCaml native array.

val memq : 'a -> 'a array -> bool

Refer to OCaml native array.

val min_i : ?cmp:('a -> 'a -> int) -> 'a array -> int

min_i x returns the index of minimum value in array x. If cmp is not passed in then Pervasives.compare is used as default value.

source code

val max_i : ?cmp:('a -> 'a -> int) -> 'a array -> int

max_i x returns the index of minimum value in array x. If cmp is not passed in then Pervasives.compare is used as default value.

source code

val argsort : ?cmp:('a -> 'a -> int) -> 'a array -> int array

argsort cmp x sorts x according to the compare function cmp and returns the corresponding indices.

source code

val sort : ('a -> 'a -> int) -> 'a array -> unit

Refer to OCaml native array.

val stable_sort : ('a -> 'a -> int) -> 'a array -> unit

Refer to OCaml native array.

val fast_sort : ('a -> 'a -> int) -> 'a array -> unit

Refer to OCaml native array.

val sort_fill : ?min:int -> ?max:int -> ?fill:int -> int array -> int array

sort_fill ~min ~max ~fill x first sorts x, then expands it to an array of length max - min + 1, and fills the holes with fill. E.g., sort_fill ~min:1 ~max:5 ~fill:0 [|4;2|] x returns a new array as follows: [|1; 0; 2; 0; 4; 5|].

source code

val unsafe_get : 'a array -> int -> 'a

Refer to OCaml native array.

val unsafe_set : 'a array -> int -> 'a -> unit

Refer to OCaml native array.

Extended functions

val ( @ ) : 'a array -> 'a array -> 'a array

Operator of array concatenation.

source code

val get_slice : int array -> 'a array -> 'a array

get_slice slice x returns a copy of slice of x defined by slice. The slice definition must have [|start;stop;step|] format. The value of start, stop, and step can be negative, and the boundary is inclusive.

source code

val set_slice : int array -> 'a array -> 'a array -> unit

set_slice slice x y sets the elements in x to the corresponding value of the elements in y based on the slice definition slice. Please refer to get_slice function for the information on the format of slice definiton.

source code

val flatten : 'a array array -> 'a array

Flatten an array array into an array.

source code

val set_n : 'a array -> int array -> 'a -> unit

TODO

source code

val range : int -> int -> int array

TODO

source code

val count : 'a array -> 'a -> int

TODO

source code

val insert : 'a array -> 'a array -> int -> 'a array

TODO

source code

val unique : 'a array -> 'a array

unique x removes the duplicates in the array x.

source code

val merge : 'a array -> 'a array -> 'a array

merge x y merges two arrays and removes the duplicates.

source code

val remove : 'a array -> int -> 'a array

TODO

source code

val replace : int -> int -> 'a array -> 'a array -> 'a array

TODO

source code

val reverse : 'a array -> unit

reverse x reverse the elements in x in place.

source code

val mapi : (int -> 'a -> 'b) -> 'a array -> 'b array

TODO

source code

val map : ('a -> 'b) -> 'a array -> 'b array

TODO

source code

val iter2i : (int -> 'a -> 'b -> unit) -> 'a array -> 'b array -> unit

TODO

source code

val iter2 : ('a -> 'b -> unit) -> 'a array -> 'b array -> unit

TODO

source code

val iter3i : (int -> 'a -> 'b -> 'c -> unit) -> 'a array -> 'b array -> 'c array -> unit

TODO

source code

val iter3 : ('a -> 'b -> 'c -> unit) -> 'a array -> 'b array -> 'c array -> unit

TODO

source code

val iter4i : (int -> 'a -> 'b -> 'c -> 'd -> unit) -> 'a array -> 'b array -> 'c array -> 'd array -> unit

TODO

source code

val iter4 : ('a -> 'b -> 'c -> 'd -> unit) -> 'a array -> 'b array -> 'c array -> 'd array -> unit

TODO

source code

val map2i : (int -> 'a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array

TODO

source code

val map2i_split2 : (int -> 'a -> 'b -> 'c * 'd) -> 'a array -> 'b array -> 'c array * 'd array

TODO

source code

val map3i : (int -> 'a -> 'b -> 'c -> 'd) -> 'a array -> 'b array -> 'c array -> 'd array

TODO

source code

val map3 : ('a -> 'b -> 'c -> 'd) -> 'a array -> 'b array -> 'c array -> 'd array

TODO

source code

val map4i : (int -> 'a -> 'b -> 'c -> 'd -> 'e) -> 'a array -> 'b array -> 'c array -> 'd array -> 'e array

TODO

source code

val map4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a array -> 'b array -> 'c array -> 'd array -> 'e array

TODO

source code

val filteri_v : (int -> 'a -> bool * 'b) -> 'a array -> 'b array

TODO

source code

val filter_v : ('a -> bool * 'b) -> 'a array -> 'b array

TODO

source code

val filteri : (int -> 'a -> bool) -> 'a array -> 'a array

filteri f x filters out the elements in x according to predicate f.

source code

val filter : ('a -> bool) -> 'a array -> 'a array

filter f x filters out the elements in x according to predicate f.

source code

val filter2i : (int -> 'a -> 'b -> bool) -> 'a array -> 'b array -> ('a * 'b) array

filter2i f x y filters the elements in x and y using passed in function f. Both arrays must have same length.

source code

val filter2 : ('a -> 'b -> bool) -> 'a array -> 'b array -> ('a * 'b) array

filter2 f x y is similar to filter2i but without passing index of the elements to function f.

source code

val filter2i_i : (int -> 'a -> 'b -> bool) -> 'a array -> 'b array -> int array

filter2i_i f x y filters the elements in x and y using passed in function f. Both arrays must have same length. Note that the indices of those satisfying the predicate f are returned in an array.

source code

val filter2_i : ('a -> 'b -> bool) -> 'a array -> 'b array -> int array

filter2_i f x y is similar to filter2i_i but without passing index of the elements to function f.

source code

val filter2_split : ('a -> 'b -> bool) -> 'a array -> 'b array -> 'a array * 'b array

filter2_split f x y is similar to filter2 f x y, but the returned results are two separated arrays rather than merging into one tuple array.

source code

val resize : ?head:bool -> 'a -> int -> 'a array -> 'a array

resize ~head v n x resizes x of length m to length n. If m <= n, a copy of x subarray is returned. If m > n, then x is extended, the extra space is filled with value v.

source code

val fold2: ('a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a

fold2 a x y folds both x and y from left with starting value a.

val pad : [ `Left | `Right ] -> 'a -> int -> 'a array -> 'a array

TODO

source code

val align : [ `Left | `Right ] -> 'a -> 'a array -> 'a array -> 'a array * 'a array

align side v x y aligns two arrays x and y along the specified side with value v. The copies of two arrays are returned.

source code

val align3 : [ `Left | `Right ] -> 'a -> 'a array -> 'a array -> 'a array -> 'a array * 'a array * 'a array

align3 side v x y z aligns three arrays x, y, and z.

source code

val greater_eqaul : 'a array -> 'a array -> bool

TODO

source code

val swap : 'a array -> int -> int -> unit

TODO

source code

val permute : int array -> 'a array -> 'a array

TODO

source code

val of_tuples : ('a * 'a) array -> 'a array

TODO

source code

val balance_last : float -> float array -> float array

balance_last mass x performs the following function. Let k be the length of x, if i < l - 1, then x.(i) = x.(i), otherwise x.(l - 1) = mass - \sum x.(i).

source code

val index_of : 'a array -> 'a -> int

index_of x a returns the index of first occurrence of a in x.

source code

val bsearch : cmp:('a -> 'a -> int) -> 'a  -> 'a array -> int

Binary search. bsearch cmp x a returns the index of the largest value in the sorted array a less than or equal to x, according to the comparison function cmp. If x is smaller than all elements, returns -1. The function raises an exception if a is empty.

source code

val to_string : ?prefix:string -> ?suffix:string -> ?sep:string -> ('a -> string) -> 'a array -> string

TODO

source code