MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / strided_slice

Function strided_slice

tests/validation/reference/SliceOperations.cpp:80–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78
79template <typename T>
80SimpleTensor<T> strided_slice(const SimpleTensor<T> &src,
81 Coordinates starts,
82 Coordinates ends,
83 BiStrides strides,
84 int32_t begin_mask,
85 int32_t end_mask,
86 int32_t shrink_axis_mask)
87{
88 using namespace arm_compute::helpers::tensor_transform;
89
90 // Validation checks
91 ARM_COMPUTE_ERROR_ON(src.shape().num_dimensions() > 4);
92 ARM_COMPUTE_ERROR_ON(starts.num_dimensions() > src.shape().num_dimensions());
93 ARM_COMPUTE_ERROR_ON(ends.num_dimensions() > src.shape().num_dimensions());
94 ARM_COMPUTE_ERROR_ON(strides.num_dimensions() > src.shape().num_dimensions());
95 ARM_COMPUTE_ERROR_ON(
96 std::any_of(strides.cbegin(), strides.cbegin() + strides.num_dimensions(), [](int i) { return i == 0; }));
97
98 // Get source shape
99 const TensorShape &src_shape = src.shape();
100
101 // Get destination shape
102 const TensorShape dst_shape =
103 compute_strided_slice_output_shape(src_shape, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
104
105 // Create destination tensor
106 SimpleTensor<T> dst{dst_shape, src.data_type(), 1};
107
108 // Get coordinates
109 Coordinates starts_abs{};
110 Coordinates ends_abs{};
111 Coordinates final_strides{};
112 std::tie(starts_abs, ends_abs, final_strides) =
113 calculate_strided_slice_coords(src_shape, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
114
115 // Perform strided slice
116 unsigned int idx = 0;
117 Window win;
118 win.use_tensor_dimensions(compute_strided_slice_output_shape(src_shape, starts, ends, strides, begin_mask, end_mask,
119 shrink_axis_mask, true));
120 execute_window_loop(win,
121 [&](const Coordinates &id)
122 {
123 Coordinates offset;
124 for (unsigned int i = 0; i < id.num_dimensions(); ++i)
125 {
126 offset.set(i, starts_abs[i] + id[i] * final_strides[i]);
127 }
128 dst.data()[idx++] = *reinterpret_cast<const T *>(src(offset));
129 });
130
131 return dst;
132}
133
134template SimpleTensor<float> strided_slice(const SimpleTensor<float> &src,
135 Coordinates starts,

Callers 1

compute_referenceMethod · 0.85

Calls 8

num_dimensionsMethod · 0.45
shapeMethod · 0.45
cbeginMethod · 0.45
data_typeMethod · 0.45
setMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected