| 36 | { |
| 37 | template <typename T> |
| 38 | SimpleTensor<T> slice(const SimpleTensor<T> &src, Coordinates starts, Coordinates ends) |
| 39 | { |
| 40 | using namespace arm_compute::helpers::tensor_transform; |
| 41 | |
| 42 | // Validation checks |
| 43 | ARM_COMPUTE_ERROR_ON(src.shape().num_dimensions() > 4); |
| 44 | ARM_COMPUTE_ERROR_ON(starts.num_dimensions() > src.shape().num_dimensions()); |
| 45 | ARM_COMPUTE_ERROR_ON( |
| 46 | std::any_of(starts.cbegin(), starts.cbegin() + starts.num_dimensions(), [](int i) { return i < 0; })); |
| 47 | ARM_COMPUTE_ERROR_ON(ends.num_dimensions() > src.shape().num_dimensions()); |
| 48 | |
| 49 | // Get source shape |
| 50 | const TensorShape &src_shape = src.shape(); |
| 51 | |
| 52 | // Get destination shape |
| 53 | TensorShape dst_shape = arm_compute::misc::shape_calculator::compute_slice_shape(src_shape, starts, ends); |
| 54 | |
| 55 | // Create destination tensor |
| 56 | SimpleTensor<T> dst{dst_shape, src.data_type(), 1}; |
| 57 | |
| 58 | // Perform slice |
| 59 | Window win; |
| 60 | win.use_tensor_dimensions(dst_shape); |
| 61 | execute_window_loop(win, |
| 62 | [&](const Coordinates &id) |
| 63 | { |
| 64 | Coordinates offset; |
| 65 | for (unsigned int i = 0; i < id.num_dimensions(); ++i) |
| 66 | { |
| 67 | offset.set(i, starts[i] + id[i]); |
| 68 | } |
| 69 | *reinterpret_cast<T *>(dst(id)) = *reinterpret_cast<const T *>(src(offset)); |
| 70 | }); |
| 71 | |
| 72 | return dst; |
| 73 | } |
| 74 | |
| 75 | template SimpleTensor<float> slice(const SimpleTensor<float> &src, Coordinates starts, Coordinates ends); |
| 76 | template SimpleTensor<half_float::half> |
no test coverage detected