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

#include <Squeeze.h>

Collaboration diagram for luci_interpreter::kernels::Squeeze:

Public Member Functions

 Squeeze (const Tensor *input, Tensor *output, const SqueezeParams &params)
 
const Tensorinput () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
 Squeeze (const Tensor *input, Tensor *output, const SqueezeParams &params)
 
const Tensorinput () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
- Public Member Functions inherited from luci_interpreter::KernelWithParams< SqueezeParams >
const SqueezeParamsparams () const
 
- 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::KernelWithParams< SqueezeParams >
 KernelWithParams (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs, const SqueezeParams &params)
 
- Protected Member Functions inherited from luci_interpreter::Kernel
 Kernel (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
 
- Protected Attributes inherited from luci_interpreter::KernelWithParams< SqueezeParams >
const SqueezeParams _params
 
- Protected Attributes inherited from luci_interpreter::Kernel
const std::vector< const Tensor * > _inputs
 
const std::vector< Tensor * > _outputs
 

Detailed Description

Definition at line 29 of file Squeeze.h.

Constructor & Destructor Documentation

◆ Squeeze() [1/2]

luci_interpreter::kernels::Squeeze::Squeeze ( const Tensor input,
Tensor output,
const SqueezeParams params 
)

Definition at line 29 of file Squeeze.cpp.

30 : KernelWithParams<SqueezeParams>({input}, {output}, params)
31{
32}
const SqueezeParams & params() const
Definition Kernel.h:67
const Tensor * input() const
Definition Squeeze.h:34

References input().

◆ Squeeze() [2/2]

luci_interpreter::kernels::Squeeze::Squeeze ( const Tensor input,
Tensor output,
const SqueezeParams params 
)

Member Function Documentation

◆ configure() [1/2]

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

Implements luci_interpreter::Kernel.

Definition at line 34 of file Squeeze.cpp.

35{
36 int input_num_dims = input()->shape().num_dims();
37 int num_squeeze_dims = params().squeeze_dims.size();
38 assert(input_num_dims <= 8);
39 bool should_squeeze[8] = {false};
40 int num_squeezed_dims = 0;
41 if (num_squeeze_dims == 0)
42 {
43 for (int idx = 0; idx < input_num_dims; ++idx)
44 {
45 if (input()->shape().dim(idx) == 1)
46 {
47 should_squeeze[idx] = true;
48 ++num_squeezed_dims;
49 }
50 }
51 }
52 else
53 {
54 for (int idx = 0; idx < num_squeeze_dims; ++idx)
55 {
56 int current = params().squeeze_dims[idx] < 0 ? params().squeeze_dims[idx] + input_num_dims
57 : params().squeeze_dims[idx];
58 assert(current >= 0 && current < input_num_dims && input()->shape().dim(current) == 1);
59 if (!should_squeeze[current])
60 ++num_squeezed_dims;
61 should_squeeze[current] = true;
62 }
63 }
64 Shape output_shape(input_num_dims - num_squeezed_dims);
65 for (int in_idx = 0, out_idx = 0; in_idx < input_num_dims; ++in_idx)
66 {
67 if (!should_squeeze[in_idx])
68 {
69 output_shape.dim(out_idx++) = input()->shape().dim(in_idx);
70 }
71 }
73}
int32_t dim(int i) const
Definition Tensor.h:41
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
const luci_interpreter::RuntimeShape output_shape
Definition Shape.h:28
std::vector< int32_t > squeeze_dims

References luci_interpreter::Shape::dim(), input(), luci_interpreter::Shape::num_dims(), output(), output_shape, luci_interpreter::KernelWithParams< SqueezeParams >::params(), luci_interpreter::Tensor::resize(), luci_interpreter::Tensor::shape(), and luci_interpreter::SqueezeParams::squeeze_dims.

◆ configure() [2/2]

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

◆ execute() [1/2]

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

Implements luci_interpreter::Kernel.

Definition at line 75 of file Squeeze.cpp.

76{
77 assert(input()->shape().num_elements() == output()->shape().num_elements());
78
79 const auto *input_data = input()->data<void>();
80 auto *output_data = output()->data<void>();
81 std::memcpy(output_data, input_data,
82 getDataTypeSize(input()->element_type()) * input()->shape().num_elements());
83}
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(), and output().

◆ execute() [2/2]

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

◆ input() [1/2]

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

Definition at line 34 of file Squeeze.h.

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

References luci_interpreter::Kernel::_inputs.

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

◆ input() [2/2]

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

Definition at line 34 of file Squeeze.h.

34{ return _inputs[0]; }

References luci_interpreter::Kernel::_inputs.

◆ output() [1/2]

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

Definition at line 35 of file Squeeze.h.

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

References luci_interpreter::Kernel::_outputs.

Referenced by configure(), and execute().

◆ output() [2/2]

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

Definition at line 35 of file Squeeze.h.

35{ return _outputs[0]; }

References luci_interpreter::Kernel::_outputs.


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