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:
parent
be6e1ce49a
commit
71dd20a995
tensorflow/lite/micro
@ -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++) {
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user