Module Parallel_sequence.With_lengthSource

Sequences of type 'a With_length.t are guaranteed to have a known length. When the length is known, collecting the sequence can be more efficient. Note that concat and filter functions are not supported.

Sourcetype ('a : value_or_null) t : value mod contended portable

'a t represents a finite sequence of independent computations that produce an 'a. These computations are evaluated in parallel upon collecting the sequence into a strict data structure. Parallel sequences are distinguished from normal sequences by supporting the split operation, which divides a sequence into two parts that may be collected in parallel.

Sourceval empty : 'a t @@ portable

The empty sequence.

Sourceval globalize : ('a : value_or_null). 'a t @ local -> 'a t @@ portable

globalize seq copies a local sequence to the heap.

Sourceval range : ?stride:Base.int -> ?start:[ `inclusive | `exclusive ] -> ?stop:[ `inclusive | `exclusive ] -> Base.int -> Base.int -> Base.int t @ local @@ portable

range ?stride ?start ?stop start_i stop_i is the sequence of integers from start_i to stop_i, stepping by stride. If stride < 0 then we need start_i > stop_i for the result to be nonempty (or start_i >= stop_i in the case where both bounds are inclusive).

Sourceval init : ('a : value_or_null). Base.int -> f:(Parallel_kernel.t @ local -> Base.int -> 'a) @ portable -> 'a t @ local @@ portable

init n ~f is a sequence containing f _ i for each i in 0..n-1.

Sourceval of_iarray : ('a : value_or_null mod contended portable separable). 'a Base.iarray -> 'a t @ local @@ portable

of_iarray i is a sequence containing the contents of the iarray i. This sequence has a known length and may be split in constant time.

Sourceval append : ('a : value_or_null). 'a t @ local -> 'a t @ local -> 'a t @ local @@ portable

append s0 s1 returns a sequence containing the elements of s0 and then the elements of s1.

Sourceval product_left : ('a : value_or_null mod contended portable). 'a t @ local -> 'b t @ local -> ('a * 'b) t @ local @@ portable

product_left seq0 seq1 joins an 'a sequence and a 'b sequence into an ('a * 'b) sequence by pairing each element of seq0 with a copy of seq1.

Sourceval product_right : ('b : value_or_null mod contended portable). 'a t @ local -> 'b t @ local -> ('a * 'b) t @ local @@ portable

product_right seq0 seq1 joins an 'a sequence and a 'b sequence into an ('a * 'b) sequence by pairing each element of seq1 with a copy of seq0.

Sourceval map : ('a : value_or_null). 'a t @ local -> f:(Parallel_kernel.t @ local -> 'a -> 'b) @ portable -> 'b t @ local @@ portable

map seq ~f converts an 'a sequence to a 'b sequence by applying f to each element of seq.

Sourceval iter : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> f:(Parallel_kernel.t @ local -> 'a -> Base.unit) @ shareable -> Base.unit @@ portable

iter parallel seq ~f applies f to each element of seq in parallel. The order in which f is applied is unspecified and potentially non-deterministic.

Sourceval fold : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> init:(Base.unit -> 'acc) @ portable -> f:(Parallel_kernel.t @ local -> 'acc -> 'a -> 'acc) @ shareable -> combine:(Parallel_kernel.t @ local -> 'acc -> 'acc -> 'acc) @ shareable -> 'acc @@ portable

fold parallel seq ~f ~init ~combine folds combine over map seq ~f in parallel. combine and init must form a monoid over 'acc: combine must be associative and init () must be a neutral element. The order in which f and combine are applied is unspecified and potentially non-deterministic.

Sourceval reduce : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> f:(Parallel_kernel.t @ local -> 'a -> 'a -> 'a) @ shareable -> 'a Base.option @@ portable

reduce parallel seq ~f reduces seq using f in parallel. f must be associative. If the sequence is empty, reduce returns None. The order in which f is applied is unspecified and potentially non-deterministic.

Sourceval find : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> f:(Parallel_kernel.t @ local -> 'a -> Base.bool) @ shareable -> 'a Base.option @@ portable

find parallel seq ~f returns the first element of seq for which f returns true, if it exists. f will always be applied to every element of seq. The order in which f is applied is unspecified and potentially non-deterministic.

Sourceval to_list : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> 'a Base.list @@ portable

to_list seq collects a sequence into a list by evaluating each element in parallel. Requires iterating the sequence sequentially.

Sourceval to_iarray : ('a : value_or_null mod non_float). Parallel_kernel.t @ local -> 'a t @ local -> 'a Base.iarray @@ portable

to_iarray seq collects a sequence into an iarray by evaluating each element in parallel. If the sequence has a known length, does not require iterating the sequence sequentially.

Sourceval length : ('a : value_or_null). 'a t @ local -> Base.int

length seq returns the number of elements in seq.

Sourceval unfold : ('a : value_or_null) ('s : value_or_null mod contended portable). init:'s -> next:(Parallel_kernel.t @ local -> 's -> #('a * 's)) @ portable -> split_at: (Parallel_kernel.t @ local -> 's -> n:Base.int -> #('s * 's)) @ portable -> length:('s -> Base.int) @ portable -> 'a t @ local

unfold ~init ~next ~split_at ~length creates a sequence representing the stream of values produced by recursively applying next to init.

length state must return the number of elements in the sequence generated by unfolding state.

next state must return #(a, s), where a is the first element of the sequence and unfolding s generates the rest of the sequence. next will only be called when length state > 0.

split_at state ~n must return #(s0, s1) such that length s0 = n and the concatenation of the unfoldings of s0 and s1 produces the same elements as the original sequence. split_at will only be called when length state > 1 and may assume n > 0 && n < length state.

Sourceval zip_exn : ('a : value_or_null) ('b : value_or_null). 'a t @ local -> 'b t @ local -> ('a * 'b) t @ local

zip_exn seq0 seq1 joins an 'a sequence and a 'b sequence into a ('a * 'b) sequence by pairing each element. Raises if the two sequences do not have equal lengths.

Sourceval mapi : ('a : value_or_null) ('b : value_or_null). 'a t @ local -> f:(Parallel_kernel.t @ local -> Base.int -> 'a -> 'b) @ portable -> 'b t @ local

mapi seq ~f converts an 'a sequence to a 'b sequence by applying f to each element of seq and its index.

Sourceval iteri : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> f:(Parallel_kernel.t @ local -> Base.int -> 'a -> Base.unit) @ shareable -> Base.unit

iteri parallel seq ~f applies f to each element of seq and its index, in parallel. The order in which f is applied is unspecified and potentially non-deterministic.

Sourceval foldi : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> init:(Base.unit -> 'acc) @ portable -> f:(Parallel_kernel.t @ local -> Base.int -> 'acc -> 'a -> 'acc) @ shareable -> combine:(Parallel_kernel.t @ local -> 'acc -> 'acc -> 'acc) @ shareable -> 'acc

foldi parallel seq ~f ~init ~combine folds combine over mapi seq ~f in parallel. combine and init must form a monoid over 'acc: combine must be associative and init must be a neutral element. The order in which f and combine are applied is unspecified and potentially non-deterministic.

Sourceval findi : ('a : value_or_null). Parallel_kernel.t @ local -> 'a t @ local -> f:(Parallel_kernel.t @ local -> Base.int -> 'a -> Base.bool) @ shareable -> (Base.int * 'a) Base.option

findi parallel seq ~f returns the first element of seq, along with its index i, for which f returns true, if it exists. f will always be applied to every element of seq. The order in which f is applied is unspecified and potentially non-deterministic.