A high-performance general-purpose compute library

Finds unique values from an input set. More...

Functions

AFAPI array setUnique (const array &in, const bool is_sorted=false)
 C++ Interface for getting unique values.
 
AFAPI af_err af_set_unique (af_array *out, const af_array in, const bool is_sorted)
 C Interface for getting unique values.
 
AFAPI array setunique (const array &in, const bool is_sorted=false)
 

Detailed Description

Finds unique values from an input set.

The input must be a one-dimensional array. Batching is not currently supported.

A simple example of finding the unique values of a set using setUnique() can be seen below:

// input data
int h_set[6] = {3, 2, 3, 3, 2, 1};
af::array set(6, h_set);
af::array unique = setUnique(set);
// unique == { 1, 2, 3 };
A multi dimensional data container.
Definition: array.h:37

The function can be sped up if it is known that the inputs are sorted.

// input data
int h_set[6] = {1, 2, 2, 3, 3, 3};
af::array set(6, h_set);
// is_sorted flag specifies if input is sorted,
// allows algorithm to skip internal sorting step
const bool is_sorted = true;
af::array unique = setUnique(set, is_sorted);
// unique == { 1, 2, 3 };

The inputs can be sorted in ascending or descending order.

// input data
int h_set[6] = {3, 3, 3, 2, 2, 1};
af::array set(6, h_set);
// is_sorted flag specifies if input is sorted,
// allows algorithm to skip internal sorting step
// input can be sorted in ascending or descending order
const bool is_sorted = true;
af::array unique = setUnique(set, is_sorted);
// unique == { 3, 2, 1 };

Function Documentation

◆ af_set_unique()

AFAPI af_err af_set_unique ( af_array out,
const af_array  in,
const bool  is_sorted 
)

C Interface for getting unique values.

Parameters
[out]outwill contain the unique values from in
[in]inis the input array
[in]is_sortedif true, skips the sorting steps internally
Returns
AF_SUCCESS if the execution completes properly

◆ setUnique()

AFAPI array setUnique ( const array in,
const bool  is_sorted = false 
)

C++ Interface for getting unique values.

Parameters
[in]inis the input array
[in]is_sortedif true, skips the sorting steps internally
Returns
the unique values from in

◆ setunique()

AFAPI array setunique ( const array in,
const bool  is_sorted = false 
)

C++ Interface for getting unique values.

Parameters
[in]inis the input array
[in]is_sortedif true, skips the sorting steps internally
Returns
the unique values from in
Deprecated:
Use setUnique instead