A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
minByKey
ArrayFire Functions | ArrayFire Functions by Category » Vector Algorithms » Reduction operations

## Functions
AFAPI void | minByKey (array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
| C++ Interface to return the minimum along a given dimension, according to an array of keys.
AFAPI af_err | af_min_by_key (af_array *keys_out, af_array *vals_out, const af_array keys, const af_array vals, const int dim)
| C Interface to return the minimum along a given dimension, according to an array of keys.

## Detailed Description

Return the minimum along a given dimension, according to an array of keys.

The minimum is returned from the values corresponding to each group of consecutive equal keys. 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 set of 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 2 3 4 5 6 7 8 9 ];
array okeys, ovals;
minByKey(okeys, ovals, keys, vals);
// okeys = [ 0 1 0 2 ]
// ovals = [ 1 3 6 8 ]

The keys' input type must be integer (s32 or u32).

The output type is the same as input type.

The keys array must be 1-dimenstional matching the size of the reduced dimension. 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 2 3 4 5 ]
// [ 6 7 8 9 10 ]]
const int reduce_dim = 1;
array okeys, ovals;
minByKey(okeys, ovals, keys, vals, reduce_dim);
// okeys = [ 1 0 2 ]
// ovals = [[ 1 2 4 ],
// [ 6 7 9 ]]

## Function Documentation

## ◆ af_min_by_key()

AFAPI af_err af_min_by_key | ( | af_array * | keys_out,
|  | af_array * | vals_out,
|  | const af_array | keys,
|  | const af_array | vals,
|  | const int | dim )

C Interface to return the minimum along a given dimension, according to an array of keys.

Parameters

  [out] | keys_out | reduced keys
  [out] | vals_out | minimum
  [in] | keys | keys array
  [in] | vals | input array
  [in] | dim | dimension along which the minimum is found

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

## ◆ minByKey()

AFAPI void minByKey | ( | array & | keys_out,
|  | array & | vals_out,
|  | const array & | keys,
|  | const array & | vals,
|  | const int | dim = -1 )

C++ Interface to return the minimum along a given dimension, according to an array of keys.

NaN values are ignored.

Parameters

  [out] | keys_out | reduced keys
  [out] | vals_out | minimum
  [in] | keys | keys array
  [in] | vals | input array
  [in] | dim | dimension along which the minimum is found, -1 denotes the first non-singleton dimension