Parallel_sequence.With_lengthSequences 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.
'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.
val empty : 'a t @@ portableThe empty sequence.
val range :
?stride:Base.int ->
?start:[ `inclusive | `exclusive ] ->
?stop:[ `inclusive | `exclusive ] ->
Base.int ->
Base.int ->
Base.int t @ local @@ portablerange ?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).
val init :
Base.int ->
f:(Parallel_kernel.t @ local -> (Base.int -> 'a) @ local) @ portable ->
'a t @ local @@ portableinit n ~f is a sequence containing f _ i for each i in 0..n-1.
val of_iarray : 'a. 'a Base.iarray -> 'a t @ local @@ portableof_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.
append s0 s1 returns a sequence containing the elements of s0 and then the elements of s1.
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.
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.
val map :
'a t @ local ->
(f:(Parallel_kernel.t @ local -> ('a -> 'b) @ local) @ portable ->
'b t @ local) @ local @@ portablemap seq ~f converts an 'a sequence to a 'b sequence by applying f to each element of seq.
val iter :
Parallel_kernel.t @ local ->
('a t @ local ->
(f:(Parallel_kernel.t @ local -> ('a -> Base.unit) @ local) @ shareable ->
Base.unit) @ local) @ local @@ portableiter 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.
val fold :
Parallel_kernel.t @ local ->
('a t @ local ->
(init:(Base.unit -> 'acc) @ portable ->
(f:
(Parallel_kernel.t @ local -> ('acc -> ('a -> 'acc) @ local) @ local) @ shareable ->
(combine:
(Parallel_kernel.t @ local -> ('acc -> ('acc -> 'acc) @ local) @ local) @ shareable ->
'acc) @ local) @ local) @ local) @ local @@ portablefold 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.
val reduce :
Parallel_kernel.t @ local ->
('a t @ local ->
(f:
(Parallel_kernel.t @ local -> ('a -> ('a -> 'a) @ local) @ local) @ shareable ->
'a Base.option) @ local) @ local @@ portablereduce 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.
val find :
Parallel_kernel.t @ local ->
('a t @ local ->
(f:(Parallel_kernel.t @ local -> ('a -> Base.bool) @ local) @ shareable ->
'a Base.option) @ local) @ local @@ portablefind 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.
val to_list :
Parallel_kernel.t @ local ->
('a t @ local ->
'a Base.list) @ local @@ portableto_list seq collects a sequence into a list by evaluating each element in parallel. Requires iterating the sequence sequentially.
val to_iarray :
Parallel_kernel.t @ local ->
('a t @ local ->
'a Base.iarray) @ local @@ portableto_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.
val unfold :
's. init:'s ->
next:
(Parallel_kernel.t @ local ->
('s ->
#('a * 's) Unboxed_datatypes.Option_u.t__'value_or_null_value_or_null') @ local) @ portable ->
split_at:
(Parallel_kernel.t @ local ->
('s ->
(n:Base.int ->
#('s * 's) Unboxed_datatypes.Option_u.t__'value_or_null_value_or_null') @ local) @ local) @ portable ->
length:('s -> Base.int) @ portable ->
'a t @ localunfold ~init ~next ~split_at ~length creates a sequence representing the stream of values produced by recursively applying next to init.
next state returns either Some (a,s), representing the element a and the new state s, or None, representing the end of the sequence.
length state must return the exact number of elements next state will produce before returning None.
split_at state ~n optionally returns two states 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 must return Some whenever n > 0 && n < length state
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.
val mapi :
'a t @ local ->
(f:
(Parallel_kernel.t @ local -> (Base.int -> ('a -> 'b) @ local) @ local) @ portable ->
'b t @ local) @ localmapi seq ~f converts an 'a sequence to a 'b sequence by applying f to each element of seq and its index.
val iteri :
Parallel_kernel.t @ local ->
('a t @ local ->
(f:
(Parallel_kernel.t @ local ->
(Base.int ->
('a ->
Base.unit) @ local) @ local) @ shareable ->
Base.unit) @ local) @ localiteri 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.
val foldi :
Parallel_kernel.t @ local ->
('a t @ local ->
(init:(Base.unit -> 'acc) @ portable ->
(f:
(Parallel_kernel.t @ local ->
(Base.int ->
('acc ->
('a ->
'acc) @ local) @ local) @ local) @ shareable ->
(combine:
(Parallel_kernel.t @ local -> ('acc -> ('acc -> 'acc) @ local) @ local) @ shareable ->
'acc) @ local) @ local) @ local) @ localfoldi 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.
val findi :
Parallel_kernel.t @ local ->
('a t @ local ->
(f:
(Parallel_kernel.t @ local ->
(Base.int ->
('a ->
Base.bool) @ local) @ local) @ shareable ->
(Base.int * 'a) Base.option) @ local) @ localfindi 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.