45 std::vector<PaddingInfo> paddings_extended = paddings;
49 paddings_extended.emplace_back(
PaddingInfo{ 0, 0 });
58 for(uint32_t idx = 0; idx < num_elements; ++idx)
62 const size_t i = coord.
x();
63 const size_t j = coord.
y();
64 const size_t k = coord.
z();
65 const size_t l = coord[3];
66 const size_t m = coord[4];
67 const size_t n = coord[5];
69 const std::array<size_t, TensorShape::num_max_dimensions> dims = { { 0, 1, 2, 3, 4, 5 } };
70 const std::array<size_t, TensorShape::num_max_dimensions> coords = { { i, j, k, l, m, n } };
71 auto is_padding_area = [&](
size_t i)
73 return (coords[i] < paddings_extended[i].first || coords[i] > orig_shape[i] + paddings_extended[i].first - 1);
76 auto orig_coord_reflect = [&](
size_t i)
78 if(is_padding_area(i))
80 if(coords[i] < paddings_extended[i].first)
82 return paddings_extended[i].first - coords[i];
86 return 2 * orig_shape[i] + paddings_extended[i].first - 2 - coords[i];
89 return coords[i] - paddings_extended[i].first;
92 auto orig_coord_symm = [&](
size_t i)
94 if(is_padding_area(i))
96 if(coords[i] < paddings_extended[i].first)
98 return paddings_extended[i].first - coords[i] - 1;
102 return 2 * orig_shape[i] + paddings_extended[i].first - 1 - coords[i];
105 return coords[i] - paddings_extended[i].first;
109 if(std::any_of(dims.begin(), dims.end(), is_padding_area))
114 const_value.
get(dst[idx]);
118 const Coordinates orig_coords{ orig_coord_reflect(0),
119 orig_coord_reflect(1),
120 orig_coord_reflect(2),
121 orig_coord_reflect(3),
122 orig_coord_reflect(4),
123 orig_coord_reflect(5) };
125 const size_t idx_src =
coord2index(orig_shape, orig_coords);
126 dst[idx] = src[idx_src];
136 orig_coord_symm(5) };
138 const size_t idx_src =
coord2index(orig_shape, orig_coords);
139 dst[idx] = src[idx_src];
153 i - paddings_extended[0].first,
154 j - paddings_extended[1].first,
155 k - paddings_extended[2].first,
156 l - paddings_extended[3].first,
157 m - paddings_extended[4].first,
158 n - paddings_extended[5].first
161 const size_t idx_src =
coord2index(orig_shape, orig_coords);
162 dst[idx] = src[idx_src];
SimpleTensor< T > pad_layer(const SimpleTensor< T > &src, const PaddingList &paddings, const PixelValue const_value, const PaddingMode mode)
Reference function to pad an ND tensor.
Class describing the value of a pixel for any image format.
std::vector< PaddingInfo > PaddingList
List of padding information.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void get(uint8_t &v) const
Interpret the pixel value as a U8.
DataType data_type() const override
Data type of the tensor.
TensorShape shape() const override
Shape of the tensor.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
T x() const
Alias to access the size of the first dimension.
PaddingMode
Padding mode to use for PadLayer.
T z() const
Alias to access the size of the third dimension.
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
TensorShape compute_padded_shape(const TensorShape &input_shape, const PaddingList &padding)
Calculate the padded shape of a tensor.
Simple tensor object that stores elements in a consecutive chunk of memory.
std::pair< uint32_t, uint32_t > PaddingInfo
Padding information as a pair of unsigned int start/end.
int num_elements() const override
Number of elements of the tensor.
T y() const
Alias to access the size of the second dimension.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
DataType
Available data types.