ONE - On-device Neural Engine
Loading...
Searching...
No Matches
mir_interpreter::PadImpl< T > Struct Template Reference

Static Public Member Functions

static void run (const mir::TensorVariant &inputv, const mir::ops::PadOp &op, mir::TensorVariant &result)
 

Detailed Description

template<typename T>
struct mir_interpreter::PadImpl< T >

Definition at line 28 of file Pad.cpp.

Member Function Documentation

◆ run()

template<typename T >
void mir_interpreter::PadImpl< T >::run ( const mir::TensorVariant inputv,
const mir::ops::PadOp op,
mir::TensorVariant result 
)
static

Definition at line 35 of file Pad.cpp.

36{
37 Tensor<T> result_accessor(result);
38 Tensor<T> input(inputv);
39
40 Shape out_shape = result_accessor.getShape();
41
42 ShapeRange out_range(out_shape);
43 const int rank = op.getInputShape(0).rank();
44 const auto &padding_before = op.getPaddingBefore();
45 const auto &padding_after = op.getPaddingAfter();
46
47 Index temp_index;
48 temp_index.resize(rank);
49
50 bool index_on_padding(false);
51 for (const Index &ind : out_range)
52 {
53 index_on_padding = false;
54
55 for (int32_t i = 0; i < rank; i++)
56 {
57 // index on input values
58 if (ind.at(i) >= padding_before[i] && ind.at(i) < out_shape.dim(i) - padding_after[i])
59 {
60 temp_index.at(i) = ind.at(i) - padding_before[i];
61 }
62 else
63 { // not in input
64 index_on_padding = true;
65 break;
66 }
67 }
68 if (index_on_padding)
69 {
70 result_accessor.at(ind) = op.getPaddingValue();
71 }
72 else
73 {
74 result_accessor.at(ind) = input.at(temp_index);
75 }
76 }
77}
const Shape & getInputShape(std::size_t index) const
Definition Operation.h:161
int32_t rank() const
Definition Shape.h:43
float getPaddingValue() const
Definition PadOp.h:47
const std::vector< std::int32_t > & getPaddingBefore() const
Definition PadOp.h:43
const std::vector< std::int32_t > & getPaddingAfter() const
Definition PadOp.h:45
Definition Shape.h:28

References mir::Tensor< T >::at(), mir::Index::at(), mir::Shape::dim(), mir::Operation::getInputShape(), mir::ops::PadOp::getPaddingAfter(), mir::ops::PadOp::getPaddingBefore(), mir::ops::PadOp::getPaddingValue(), mir::Tensor< T >::getShape(), mir::Shape::rank(), and mir::Index::resize().

Referenced by package.infer.session::inference().


The documentation for this struct was generated from the following file: