Module Brr.Tarray
Typed arrays.
Buffers
module Buffer : sig ... endArrayBuffer objects (byte buffers).
module Data_view : sig ... endDataView objects (byte-level typed data access on ArrayBuffers).
Array types
type ('a, 'b) type' = | Int8 : (int, Stdlib.Bigarray.int8_signed_elt) Brr.Tarray.type'| Int16 : (int, Stdlib.Bigarray.int16_signed_elt) Brr.Tarray.type'| Int32 : (int32, Stdlib.Bigarray.int32_elt) Brr.Tarray.type'| Uint8 : (int, Stdlib.Bigarray.int8_unsigned_elt) Brr.Tarray.type'| Uint8_clamped : (int, Stdlib.Bigarray.int8_unsigned_elt) Brr.Tarray.type'| Uint16 : (int, Stdlib.Bigarray.int16_unsigned_elt) Brr.Tarray.type'| Uint32 : (int32, Stdlib.Bigarray.int32_elt) Brr.Tarray.type'| Float32 : (float, Stdlib.Bigarray.float32_elt) Brr.Tarray.type'| Float64 : (float, Stdlib.Bigarray.float64_elt) Brr.Tarray.type'
The type for typed array whose elements are of type 'b and are accessed with type 'a.
val type_size_in_bytes : ('a, 'b) Brr.Tarray.type' -> inttype_size_in_bytes t is the number of bytes used to store an element of type 'b.
Typed arrays
Note. In the functions below.
- Indices can always be negative in which case they are subtracted from
length. This means that-1denotes the last element of the buffer. - If unspecified
startdefaults to0. - If unspecified
stopdefaults tolength b.
The type for ArrayBufferView objects (typed access to ArrayBuffer objects) whose elements are of type 'b and accessed with type 'a. See the type aliases.
val create : ('a, 'b) Brr.Tarray.type' -> int -> ('a, 'b) Brr.Tarray.tcreate n t is an array of type t with n elements of type 'b initialised to their zero. See also converting.
val of_buffer :
('a, 'b) Brr.Tarray.type' ->
?byte_offset:int ->
?length:int ->
Brr.Tarray.Buffer.t ->
('a, 'b) Brr.Tarray.tof_buffer t ~byte_offset ~length b is an array of type t with length elements of type 'b starting at the byte offset byte_offset of b. byte_offset defaults to 0 and length so as to get to the end of the buffer.
val buffer : ('a, 'b) Brr.Tarray.t -> Brr.Tarray.Buffer.tbuffer a is the untyped buffer of a.
val byte_offset : ('a, 'b) Brr.Tarray.t -> intbyte_offset a is the byte index where a starts in buffer a.
val byte_length : ('a, 'b) Brr.Tarray.t -> intbyte_length a is the byte length of a.
val length : ('a, 'b) Brr.Tarray.t -> intlength a are the number of elements in a.
val type' : ('a, 'b) Brr.Tarray.t -> ('a, 'b) Brr.Tarray.type'type' a is the type of a.
Setting, copying and slicing
val get : ('a, 'b) Brr.Tarray.t -> int -> 'aget a i is the element of a at i.
val set : ('a, 'b) Brr.Tarray.t -> int -> 'a -> unitset a i v sets the element of a at i to v.
val set_tarray :
('a, 'b) Brr.Tarray.t ->
dst:int ->
('c, 'd) Brr.Tarray.t ->
unitset_tarray a ~dst b sets the values of a starting at index dst with those of b which are converted to match the type of a (unclear how exactly).
val fill : ?start:int -> ?stop:int -> 'a -> ('a, 'b) Brr.Tarray.t -> unitfill ~start ~stop v a sets the elements in range [start];[stop-1] to v.
val copy_within :
?start:int ->
?stop:int ->
dst:int ->
('a, 'b) Brr.Tarray.t ->
unitcopy_within ~start ~stop ~dst a copies at at dst the elements in range [start];[stop-1].
val slice :
?start:int ->
?stop:int ->
('a, 'b) Brr.Tarray.t ->
('a, 'b) Brr.Tarray.tslice ~start ~stop a is a new array holding a copy of the bytes of a in range [start;stop-1]. This is a copy, use sub to share the data.
val sub :
?start:int ->
?stop:int ->
('a, 'b) Brr.Tarray.t ->
('a, 'b) Brr.Tarray.tsub ~start ~stop a is an array that spans the bytes of b in range [start;stop-1]. This is not a copy, use slice to make a copy.
Predicates
val find : (int -> 'a -> bool) -> ('a, 'b) Brr.Tarray.t -> 'a optionfind sat a is the first index a.i for which sat i a.[i] is true.
val find_index : (int -> 'a -> bool) -> ('a, 'b) Brr.Tarray.t -> int optionfind sat a is the first index i for which sat i a.[i] is true.
val for_all : (int -> 'a -> bool) -> ('a, 'b) Brr.Tarray.t -> boolfor_all sat a is true iff all elements a.[i] of b satisfy sat i a.[i].
val exists : (int -> 'a -> bool) -> ('a, 'b) Brr.Tarray.t -> boolexists sat a is true iff one elements a.[i] of b satisfies sat i a.[i].
Traversals
val filter :
(int -> 'a -> bool) ->
('a, 'b) Brr.Tarray.t ->
('a, 'b) Brr.Tarray.tfilter sat a is an array with the elements a.[i] of a for which sat i a.[i] is true.
val iter : (int -> 'a -> unit) -> ('a, 'b) Brr.Tarray.t -> unititer f a calls f i a.[i] on each element of a.
val map : ('a -> 'a) -> ('a, 'b) Brr.Tarray.t -> ('a, 'b) Brr.Tarray.tmap f a is a new typed array with elements of a mapped by f.
val fold_left : ('c -> 'a -> 'c) -> 'c -> ('a, 'b) Brr.Tarray.t -> 'cfold_left f acc a folds f over the elements of a starting with acc.
val fold_right : ('a -> 'c -> 'c) -> ('a, 'b) Brr.Tarray.t -> 'c -> 'cfold_right f acc a folds f over the elements of a starting with acc.
val reverse : ('a, 'b) Brr.Tarray.t -> ('a, 'b) Brr.Tarray.treverse a is a new array with a's elements reversed.
Type aliases
Use these in interfaces.
type int8 = (int, Stdlib.Bigarray.int8_signed_elt) Brr.Tarray.ttype int16 = (int, Stdlib.Bigarray.int16_signed_elt) Brr.Tarray.ttype int32 = (Stdlib.Int32.t, Stdlib.Bigarray.int32_elt) Brr.Tarray.ttype uint8 = (int, Stdlib.Bigarray.int8_unsigned_elt) Brr.Tarray.ttype uint8_clamped = (int, Stdlib.Bigarray.int8_unsigned_elt) Brr.Tarray.ttype uint16 = (int, Stdlib.Bigarray.int16_unsigned_elt) Brr.Tarray.ttype uint32 = (Stdlib.Int32.t, Stdlib.Bigarray.int32_elt) Brr.Tarray.ttype float32 = (float, Stdlib.Bigarray.float32_elt) Brr.Tarray.ttype float64 = (float, Stdlib.Bigarray.float64_elt) Brr.Tarray.tConverting
val of_tarray :
('c, 'd) Brr.Tarray.type' ->
('a, 'b) Brr.Tarray.t ->
('c, 'd) Brr.Tarray.tof_tarray t a is an array of type t with the elements of a converted accordingly (unclear how exactly).
val uint8_of_buffer : Brr.Tarray.Buffer.t -> Brr.Tarray.uint8uint8_of_buffer b wraps b as an Uint8 typed array.
val of_int_array :
('a, 'b) Brr.Tarray.type' ->
int array ->
('a, 'b) Brr.Tarray.tof_int_array t arr is an array of type t whose elements are the values of arr, values exceeding the range for the type are taken modulo the range bounds (except for Uint8_clamped).
val of_float_array :
('a, 'b) Brr.Tarray.type' ->
float array ->
('a, 'b) Brr.Tarray.tof_int_array t arr is an array of type t whose elements are the values of arr, values exceeding the range for the type are taken modulo the range bounds (except for Uint8_clamped).
With strings
val of_jstr : Jstr.t -> Brr.Tarray.uint8of_jstr s is an unsigned byte array with s as UTF-8 encoded data.
val to_jstr : Brr.Tarray.uint8 -> (Jstr.t, Jv.Error.t) Stdlib.resultto_jstr a is the UTF-8 encoded data a as a string. Errors if a holds invalid UTF-8.
val of_binary_jstr : Jstr.t -> (Brr.Tarray.uint8, Jv.Error.t) Stdlib.resultof_binary_jstr s is an unsigned byte array with the bytes of the JavaScript binary string s. Errors if a code unit of s is greater than 255.
val to_binary_jstr : Brr.Tarray.uint8 -> Jstr.tto_binary_jstr a is a JavaScript binary string with the unsigned bytes of a.
val to_int_jstr : ?sep:Jstr.t -> ('a, 'b) Brr.Tarray.t -> Jstr.tto_int_jstr ~sep a is a string with the elements of a printed and separated by sep (defaults to Jstr.sp).
val to_hex_jstr : ?sep:Jstr.t -> ('a, 'b) Brr.Tarray.t -> Jstr.tto_hex_jstr ?sep a is a string with the bytes of a printed in lowercase hex and separated by sep (defaults to Jstr.empty).
val to_string : Brr.Tarray.uint8 -> stringto_string a is an OCaml byte string from the byte array.
As bigarrays
val type_to_bigarray_kind :
('a, 'b) Brr.Tarray.type' ->
('a, 'b) Stdlib.Bigarray.kindtype_to_bigarray_kind t is t as a bigarray kind. Uint32 is mapped on Bigarray.int32.
val type_of_bigarray_kind :
('a, 'b) Stdlib.Bigarray.kind ->
('a, 'b) Brr.Tarray.type' optiontype_of_bigarray_kind k is k as a type array type or None if there is no corresponding one.
val bigarray_kind : ('a, 'b) Brr.Tarray.t -> ('a, 'b) Stdlib.Bigarray.kindbigarray_kind a is the bigarray kind of a.
val of_bigarray1 :
('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t ->
('a, 'b) Brr.Tarray.tof_bigarray1 b is a typed array with the data of bigarray b. The data buffer is shared.
val to_bigarray1 :
('a, 'b) Brr.Tarray.t ->
('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.tto_bigarray b is a bigarray with the data of bigarray b. The data buffer is shared.
val of_bigarray :
('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Genarray.t ->
('a, 'b) Brr.Tarray.tof_bigarray b is a typed array with the data of bigarray b. The data buffer is shared. XXX. How is the data laid out ?