Compute Library
 23.05
CLSlice Class Reference

Basic function to perform tensor slicing. More...

#include <CLSlice.h>

Collaboration diagram for CLSlice:
[legend]

Public Member Functions

void configure (const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output, const Coordinates &starts, const Coordinates &ends)
 Configure kernel. More...
 
- Public Member Functions inherited from ICLOperator
 ICLOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 ICLOperator (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLOperator (ICLOperator &&)=default
 Default move constructor. More...
 
ICLOperatoroperator= (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLOperatoroperator= (ICLOperator &&)=default
 Default move assignment operator. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
void prepare (ITensorPack &constants) override
 Prepare the function for executing. More...
 
MemoryRequirements workspace () const override
 Return the memory requirements required by the workspace. More...
 
- Public Member Functions inherited from IOperator
virtual ~IOperator ()=default
 Destructor. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends)
 Static function to check if given info will lead to a valid configuration of CLSlice. More...
 

Detailed Description

Basic function to perform tensor slicing.

Definition at line 116 of file CLSlice.h.

Member Function Documentation

◆ configure()

void configure ( const CLCompileContext compile_context,
const ITensorInfo input,
ITensorInfo output,
const Coordinates starts,
const Coordinates ends 
)

Configure kernel.

Note
Supported tensor rank: up to 4
Start indices must be non-negative. 0 <= starts[i]
End coordinates can be negative, which represents the number of elements before the end of that dimension.
End indices are not inclusive unless negative.
Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor info. Data type supported: All.
[out]outputDestination tensor info. Data type supported: Same as input
[in]startsThe starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]endsThe ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).

Definition at line 37 of file CLSlice.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_LOG_PARAMS, arm_compute::helpers::tensor_transform::construct_slice_end_mask(), and arm_compute::test::validation::k.

38 {
40  ARM_COMPUTE_LOG_PARAMS(input, output, starts, ends);
41 
42  // Get absolute end coordinates
43  const int32_t slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(ends);
44 
45  auto k = std::make_unique<CLStridedSliceKernel>();
46  k->configure(compile_context, input, output, starts, ends, BiStrides(), 0, slice_end_mask, 0);
47  _kernel = std::move(k);
48 }
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:53
int32_t construct_slice_end_mask(Coordinates ends)
Constructs end mask in case we want to perform a slice operation using the strided slice interface...
#define ARM_COMPUTE_LOG_PARAMS(...)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const Coordinates starts,
const Coordinates ends 
)
static

Static function to check if given info will lead to a valid configuration of CLSlice.

Note
Supported tensor rank: up to 4
Start indices must be non-negative. 0 <= starts[i]
End coordinates can be negative, which represents the number of elements before the end of that dimension.
End indices are not inclusive unless negative.
Parameters
[in]inputSource tensor info. Data type supported: All
[in]outputDestination tensor info. Data type supported: Same as input
[in]startsThe starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]endsThe ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
Returns
A status

Definition at line 50 of file CLSlice.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, Dimensions< T >::cbegin(), arm_compute::helpers::tensor_transform::construct_slice_end_mask(), arm_compute::test::validation::dst, Dimensions< T >::num_dimensions(), arm_compute::test::validation::src, and CLStridedSliceKernel::validate().

Referenced by CLSlice::validate().

51 {
53 
54  // Check start dimensions for being non-negative
55  ARM_COMPUTE_RETURN_ERROR_ON(std::any_of(starts.cbegin(), starts.cbegin() + starts.num_dimensions(), [](int i)
56  {
57  return i < 0;
58  }));
59 
60  // Get absolute end coordinates
61  const int32_t slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(ends);
62 
63  return CLStridedSliceKernel::validate(input, output, starts, ends, BiStrides(), 0, slice_end_mask, 0);
64 }
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:53
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
int32_t construct_slice_end_mask(Coordinates ends)
Constructs end mask in case we want to perform a slice operation using the strided slice interface...
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
Static function to check if given info will lead to a valid configuration of CLStridedSliceKernel.

The documentation for this class was generated from the following files: