Add 'const' where possible to TFLite mul operator tests

This commit is contained in:
Thibaut Goetghebuer-Planchon 2020-09-14 17:30:28 +01:00
parent c1348607d1
commit fe6680abaf

View File

@ -113,7 +113,7 @@ TEST(FloatMulOpTest, ActivationRELU_N1_TO_1) {
}
TEST(FloatMulOpTest, VariousInputShapes) {
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{6}, {2, 3}, {2, 1, 3}, {1, 3, 1, 2}};
for (int i = 0; i < test_shapes.size(); ++i) {
FloatMulOpModel m({TensorType_FLOAT32, test_shapes[i]},
@ -130,7 +130,7 @@ TEST(FloatMulOpTest, VariousInputShapes) {
}
TEST(FloatMulOpTest, WithScalarBroadcast) {
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{6}, {2, 3}, {2, 1, 3}, {1, 3, 1, 2}};
for (int i = 0; i < test_shapes.size(); ++i) {
FloatMulOpModel m({TensorType_FLOAT32, test_shapes[i]},
@ -147,7 +147,7 @@ TEST(FloatMulOpTest, WithScalarBroadcast) {
}
TEST(FloatMulOpTest, WithBroadcast) {
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{2, 4}, {2, 1, 4}, {1, 2, 4}, {1, 2, 1, 4}};
for (int i = 0; i < test_shapes.size(); ++i) {
FloatMulOpModel m({TensorType_FLOAT32, test_shapes[i]},
@ -166,9 +166,9 @@ TEST(FloatMulOpTest, WithBroadcast) {
TEST(FloatMulOpTest, MixedBroadcast) {
const std::vector<int> base_shape = {2, 3, 1, 2};
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{1, 1, 3, 2}, {1, 3, 1, 2}, {2, 1, 3, 1}, {2, 3, 1, 1}};
std::vector<std::vector<float>> test_outputs = {
const std::vector<std::vector<float>> test_outputs = {
{-0.06f, 0.69f, 0.12f, 1.15f, -0.30f, 2.07f, 0.18f, 0.15f, -0.36f,
0.25f, 0.90f, 0.45f, 0.16f, -0.33f, -0.32f, -0.55f, 0.80f, -0.99f,
0.24f, 0.84f, -0.48f, 1.40f, 1.20f, 2.52f, -0.32f, 0.00f, 0.64f,
@ -214,7 +214,7 @@ TEST(FloatMulOpTest, MixedBroadcast) {
}
TEST(FloatMulOpTest, WithBroadcast2Elements) {
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{2, 2}, {2, 1, 2}, {1, 2, 2}, {1, 2, 1, 2}};
for (int i = 0; i < test_shapes.size(); ++i) {
FloatMulOpModel m({TensorType_FLOAT32, test_shapes[i]},
@ -250,7 +250,7 @@ TEST(IntegerMulOpTest, ActivationRELU_N1_TO_1) {
}
TEST(IntegerMulOpTest, VariousInputShapes) {
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{6}, {2, 3}, {2, 1, 3}, {1, 3, 1, 2}};
for (int i = 0; i < test_shapes.size(); ++i) {
IntegerMulOpModel m({TensorType_INT32, test_shapes[i]},
@ -265,7 +265,7 @@ TEST(IntegerMulOpTest, VariousInputShapes) {
}
TEST(IntegerMulOpTest, WithBroadcast) {
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{6}, {2, 3}, {2, 1, 3}, {1, 3, 1, 2}};
for (int i = 0; i < test_shapes.size(); ++i) {
IntegerMulOpModel m({TensorType_INT32, test_shapes[i]},
@ -392,12 +392,12 @@ float GetTolerance(int min, int max) {
template <TensorType tensor_type, typename integer_dtype>
void WithBroadcast() {
float kQuantizedTolerance = GetTolerance(-3.0, 3.0);
std::vector<std::vector<int>> test_shapes = {
const float kQuantizedTolerance = GetTolerance(-3.0, 3.0);
const std::vector<std::vector<int>> test_shapes = {
{6}, {2, 3}, {2, 1, 3}, {1, 3, 1, 2}};
// Test with a smaller than 1 and greater than 1 quantization multiplier
std::vector<std::pair<float, float>> test_input_range = {{-3.0, 3.0},
{-6.0, 6.0}};
const std::vector<std::pair<float, float>> test_input_range = {{-3.0, 3.0},
{-6.0, 6.0}};
for (int i = 0; i < test_shapes.size(); ++i) {
for (int j = 0; j < test_input_range.size(); ++j) {
const std::pair<float, float>& input_range = test_input_range[j];
@ -420,11 +420,11 @@ void WithBroadcast() {
template <enum TensorType tensor_type, typename integer_dtype>
void QuantizedWithMixedBroadcast() {
float kQuantizedTolerance = GetTolerance(-3.f, 3.f);
const float kQuantizedTolerance = GetTolerance(-3.f, 3.f);
const std::vector<int> base_shape = {2, 3, 1, 2};
std::vector<std::vector<int>> test_shapes = {
const std::vector<std::vector<int>> test_shapes = {
{1, 1, 3, 2}, {1, 3, 1, 2}, {2, 1, 3, 1}, {2, 3, 1, 1}};
std::vector<std::vector<float>> test_outputs = {
const std::vector<std::vector<float>> test_outputs = {
{-0.06f, 0.69f, 0.12f, 1.15f, -0.30f, 2.07f, 0.18f, 0.15f, -0.36f,
0.25f, 0.90f, 0.45f, 0.16f, -0.33f, -0.32f, -0.55f, 0.80f, -0.99f,
0.24f, 0.84f, -0.48f, 1.40f, 1.20f, 2.52f, -0.32f, 0.00f, 0.64f,