A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
setunique
ArrayFire Functions | ArrayFire Functions by Category » Vector Algorithms » Set operations

## Functions
AFAPI array | setUnique (const array &in, const bool is_sorted=false)
| C++ Interface to return the unique values in an array.
AFAPI af_err | af_set_unique (af_array *out, const af_array in, const bool is_sorted)
| C Interface to return the unique values in an array.
AFAPI array | setunique (const array &in, const bool is_sorted=false)
| C++ Interface to return the unique values in an array.

## Detailed Description

Return the unique values in an array.

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

An example, unsorted:

// 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 };

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

An example, sorted (ascending):

// 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.

An example, sorted (descending):

// 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 to return the unique values in an array.

Parameters

  [out] | out | unique values
  [in] | in | input array
  [in] | is_sorted | if true, skip the sorting steps internally

Returns
  AF_SUCCESS, if function returns successfully, else an af_err code is given

## ◆ setUnique()

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

C++ Interface to return the unique values in an array.

Parameters

  [in] | in | input array
  [in] | is_sorted | if true, skip the sorting steps internally

Returns
  unique values

## ◆ setunique()

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

C++ Interface to return the unique values in an array.

Parameters

  [in] | in | input array
  [in] | is_sorted | if true, skip the sorting steps internally

Returns
  unique values

Deprecated
  Use setUnique instead