Abstract

Irregular segmented operations, like scans and reductions.

Synopsis

val segmented_scan [n] 't : (op: t -> t -> t) -> (ne: t) -> (flags: [n]bool) -> (as: [n]t) -> [n]t
val segmented_reduce [n] 't : (op: t -> t -> t) -> (ne: t) -> (flags: [n]bool) -> (as: [n]t) -> *[]t
val replicated_iota [n] : (reps: [n]i32) -> []i32
val segmented_iota [n] : (flags: [n]bool) -> [n]i32
val expand 'a 'b : (sz: a -> i32) -> (get: a -> i32 -> b) -> (arr: []a) -> []b

Description

val segmented_scan [n] 't: (op: t -> t -> t) -> (ne: t) -> (flags: [n]bool) -> (as: [n]t) -> [n]t

Segmented scan. Given a binary associative operator op with neutral element ne, computes the inclusive prefix scan of the segments of as specified by the flags array, where true starts a segment and false continues a segment.

val segmented_reduce [n] 't: (op: t -> t -> t) -> (ne: t) -> (flags: [n]bool) -> (as: [n]t) -> *[]t

Segmented reduction. Given a binary associative operator op with neutral element ne, computes the reduction of the segments of as specified by the flags array, where true starts a segment and false continues a segment. One value is returned per segment.

val replicated_iota [n]: (reps: [n]i32) -> []i32

Replicated iota. Given a repetition array, the function returns an array with each index (starting from 0) repeated according to the repetition array. As an example, replicated_iota [2,3,1] returns the array [0,0,1,1,1,2].

val segmented_iota [n]: (flags: [n]bool) -> [n]i32

Segmented iota. Given a flags array, the function returns an array of index sequences, each of which is reset according to the flags array. As an examples, segmented_iota [false,false,false,true,false,false,false] returns the array [0,1,2,0,1,2,3].

val expand 'a 'b: (sz: a -> i32) -> (get: a -> i32 -> b) -> (arr: []a) -> []b

Generic expansion function. The function expands a source array into a target array given (1) a function that determines, for each source element, how many target elements it expands to and (2) a function that computes a particular target element based on a source element and the target element number associated with the source. As an example, the expression expand (\x->x) (*) [2,3,1] returns the array [0,2,0,3,6,0].