// // Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "ComparisonTestHelper.hpp" #include #include #include #include #include #include #include namespace armnnDelegate { void EqualFP32Test(std::vector& backends) { std::vector input0Shape { 2, 2, 2, 2 }; std::vector input1Shape { 2, 2, 2, 2 }; std::vector expectedOutputShape { 2, 2, 2, 2 }; std::vector input0Values = { 1.f, 1.f, 1.f, 1.f, 5.f, 5.f, 5.f, 5.f, 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f }; std::vector input1Values = { 1.f, 1.f, 1.f, 1.f, 3.f, 3.f, 3.f, 3.f, 5.f, 5.f, 5.f, 5.f, 4.f, 4.f, 4.f, 4.f }; std::vector expectedOutputValues = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 }; ComparisonTest(tflite::BuiltinOperator_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void EqualBroadcastTest(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 3 }; std::vector input1Shape { 1, 1, 1, 3 }; std::vector expectedOutputShape { 1, 2, 2, 3 }; std::vector input0Values { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }; std::vector input1Values { 4.f, 5.f, 6.f }; // Set output data std::vector expectedOutputValues { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; ComparisonTest(tflite::BuiltinOperator_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void EqualInt32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 4 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { 1, 0, 0, 1 }; ComparisonTest(tflite::BuiltinOperator_EQUAL, ::tflite::TensorType_INT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void NotEqualFP32Test(std::vector& backends) { std::vector input0Shape { 2, 2, 2, 2 }; std::vector input1Shape { 2, 2, 2, 2 }; std::vector expectedOutputShape { 2, 2, 2, 2 }; std::vector input0Values = { 1.f, 1.f, 1.f, 1.f, 5.f, 5.f, 5.f, 5.f, 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f }; std::vector input1Values = { 1.f, 1.f, 1.f, 1.f, 3.f, 3.f, 3.f, 3.f, 5.f, 5.f, 5.f, 5.f, 4.f, 4.f, 4.f, 4.f }; std::vector expectedOutputValues = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 }; ComparisonTest(tflite::BuiltinOperator_NOT_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void NotEqualBroadcastTest(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 3 }; std::vector input1Shape { 1, 1, 1, 3 }; std::vector expectedOutputShape { 1, 2, 2, 3 }; std::vector input0Values { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }; std::vector input1Values { 4.f, 5.f, 6.f }; // Set output data std::vector expectedOutputValues { 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1 }; ComparisonTest(tflite::BuiltinOperator_NOT_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void NotEqualInt32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 4 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { 0, 1, 1, 0 }; ComparisonTest(tflite::BuiltinOperator_NOT_EQUAL, ::tflite::TensorType_INT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void GreaterFP32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 4 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { 0, 1, 0, 0 }; ComparisonTest(tflite::BuiltinOperator_GREATER, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void GreaterBroadcastTest(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 3 }; std::vector input1Shape { 1, 1, 1, 3 }; std::vector expectedOutputShape { 1, 2, 2, 3 }; std::vector input0Values { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }; std::vector input1Values { 4.f, 5.f, 6.f }; std::vector expectedOutputValues { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }; ComparisonTest(tflite::BuiltinOperator_GREATER, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void GreaterInt32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 4 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { 0, 1, 0, 0 }; ComparisonTest(tflite::BuiltinOperator_GREATER, ::tflite::TensorType_INT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void GreaterEqualFP32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1.f, 5.f, 6.f, 4.f }; std::vector input1Values = { 1.f, 3.f, 9.f, 4.f }; std::vector expectedOutputValues = { true, true, false, true }; ComparisonTest(tflite::BuiltinOperator_GREATER_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void GreaterEqualBroadcastTest(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 3 }; std::vector input1Shape { 1, 1, 1, 3 }; std::vector expectedOutputShape { 1, 2, 2, 3 }; std::vector input0Values { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }; std::vector input1Values { 4.f, 5.f, 6.f }; // Set output data std::vector expectedOutputValues { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; ComparisonTest(tflite::BuiltinOperator_GREATER_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void GreaterEqualInt32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 3 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { 1, 1, 0, 0 }; ComparisonTest(tflite::BuiltinOperator_GREATER_EQUAL, ::tflite::TensorType_INT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void LessFP32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1.f, 5.f, 6.f, 4.f }; std::vector input1Values = { 1.f, 3.f, 9.f, 4.f }; std::vector expectedOutputValues = { false, false, true, false }; ComparisonTest(tflite::BuiltinOperator_LESS, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void LessBroadcastTest(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 3 }; std::vector input1Shape { 1, 1, 1, 3 }; std::vector expectedOutputShape { 1, 2, 2, 3 }; std::vector input0Values { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }; std::vector input1Values { 4.f, 5.f, 6.f }; std::vector expectedOutputValues { true, true, true, false, false, false, false, false, false, false, false, false }; ComparisonTest(tflite::BuiltinOperator_LESS, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void LessInt32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 3 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { false, false, true, true }; ComparisonTest(tflite::BuiltinOperator_LESS, ::tflite::TensorType_INT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void LessEqualFP32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1.f, 5.f, 6.f, 4.f }; std::vector input1Values = { 1.f, 3.f, 9.f, 4.f }; std::vector expectedOutputValues = { true, false, true, true }; ComparisonTest(tflite::BuiltinOperator_LESS_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void LessEqualBroadcastTest(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 3 }; std::vector input1Shape { 1, 1, 1, 3 }; std::vector expectedOutputShape { 1, 2, 2, 3 }; std::vector input0Values { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }; std::vector input1Values { 4.f, 5.f, 6.f }; std::vector expectedOutputValues { true, true, true, true, true, true, false, false, false, false, false, false }; ComparisonTest(tflite::BuiltinOperator_LESS_EQUAL, ::tflite::TensorType_FLOAT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } void LessEqualInt32Test(std::vector& backends) { std::vector input0Shape { 1, 2, 2, 1 }; std::vector input1Shape { 1, 2, 2, 1 }; std::vector expectedOutputShape { 1, 2, 2, 1 }; std::vector input0Values = { 1, 5, 6, 3 }; std::vector input1Values = { 1, 3, 9, 4 }; std::vector expectedOutputValues = { true, false, true, true }; ComparisonTest(tflite::BuiltinOperator_LESS_EQUAL, ::tflite::TensorType_INT32, input0Shape, input1Shape, expectedOutputShape, input0Values, input1Values, expectedOutputValues, 1.0f, 0, backends); } TEST_SUITE("Comparison_Tests") { TEST_CASE ("EQUAL_FP32_Test") { std::vector backends = { }; EqualFP32Test(backends); } TEST_CASE ("EQUAL_Broadcast_Test") { std::vector backends = { }; EqualBroadcastTest(backends); } TEST_CASE ("EQUAL_INT32_Test") { std::vector backends = { }; EqualInt32Test(backends); } TEST_CASE ("NOT_EQUAL_FP32_Test") { std::vector backends = { }; NotEqualFP32Test(backends); } TEST_CASE ("NOT_EQUAL_Broadcast_Test") { std::vector backends = { }; NotEqualBroadcastTest(backends); } TEST_CASE ("NOT_EQUAL_INT32_Test") { std::vector backends = { }; NotEqualInt32Test(backends); } TEST_CASE ("GREATER_FP32_Test") { std::vector backends = { }; GreaterFP32Test(backends); } TEST_CASE ("GREATER_Broadcast_Test") { std::vector backends = { }; GreaterBroadcastTest(backends); } TEST_CASE ("GREATER_INT32_Test") { std::vector backends = { }; GreaterInt32Test(backends); } TEST_CASE ("GREATER_EQUAL_FP32_Test") { std::vector backends = { }; GreaterEqualFP32Test(backends); } TEST_CASE ("GREATER_EQUAL_Broadcast_Test") { std::vector backends = { }; GreaterEqualBroadcastTest(backends); } TEST_CASE ("GREATER_EQUAL_INT32_Test") { std::vector backends = { }; GreaterEqualInt32Test(backends); } TEST_CASE ("LESS_FP32_Test") { std::vector backends = { }; LessFP32Test(backends); } TEST_CASE ("LESS_Broadcast_Test") { std::vector backends = { }; LessBroadcastTest(backends); } TEST_CASE ("LESS_INT32_Test") { std::vector backends = { }; LessInt32Test(backends); } TEST_CASE ("LESS_EQUAL_FP32_Test") { std::vector backends = { }; LessEqualFP32Test(backends); } TEST_CASE ("LESS_EQUAL_Broadcast_Test") { std::vector backends = { }; LessEqualBroadcastTest(backends); } TEST_CASE ("LESS_EQUAL_INT32_Test") { std::vector backends = { }; LessEqualInt32Test(backends); } } // End TEST_SUITE("Comparison_Tests") } // namespace armnnDelegate