 A high-performance general-purpose compute library

Calculate if all values that share the same consecutive keys are true.

Calculate if all values that share the same consecutive keys are true.

Finds if all of the values of an input array are true according to an array of keys. All values corresponding to each group of consecutive equal keys will be tested to make sure all are true. Keys can repeat, however only consecutive key values will be considered for each reduction. If a key value is repeated somewhere else in the keys array it will be considered the start of a new reduction. There are two outputs: the reduced set of consecutive keys and the corresponding final reduced values. An example demonstrating the reduction behavior can be seen in the following snippet.

array keys(9, hkeys); // keys = [ 0 0 1 1 1 0 0 2 2 ]
array vals(9, hvals); // vals = [ 1 1 0 1 1 0 0 1 0 ];
array okeys, ovals;
allTrueByKey(okeys, ovals, keys, vals);
// okeys = [ 0 1 0 2 ]
// ovals = [ 1 0 0 0 ]

The keys input type must be an integer type(s32 or u32). The values return type will be of type b8.

The input keys must be a 1-D vector matching the size of the reduced dimension. In the case of multiple dimensions in the input values array, the dim parameter specifies which dimension to reduce along. An example of multi-dimensional reduce by key can be seen below:

array keys(5, hkeys);
array vals(2, 5, hvals);
// keys = [ 1 0 0 2 2 ]
// vals = [[ 1 1 1 0 1 ]
// [ 0 1 0 1 1 ]]
const int reduce_dim = 1;
array okeys, ovals;
allTrueByKey(okeys, ovals, keys, vals, reduce_dim);
// okeys = [ 1 0 2 ]
// ovals = [[ 1 1 0 ],
// [ 0 0 1 ]]