fixed static sized arrays with variable length

using const int or int for the size of an array implies that it has variable length (ill-formed, https://en.cppreference.com/w/cpp/language/ub), static arrays' lengths should be constexpr or a macro constant
This commit is contained in:
Lamar 2020-01-09 20:20:12 +01:00
parent be6e1ce49a
commit 71dd20a995
2 changed files with 6 additions and 6 deletions

View File

@ -82,7 +82,7 @@ TF_LITE_MICRO_TEST(FloatToAsymmetricQuantizedInt32Test) {
TF_LITE_MICRO_TEST(AsymmetricQuantizeInt8) {
float values[] = {-10.3, -3.1, -2.1, -1.9, -0.9, 0.1, 0.9, 1.85, 2.9, 4.1};
int8_t goldens[] = {-20, -5, -3, -3, -1, 1, 3, 5, 7, 9};
const int length = sizeof(values) / sizeof(float);
constexpr int length = sizeof(values) / sizeof(float);
int8_t quantized[length];
tflite::AsymmetricQuantize(values, quantized, length, 0.5, 1);
for (int i = 0; i < length; i++) {
@ -93,7 +93,7 @@ TF_LITE_MICRO_TEST(AsymmetricQuantizeInt8) {
TF_LITE_MICRO_TEST(AsymmetricQuantizeUInt8) {
float values[] = {-10.3, -3.1, -2.1, -1.9, -0.9, 0.1, 0.9, 1.85, 2.9, 4.1};
uint8_t goldens[] = {106, 121, 123, 123, 125, 127, 129, 131, 133, 135};
const int length = sizeof(values) / sizeof(float);
constexpr int length = sizeof(values) / sizeof(float);
uint8_t quantized[length];
tflite::AsymmetricQuantize(values, quantized, length, 0.5, 127);
for (int i = 0; i < length; i++) {
@ -104,7 +104,7 @@ TF_LITE_MICRO_TEST(AsymmetricQuantizeUInt8) {
TF_LITE_MICRO_TEST(SymmetricQuantizeInt32) {
float values[] = {-10.3, -3.1, -2.1, -1.9, -0.9, 0.1, 0.9, 1.85, 2.9, 4.1};
int32_t goldens[] = {-21, -6, -4, -4, -2, 0, 2, 4, 6, 8};
const int length = sizeof(values) / sizeof(float);
constexpr int length = sizeof(values) / sizeof(float);
int32_t quantized[length];
tflite::SymmetricQuantize(values, quantized, length, 0.5);
for (int i = 0; i < length; i++) {

View File

@ -21,7 +21,7 @@ TF_LITE_MICRO_TESTS_BEGIN
TF_LITE_MICRO_TEST(CreateQuantizedBiasTensor) {
float input_scale = 0.5;
float weight_scale = 0.5;
const int tensor_size = 12;
constexpr int tensor_size = 12;
int dims_arr[] = {4, 2, 3, 2, 1};
const char* tensor_name = "test_tensor";
int32_t quantized[tensor_size];
@ -45,7 +45,7 @@ TF_LITE_MICRO_TEST(CreateQuantizedBiasTensor) {
TF_LITE_MICRO_TEST(CreatePerChannelQuantizedBiasTensor) {
float input_scale = 0.5;
float weight_scales[] = {0.5, 1, 2, 4};
const int tensor_size = 12;
constexpr int tensor_size = 12;
const int channels = 4;
int dims_arr[] = {4, 4, 3, 1, 1};
const char* tensor_name = "test_tensor";
@ -78,7 +78,7 @@ TF_LITE_MICRO_TEST(CreatePerChannelQuantizedBiasTensor) {
TF_LITE_MICRO_TEST(CreateSymmetricPerChannelQuantizedTensor) {
const int tensor_size = 12;
const int channels = 2;
constexpr int channels = 2;
const int dims_arr[] = {4, channels, 3, 2, 1};
const char* tensor_name = "test_tensor";
int8_t quantized[12];