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

Function slice

tests/validation/reference/SliceOperations.cpp:38–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36{
37template <typename T>
38SimpleTensor<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
75template SimpleTensor<float> slice(const SimpleTensor<float> &src, Coordinates starts, Coordinates ends);
76template SimpleTensor<half_float::half>

Callers 4

conv2d_dftFunction · 0.85
compute_referenceMethod · 0.85
compute_referenceMethod · 0.85
compute_referenceMethod · 0.85

Calls 6

compute_slice_shapeFunction · 0.85
num_dimensionsMethod · 0.45
shapeMethod · 0.45
cbeginMethod · 0.45
data_typeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected