Select K

View as Markdown

Source header: cuvs/selection/select_k.hpp

Batched-select k smallest or largest key/values

selection::select_k

Select k smallest or largest key/values from each row in the input data.

1void select_k(
2raft::resources const& handle,
3raft::device_matrix_view<const float, int64_t, raft::row_major> in_val,
4std::optional<raft::device_matrix_view<const int64_t, int64_t, raft::row_major>> in_idx,
5raft::device_matrix_view<float, int64_t, raft::row_major> out_val,
6raft::device_matrix_view<int64_t, int64_t, raft::row_major> out_idx,
7bool select_min,
8bool sorted = false,
9SelectAlgo algo = SelectAlgo::kAuto,
10std::optional<raft::device_vector_view<const int64_t, int64_t>> len_i = std::nullopt);

If you think of the input data in_val as a row-major matrix with len columns and batch_size rows, then this function selects k smallest/largest values in each row and fills in the row-major matrix out_val of size (batch_size, k).

Example usage

Parameters

NameDirectionTypeDescription
handleinraft::resources const&container of reusable resources
in_valinraft::device_matrix_view<const float, int64_t, raft::row_major>inputs values [batch_size, len]; these are compared and selected.
in_idxinstd::optional<raft::device_matrix_view<const int64_t, int64_t, raft::row_major>>optional input payload [batch_size, len]; typically, these are indices of the corresponding in_val. If in_idx is std::nullopt, a contiguous array 0...len-1 is implied.
out_valoutraft::device_matrix_view<float, int64_t, raft::row_major>output values [batch_size, k]; the k smallest/largest values from each row of the in_val.
out_idxoutraft::device_matrix_view<int64_t, int64_t, raft::row_major>output payload (e.g. indices) [batch_size, k]; the payload selected together with out_val.
select_mininboolwhether to select k smallest (true) or largest (false) keys.
sortedinboolwhether to make sure selected pairs are sorted by value Default: false.
algoinSelectAlgothe selection algorithm to use Default: SelectAlgo::kAuto.
len_iinstd::optional<raft::device_vector_view<const int64_t, int64_t>>optional array of size (batch_size) providing lengths for each individual row Default: std::nullopt.

Returns

void

Additional overload: selection::select_k

Select k smallest or largest key/values from each row in the input data.

1void select_k(
2raft::resources const& handle,
3raft::device_matrix_view<const float, int64_t, raft::row_major> in_val,
4std::optional<raft::device_matrix_view<const uint32_t, int64_t, raft::row_major>> in_idx,
5raft::device_matrix_view<float, int64_t, raft::row_major> out_val,
6raft::device_matrix_view<uint32_t, int64_t, raft::row_major> out_idx,
7bool select_min,
8bool sorted = false,
9SelectAlgo algo = SelectAlgo::kAuto,
10std::optional<raft::device_vector_view<const uint32_t, int64_t>> len_i = std::nullopt);

If you think of the input data in_val as a row-major matrix with len columns and batch_size rows, then this function selects k smallest/largest values in each row and fills in the row-major matrix out_val of size (batch_size, k).

Example usage

Parameters

NameDirectionTypeDescription
handleinraft::resources const&container of reusable resources
in_valinraft::device_matrix_view<const float, int64_t, raft::row_major>inputs values [batch_size, len]; these are compared and selected.
in_idxinstd::optional<raft::device_matrix_view<const uint32_t, int64_t, raft::row_major>>optional input payload [batch_size, len]; typically, these are indices of the corresponding in_val. If in_idx is std::nullopt, a contiguous array 0...len-1 is implied.
out_valoutraft::device_matrix_view<float, int64_t, raft::row_major>output values [batch_size, k]; the k smallest/largest values from each row of the in_val.
out_idxoutraft::device_matrix_view<uint32_t, int64_t, raft::row_major>output payload (e.g. indices) [batch_size, k]; the payload selected together with out_val.
select_mininboolwhether to select k smallest (true) or largest (false) keys.
sortedinboolwhether to make sure selected pairs are sorted by value Default: false.
algoinSelectAlgothe selection algorithm to use Default: SelectAlgo::kAuto.
len_iinstd::optional<raft::device_vector_view<const uint32_t, int64_t>>optional array of size (batch_size) providing lengths for each individual row Default: std::nullopt.

Returns

void

Additional overload: selection::select_k

Select k smallest or largest key/values from each row in the input data.

1void select_k(
2raft::resources const& handle,
3raft::device_matrix_view<const half, int64_t, raft::row_major> in_val,
4std::optional<raft::device_matrix_view<const uint32_t, int64_t, raft::row_major>> in_idx,
5raft::device_matrix_view<half, int64_t, raft::row_major> out_val,
6raft::device_matrix_view<uint32_t, int64_t, raft::row_major> out_idx,
7bool select_min,
8bool sorted = false,
9SelectAlgo algo = SelectAlgo::kAuto,
10std::optional<raft::device_vector_view<const uint32_t, int64_t>> len_i = std::nullopt);

If you think of the input data in_val as a row-major matrix with len columns and batch_size rows, then this function selects k smallest/largest values in each row and fills in the row-major matrix out_val of size (batch_size, k).

Example usage

Parameters

NameDirectionTypeDescription
handleinraft::resources const&container of reusable resources
in_valinraft::device_matrix_view<const half, int64_t, raft::row_major>inputs values [batch_size, len]; these are compared and selected.
in_idxinstd::optional<raft::device_matrix_view<const uint32_t, int64_t, raft::row_major>>optional input payload [batch_size, len]; typically, these are indices of the corresponding in_val. If in_idx is std::nullopt, a contiguous array 0...len-1 is implied.
out_valoutraft::device_matrix_view<half, int64_t, raft::row_major>output values [batch_size, k]; the k smallest/largest values from each row of the in_val.
out_idxoutraft::device_matrix_view<uint32_t, int64_t, raft::row_major>output payload (e.g. indices) [batch_size, k]; the payload selected together with out_val.
select_mininboolwhether to select k smallest (true) or largest (false) keys.
sortedinboolwhether to make sure selected pairs are sorted by value Default: false.
algoinSelectAlgothe selection algorithm to use Default: SelectAlgo::kAuto.
len_iinstd::optional<raft::device_vector_view<const uint32_t, int64_t>>optional array of size (batch_size) providing lengths for each individual row Default: std::nullopt.

Returns

void