| 37 | { |
| 38 | template <typename T> |
| 39 | SimpleTensor<T> select(const SimpleTensor<uint8_t> &c, const SimpleTensor<T> &x, const SimpleTensor<T> &y) |
| 40 | { |
| 41 | // Check if condition has the same rank as c |
| 42 | const bool is_same_rank = (c.shape().num_dimensions() == x.shape().num_dimensions()); |
| 43 | |
| 44 | // Check shapes |
| 45 | ARM_COMPUTE_ERROR_ON(x.shape() != y.shape()); |
| 46 | ARM_COMPUTE_ERROR_ON(is_same_rank && (x.shape() != c.shape())); |
| 47 | ARM_COMPUTE_ERROR_ON(!is_same_rank && (c.shape().num_dimensions() > 1) && |
| 48 | (c.shape().x() != x.shape()[x.shape().num_dimensions() - 1])); |
| 49 | |
| 50 | // Create reference |
| 51 | SimpleTensor<T> dst{x.shape(), x.data_type(), 1}; |
| 52 | |
| 53 | // Run select core |
| 54 | if (is_same_rank) |
| 55 | { |
| 56 | for (int i = 0; i < x.num_elements(); ++i) |
| 57 | { |
| 58 | dst[i] = c[i] > 0 ? x[i] : y[i]; |
| 59 | } |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | T *output_ptr = dst.data(); |
| 64 | |
| 65 | const int outer_size = c.num_elements(); |
| 66 | const int inner_size = x.num_elements() / outer_size; |
| 67 | size_t offset = 0; |
| 68 | |
| 69 | for (int i = 0; i < outer_size; ++i) |
| 70 | { |
| 71 | const T *input_ptr = c[i] > 0 ? x.data() : y.data(); |
| 72 | memcpy(output_ptr + offset, input_ptr + offset, inner_size * sizeof(T)); |
| 73 | offset += inner_size; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return dst; |
| 78 | } |
| 79 | |
| 80 | template SimpleTensor<uint8_t> |
| 81 | select(const SimpleTensor<uint8_t> &c, const SimpleTensor<uint8_t> &x, const SimpleTensor<uint8_t> &y); |
nothing calls this directly
no test coverage detected