Selects elements from two arrays based on the values of a binary conditional array.
More...
|
AFAPI array | select (const array &cond, const array &a, const array &b) |
|
AFAPI array | select (const array &cond, const array &a, const double &b) |
|
AFAPI array | select (const array &cond, const double &a, const array &b) |
|
AFAPI af_err | af_select (af_array *out, const af_array cond, const af_array a, const af_array b) |
|
AFAPI af_err | af_select_scalar_r (af_array *out, const af_array cond, const af_array a, const double b) |
|
AFAPI af_err | af_select_scalar_l (af_array *out, const af_array cond, const double a, const af_array b) |
|
Selects elements from two arrays based on the values of a binary conditional array.
Creates a new array that is composed of values either from array a
or array b
, based on a third conditional array. For all non-zero elements in the conditional array, the output array will contain values from a
. Otherwise the output will contain values from b
.
int elements = 9;
char hCond[] = {1, 0, 1, 0, 1, 0, 1, 0, 1};
float hA[] = {2, 2, 2, 2, 2, 2, 2, 2, 2};
float hB[] = {3, 3, 3, 3, 3, 3, 3, 3, 3};
array cond(elements, hCond);
AFAPI array select(const array &cond, const array &a, const array &b)
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
is equivalent to:
vector<float> hOut(elements);
for (size_t i = 0; i < hOut.size(); i++) {
if (hCond[i]) {
hOut[i] = hA[i];
} else {
hOut[i] = hB[i];
}
}
The conditional array must be a b8 typed array.
The select function can perform batched operations based on the size of each of the inputs. The following table describes the input and output sizes for supported batched configurations.
Output | Condition Array | Array A | Array B |
(M, N) | (M, 1) | (M, 1) | (M, N) |
(M, N) | (M, 1) | (M, N) | (M, 1) |
(M, N) | (M, 1) | (M, N) | (M, N) |
(M, N) | (M, N) | (M, 1) | (M, N) |
(M, N) | (M, N) | (M, 1) | (M, N) |
◆ af_select()
- Parameters
-
[out] | out | is the output containing elements of a when cond is true else elements from b |
[in] | cond | is the conditional array |
[in] | a | is the array containing elements from the true part of the condition |
[in] | b | is the array containing elements from the false part of the condition |
◆ af_select_scalar_l()
- Parameters
-
[out] | out | is the output containing elements of a when cond is true else elements from b |
[in] | cond | is the conditional array |
[in] | a | is a scalar assigned to out when cond is true |
[in] | b | is the array containing elements from the false part of the condition |
◆ af_select_scalar_r()
- Parameters
-
[out] | out | is the output containing elements of a when cond is true else elements from b |
[in] | cond | is the conditional array |
[in] | a | is the array containing elements from the true part of the condition |
[in] | b | is a scalar assigned to out when cond is false |
◆ select() [1/3]
- Parameters
-
[in] | cond | is the conditional array |
[in] | a | is the array containing elements from the true part of the condition |
[in] | b | is the array containing elements from the false part of the condition |
- Returns
- the output containing elements of
a
when cond
is true else elements from b
◆ select() [2/3]
- Parameters
-
[in] | cond | is the conditional array |
[in] | a | is the array containing elements from the true part of the condition |
[in] | b | is a scalar assigned to out when cond is false |
- Returns
- the output containing elements of
a
when cond
is true else the value b
◆ select() [3/3]
- Parameters
-
[in] | cond | is the conditional array |
[in] | a | is a scalar assigned to out when cond is true |
[in] | b | is the array containing elements from the false part of the condition |
- Returns
- the output containing the value
a
when cond
is true else elements from b