Module Bigarray.SliceSource

type ('a : any mod portable separable) t : (value mod uncontended portable) with 'a

Slices represent a contiguous portion of an array.

val length : ('a : any mod portable separable). 'a t @ local contended -> Base.int @@ portable

length t returns the number of elements in t.

val slice : ('a : value_or_null mod portable separable). ?i:Base.int -> ?j:Base.int -> 'a t -> 'a t @ local @@ portable

slice ~i ~j array is a slice representing array[i..j).

val sub : ('a : value_or_null mod portable separable). ?i:Base.int -> ?j:Base.int -> 'a t @ local -> 'a t @ local @@ portable

sub ~i ~j slice is a slice representing slice[i..j).

To read a value from a parallel array, we must prove that it does not escape its capsule. This is the case if its type crosses contention, or if it is manipulated within a portable function.

val get : ('a : value_or_null mod contended portable separable). 'a t @ local -> Base.int -> 'a @@ portable

get t i reads the element at index i. Raises Invalid_arg if i is not in the range [0..length t).

val unsafe_get : ('a : value_or_null mod contended portable separable). 'a t @ local -> Base.int -> 'a @@ portable

unsafe_get t i unsafely reads the element at index i.

val extract : ('a : value_or_null mod portable separable). 'a t @ local -> Base.int -> ('a -> 'b @ portable contended) @ local once portable -> 'b @ portable contended @@ portable

extract t i f applies f with the element read from index i. Raises Invalid_arg if i is not in the range [0..length t).

val unsafe_extract : ('a : value_or_null mod portable separable). 'a t @ local -> Base.int -> ('a -> 'b @ portable contended) @ local once portable -> 'b @ portable contended @@ portable

unsafe_extract t i f applies f with the element unsafely read from index i.

val fork_join2 : ('a : value_or_null mod portable separable). Parallel_kernel.t @ local -> ?pivot:Base.int -> 'a t @ local -> (Parallel_kernel.t @ local -> ('a t @ local -> 'b) @ local once) @ local once shareable forkable -> (Parallel_kernel.t @ local -> ('a t @ local -> 'c) @ local once) @ once shareable -> #('b * 'c) @@ portable

fork_join2 parallel ~pivot t f g splits the slice t into two sub-slices representing t[0..pivot) and t[pivot..length t), respectively. The sub-slices are passed to f and g, which run in parallel (refer to {Parallel_kernel.fork_join2}).

val for_ : ('a : value_or_null mod portable separable). Parallel_kernel.t @ local -> pivots:Base.int Base.iarray -> 'a t @ local -> f:(Parallel_kernel.t @ local -> 'a t @ local -> Base.unit) @ shareable -> Base.unit @@ portable

for_ parallel ~pivots t ~f splits the slice t into multiple sub-slices representing the ranges t[0..pivots[0]), t[pivots[i]..pivots[i+1]), etc. The function f is evaluated for each sub-slice in parallel. pivots must be non-decreasing, but may have duplicate elements, resulting in empty sub-slices.

val fori : ('a : value_or_null mod portable separable). Parallel_kernel.t @ local -> pivots:Base.int Base.iarray -> 'a t @ local -> f: (Parallel_kernel.t @ local -> Base.int -> 'a t @ local -> Base.unit) @ shareable -> Base.unit @@ portable

fori parallel ~pivots t ~f splits the slice t into multiple sub-slices representing the ranges t[0..pivots[0]), t[pivots[i]..pivots[i+1]), etc. The function f is evaluated for each sub-slice and its index in parallel. pivots must be non-decreasing, but may have duplicate elements.

To read a value from a parallel array, we must prove that it does not escape its capsule. This is the case if its type crosses contention, or if it is manipulated within a portable function.

To store a value in a parallel array, we must prove that it does not share unsynchronized state with any other elements. This is the case if its type crosses contention or it lives in a fresh capsule.

val set : ('a : value_or_null mod contended portable separable). 'a t @ local -> Base.int -> 'a -> Base.unit @@ portable

set t i a stores the element a at index i. Raises Invalid_arg if i is not in the range [0..length t).

val unsafe_set : ('a : value_or_null mod contended portable separable). 'a t @ local -> Base.int -> 'a -> Base.unit @@ portable

unsafe_insert t i f unsafely stores f a at index i.

val insert : ('a : value_or_null mod portable separable). 'a t @ local -> Base.int -> (Base.unit -> 'a) @ local once portable -> Base.unit @@ portable

insert t i f stores f a at index i. Raises Invalid_arg if i is not in the range [0..length t).

val unsafe_insert : ('a : value_or_null mod portable separable). 'a t @ local -> Base.int -> (Base.unit -> 'a) @ local once portable -> Base.unit @@ portable

unsafe_insert t i f unsafely stores f a at index i.