package owl-base

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Owl_utils_arraySource

Basic functions
Sourceval length : 'a array -> int

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

Sourceval create_float : int -> float array

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

Sourceval append : 'a array -> 'a array -> 'a array

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

Sourceval copy : 'a array -> 'a array

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

Sourceval to_list : 'a array -> 'a list

Refer to OCaml native array.

Sourceval of_list : 'a list -> 'a array

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

Sourceval 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 Stdlib.compare is used as default value.

Sourceval 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 Stdlib.compare is used as default value.

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

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

Refer to OCaml native array.

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

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

Refer to OCaml native array.

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

Refer to OCaml native array.

Extended functions
Sourceval (@) : 'a array -> 'a array -> 'a array

Operator of array concatenation.

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

Sourceval 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 definition.

Sourceval flatten : 'a array array -> 'a array

Flatten an array array into an array.

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

set_n arr indices v sets the elements at the positions specified by indices in the array arr to the value v.

  • parameter arr

    The array in which to set values.

  • parameter indices

    An array of indices specifying the positions in arr to be updated.

  • parameter v

    The value to set at each of the specified positions.

Sourceval range : int -> int -> int array

range start stop generates an array of integers from start to stop inclusive.

  • parameter start

    The starting value of the range.

  • parameter stop

    The ending value of the range.

  • returns

    An array of integers from start to stop.

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

count arr x counts the number of occurrences of the value x in the array arr.

  • parameter arr

    The array in which to count occurrences.

  • parameter x

    The value to count within the array.

  • returns

    The number of times x appears in arr.

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

insert arr1 arr2 pos inserts the elements of arr2 into arr1 at the specified position pos.

  • parameter arr1

    The array into which elements are inserted.

  • parameter arr2

    The array of elements to insert into arr1.

  • parameter pos

    The position in arr1 at which to insert arr2.

  • returns

    A new array with arr2 inserted into arr1 at the position pos.

Sourceval unique : 'a array -> 'a array

unique x removes the duplicates in the array x.

Sourceval merge : 'a array -> 'a array -> 'a array

merge x y merges two arrays and removes the duplicates.

Sourceval reverse : 'a array -> unit

reverse arr reverses the elements of the array arr in place.

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

remove arr pos removes the element at position pos from the array arr.

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

replace pos len arr1 arr2 replaces the subarray of length len starting at pos in arr1 with the elements from arr2.

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

mapi f arr applies the function f to each element of the array arr, passing the index of the element as the first argument to f, and returns a new array of the results.

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

map f arr applies the function f to each element of the array arr and returns a new array of the results.

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

iter2i f arr1 arr2 applies the function f to each pair of corresponding elements from arr1 and arr2, passing the index as the first argument to f.

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

iter2 f arr1 arr2 applies the function f to each pair of corresponding elements from arr1 and arr2.

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

iter3i f arr1 arr2 arr3 applies the function f to each triplet of corresponding elements from arr1, arr2, and arr3, passing the index as the first argument to f.

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

iter3 f arr1 arr2 arr3 applies the function f to each triplet of corresponding elements from arr1, arr2, and arr3.

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

iter4i f arr1 arr2 arr3 arr4 applies the function f to each group of corresponding elements from arr1, arr2, arr3, and arr4, passing the index of the elements as the first argument to f.

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

iter4 f arr1 arr2 arr3 arr4 applies the function f to each group of corresponding elements from arr1, arr2, arr3, and arr4.

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

map2i f arr1 arr2 applies the function f to each pair of corresponding elements from arr1 and arr2, passing the index of the elements as the first argument to f, and returns an array of the results.

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

map2i_split2 f arr1 arr2 applies the function f to each pair of corresponding elements from arr1 and arr2, passing the index of the elements as the first argument to f, and returns a tuple of two arrays containing the first and second elements of the results of f.

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

map3i f arr1 arr2 arr3 applies the function f to each triplet of corresponding elements from arr1, arr2, and arr3, passing the index of the elements as the first argument to f, and returns an array of the results.

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

map3 f arr1 arr2 arr3 applies the function f to each triplet of corresponding elements from arr1, arr2, and arr3, and returns an array of the results.

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

map4i f arr1 arr2 arr3 arr4 applies the function f to each group of corresponding elements from arr1, arr2, arr3, and arr4, passing the index of the elements as the first argument to f, and returns an array of the results.

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

map4 f arr1 arr2 arr3 arr4 applies the function f to each group of corresponding elements from arr1, arr2, arr3, and arr4, and returns an array of the results.

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

filteri_v f arr applies the function f to each element of arr, passing the index of the element as the first argument to f. The function f returns a pair of a boolean and a value. If the boolean is true, the value is included in the result array.

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

filter_v f arr applies the function f to each element of arr. The function f returns a pair of a boolean and a value. If the boolean is true, the value is included in the result array.

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

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

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

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

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

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

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

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

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

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

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

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

pad side v len arr pads the array arr with the value v on the specified side (`Left` or `Right`) until the array reaches the desired length len.

If len is less than or equal to the length of arr, the original array is returned.

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

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

Sourceval greater_equal : 'a array -> 'a array -> bool

greater_equal arr1 arr2 returns true if all elements in arr1 are greater than or equal to the corresponding elements in arr2, and false otherwise.

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

swap arr i j swaps the elements at indices i and j in the array arr.

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

permute indices arr rearranges the elements of arr according to the order specified by indices, returning a new array with the permuted elements.

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

of_tuples arr converts an array of pairs into an array containing all the first elements followed by all the second elements of the pairs in arr.

Sourceval complement : 'a array -> 'a array -> 'a array
Sourceval balance_last : float -> float array -> float array

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

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

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

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

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

to_string ?prefix ?suffix ?sep f arr converts the array arr to a string representation, applying the function f to each element to produce a string. The elements are separated by sep (default is ", "), and the entire output is optionally wrapped with prefix and suffix.

OCaml

Innovation. Community. Security.