38 const int num_dims = input_shape.
num_dims();
41 throw std::runtime_error(
"Unsupported number of dimensions.");
43 assert(
output()->element_type() ==
input()->element_type());
44 assert(
paddings()->element_type() == DataType::S32);
46 assert(
paddings()->shape().num_dims() == 2);
47 assert(
paddings()->shape().dim(0) == num_dims);
48 assert(
paddings()->shape().dim(1) == 2);
51 const auto *paddings_data = getTensorData<int32_t>(
paddings());
52 for (
int i = 0; i < num_dims; ++i)
54 const int32_t padding_before = paddings_data[i * 2];
55 const int32_t padding_after = paddings_data[i * 2 + 1];
56 assert(padding_before >= 0 && padding_after >= 0);
57 output_shape.dim(i) = input_shape.
dim(i) + padding_before + padding_after;
67 tflite::PadParams params{};
68 params.left_padding_count = num_dims;
69 params.right_padding_count = num_dims;
71 const auto *paddings_data = getTensorData<int32_t>(
paddings());
72 for (
int i = num_dims - 1; i >= 0; --i)
74 params.left_padding[i] = paddings_data[i * 2];
75 params.right_padding[i] = paddings_data[i * 2 + 1];
78 switch (
input()->element_type())
80 case DataType::FLOAT32:
82 const float pad_value = 0.0f;
85 getTensorData<float>(
output()));
90 assert(
output()->zero_point() >= std::numeric_limits<uint8_t>::min());
91 assert(
output()->zero_point() <= std::numeric_limits<uint8_t>::max());
95 getTensorData<uint8_t>(
output()));
100 assert(
output()->zero_point() >= std::numeric_limits<int8_t>::min());
101 assert(
output()->zero_point() <= std::numeric_limits<int8_t>::max());
105 getTensorData<int8_t>(
output()));
109 throw std::runtime_error(
"luci-intp Pad Unsupported type.");