ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SpatialPaddingBuilder Class Reference

Convert a raw padding to a spatial padding of a given spatial rank. More...

#include <PaddingUtils.h>

Public Member Functions

SpatialPadding with (const RawPadding &raw) const
 

Friends

SpatialPaddingBuilder build_spatial_padding (uint32_t spatial_rank)
 

Detailed Description

Convert a raw padding to a spatial padding of a given spatial rank.

Note
This class is an auxiliary class for build_raw_padding function below

Definition at line 55 of file PaddingUtils.h.

Member Function Documentation

◆ with()

SpatialPadding SpatialPaddingBuilder::with ( const RawPadding raw) const

Definition at line 91 of file PaddingUtils.cpp.

92{
93 const auto spatial_rank = _spatial_rank;
94
96
97 res.resize(spatial_rank);
98
99 if (raw.count() == 0)
100 {
101 // NOTE default padding is 0
102 for (uint32_t spatial_axis = 0; spatial_axis < spatial_rank; ++spatial_axis)
103 {
104 res.value(spatial_axis) = 0;
105 }
106 }
107 else if (raw.count() == 1)
108 {
109 // NOTE One-for-all scheme
110 for (uint32_t spatial_axis = 0; spatial_axis < spatial_rank; ++spatial_axis)
111 {
112 res.value(spatial_axis) = raw.value(0);
113 }
114 }
115 else
116 {
117 // NOTE One-to-one scheme
118 assert(raw.count() == spatial_rank);
119 for (uint32_t spatial_axis = 0; spatial_axis < spatial_rank; ++spatial_axis)
120 {
121 res.value(spatial_axis) = raw.value(spatial_axis);
122 }
123 }
124
125 return res;
126}
uint32_t & value(uint32_t n)
Definition Padding.h:39
void resize(uint32_t len)
Definition Padding.h:43
uint32_t count(void) const
Definition Padding.h:36
A SpatialPadding denotes padding values for each "spatial" dimension.
Definition Padding.h:65

References PaddingBase< Derived >::count(), PaddingBase< Derived >::resize(), and PaddingBase< Derived >::value().

Referenced by PoolingSpec::horizontal_pad(), ConvolutionSpec::pad(), and PoolingSpec::vertical_pad().

Friends And Related Symbol Documentation

◆ build_spatial_padding

SpatialPaddingBuilder build_spatial_padding ( uint32_t  spatial_rank)
friend

SpatialPaddingBuilder is introduced to support the following code pattern:

auto raw_padding = build_raw_padding().with(conv_param); auto spatial_padding = build_spatial_padding(4).with(raw_padding);

Definition at line 128 of file PaddingUtils.cpp.

129{
130 return SpatialPaddingBuilder{spatial_rank};
131}
Convert a raw padding to a spatial padding of a given spatial rank.

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