ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci_interpreter::kernels::ExpandDims Class Reference

#include <ExpandDims.h>

Collaboration diagram for luci_interpreter::kernels::ExpandDims:

Public Member Functions

 ExpandDims (const Tensor *input, const Tensor *axis, Tensor *output)
 
const Tensorinput () const
 
const Tensoraxis () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
- Public Member Functions inherited from luci_interpreter::Kernel
virtual ~Kernel ()=default
 
const std::vector< const Tensor * > & getInputTensors () const
 
const std::vector< Tensor * > & getOutputTensors () const
 

Additional Inherited Members

- Protected Member Functions inherited from luci_interpreter::Kernel
 Kernel (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
 
- Protected Attributes inherited from luci_interpreter::Kernel
const std::vector< const Tensor * > _inputs
 
const std::vector< Tensor * > _outputs
 

Detailed Description

Definition at line 28 of file ExpandDims.h.

Constructor & Destructor Documentation

◆ ExpandDims()

luci_interpreter::kernels::ExpandDims::ExpandDims ( const Tensor input,
const Tensor axis,
Tensor output 
)

Definition at line 25 of file ExpandDims.cpp.

26 : Kernel({input, axis}, {output})
27{
28}
Kernel(std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
Definition Kernel.h:31

References axis(), and input().

Member Function Documentation

◆ axis()

const Tensor * luci_interpreter::kernels::ExpandDims::axis ( ) const
inline

Definition at line 34 of file ExpandDims.h.

34{ return _inputs[1]; }
const std::vector< const Tensor * > _inputs
Definition Kernel.h:52

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), and ExpandDims().

◆ configure()

void luci_interpreter::kernels::ExpandDims::configure ( )
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 30 of file ExpandDims.cpp.

31{
32 int32_t axis_value;
33
34 switch (axis()->element_type())
35 {
36 case loco::DataType::S32:
37 axis_value = *getTensorData<int32_t>(axis());
38 break;
39 case loco::DataType::S64:
40 axis_value = static_cast<int32_t>(*getTensorData<int64_t>(axis()));
41 break;
42 default:
43 throw std::runtime_error("luci-intp ExpandDims Unsupported type.");
44 }
45
46 const auto input_shape = input()->shape();
47
48 if (axis_value < 0)
49 {
50 axis_value += input_shape.num_dims() + 1;
51 }
52
53 LUCI_INTERPRETER_CHECK(axis_value <= input_shape.num_dims() and axis_value >= 0);
54
55 Shape output_shape(input_shape.num_dims() + 1);
56 for (int32_t i = 0; i < output_shape.num_dims(); ++i)
57 {
58 if (i < axis_value)
59 {
60 output_shape.dim(i) = input_shape.dim(i);
61 }
62 else if (i == axis_value)
63 {
64 output_shape.dim(i) = 1;
65 }
66 else
67 {
69 output_shape.dim(i) = input_shape.dim(i - 1);
70 }
71 }
72
74}
int num_dims() const
Definition Tensor.h:39
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
const luci_interpreter::RuntimeShape output_shape
Definition Shape.h:28

References axis(), input(), LUCI_INTERPRETER_CHECK, luci_interpreter::Shape::num_dims(), output(), output_shape, luci_interpreter::Tensor::resize(), and luci_interpreter::Tensor::shape().

◆ execute()

void luci_interpreter::kernels::ExpandDims::execute ( ) const
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 76 of file ExpandDims.cpp.

77{
78 // Just copy input to output
79 const auto *input_data = input()->data<void>();
80 auto *output_data = output()->data<void>();
81
82 const size_t element_size = getDataTypeSize(input()->element_type());
83 const int32_t num_elements = input()->shape().num_elements();
84 std::memcpy(output_data, input_data, num_elements * element_size);
85}
int32_t num_elements() const
Definition Tensor.h:53
const T * data() const
Definition Tensor.h:127
list input_data
Definition infer.py:29
size_t getDataTypeSize(DataType data_type)
Definition DataType.h:33
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59

References luci_interpreter::Tensor::data(), luci_interpreter::getDataTypeSize(), input(), luci_interpreter::Shape::num_elements(), output(), and luci_interpreter::Tensor::shape().

◆ input()

const Tensor * luci_interpreter::kernels::ExpandDims::input ( ) const
inline

Definition at line 33 of file ExpandDims.h.

33{ return _inputs[0]; }

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), execute(), and ExpandDims().

◆ output()

Tensor * luci_interpreter::kernels::ExpandDims::output ( ) const
inline

Definition at line 35 of file ExpandDims.h.

35{ return _outputs[0]; }
const std::vector< Tensor * > _outputs
Definition Kernel.h:53

References luci_interpreter::Kernel::_outputs.

Referenced by configure(), and execute().


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