Module Iarray.Slice

type 'a t

Slices represent a contiguous portion of an array.

val length : 'a t @ local contended -> Base.int @@ portable

length t returns the number of elements in t.

val slice : ?i:Base.int -> ?j:Base.int -> 'a t -> 'a t @ local

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

val sub : ?i:Base.int -> ?j:Base.int -> 'a t @ local -> 'a t @ local

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. 'a t @ local -> (Base.int -> 'a) @ local

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. 'a t @ local -> (Base.int -> 'a) @ local

unsafe_get t i unsafely reads the element at index i.

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

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 t @ local -> (Base.int -> (('a -> 'b @ portable contended) @ local once portable -> 'b @ portable contended) @ local) @ local

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

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

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_ : Parallel_kernel.t @ local -> (pivots:Base.int Base.iarray -> ('a t @ local -> (f: (Parallel_kernel.t @ local -> ('a t @ local -> Base.unit) @ local) @ shareable -> Base.unit) @ local) @ local) @ local

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 : Parallel_kernel.t @ local -> (pivots:Base.int Base.iarray -> ('a t @ local -> (f: (Parallel_kernel.t @ local -> (Base.int -> ('a t @ local -> Base.unit) @ local) @ local) @ shareable -> Base.unit) @ local) @ local) @ local

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.