// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" #include namespace onnxruntime { namespace test { template void RunQLinearWhere( OpTester& test, const std::vector& x, const std::vector& y, const std::vector& z, float x_scale, T x_zero_point, float y_scale, T y_zero_point, float z_scale, T z_zero_point, const std::vector& x_shape, const std::vector& y_shape, const std::vector& z_shape) { test.AddInput("X", x_shape, x); test.AddInput("x_scale", {}, {x_scale}, true); test.AddInput("x_zero_point", {}, {x_zero_point}, true); test.AddInput("Y", y_shape, y); test.AddInput("y_scale", {}, {y_scale}, true); test.AddInput("y_zero_point", {}, {y_zero_point}, true); test.AddInput("z_scale", {}, {z_scale}); test.AddInput("z_zero_point", {}, {z_zero_point}); test.AddOutput("Z", z_shape, z); test.Run(OpTester::ExpectResult::kExpectSuccess); } template void QLinearWhereScalarAll() { constexpr float scale = 0.039f; constexpr uint8_t zp = 135; OpTester test("QLinearWhere", 1, onnxruntime::kMSDomain); test.AddInput("condition", {1}, {true}, true); RunQLinearWhere( test, {1}, {2}, {1}, // x ,y ,z scale, zp, scale, zp, scale, zp, // x_scale, x_zp, y_scale, y_zp, z_scale, z_zp {1}, {1}, {1}); } TEST(QLinearWhereTest, QLinearWhereScalarAll) { QLinearWhereScalarAll(); QLinearWhereScalarAll(); } template void QLinearWhereVectorAll() { constexpr float scale = 0.039f; constexpr uint8_t zp = 135; OpTester test("QLinearWhere", 1, onnxruntime::kMSDomain); test.AddInput("condition", {4}, {true, false, false, true}, true); RunQLinearWhere( test, {1, 1, 1, 1}, {2, 2, 2, 2}, {1, 2, 2, 1}, // x ,y ,z scale, zp, scale, zp, scale, zp, // x_scale, x_zp, y_scale, y_zp, z_scale, z_zp {4}, {4}, {4}); } TEST(QLinearWhereTest, QLinearWhereVectorAll) { QLinearWhereVectorAll(); QLinearWhereVectorAll(); } template void QLinearWhereMatrixAll() { constexpr float scale = 0.039f; constexpr uint8_t zp = 135; OpTester test("QLinearWhere", 1, onnxruntime::kMSDomain); test.AddInput("condition", {2, 2}, {true, false, false, true}, true); RunQLinearWhere( test, {1, 1, 1, 1}, {2, 2, 2, 2}, {1, 2, 2, 1}, // x ,y ,z scale, zp, scale, zp, scale, zp, // x_scale, x_zp, y_scale, y_zp, z_scale, z_zp {2, 2}, {2, 2}, {2, 2}); } TEST(QLinearWhereTest, QLinearWhereMatrixAll) { QLinearWhereMatrixAll(); QLinearWhereMatrixAll(); } template void QLinearWhereScalarX_VectorY_MatrixCondition() { constexpr float scale = 0.039f; constexpr uint8_t zp = 135; OpTester test("QLinearWhere", 1, onnxruntime::kMSDomain); test.AddInput("condition", {2, 2}, {true, false, false, true}, true); RunQLinearWhere( test, {1}, {2, 2}, {1, 2, 2, 1}, // x ,y ,z scale, zp, scale, zp, scale, zp, // x_scale, x_zp, y_scale, y_zp, z_scale, z_zp {1}, {2}, {2, 2}); } TEST(QLinearWhereTest, QLinearWhereScalarX_VectorY_MatrixCondition) { QLinearWhereScalarX_VectorY_MatrixCondition(); QLinearWhereScalarX_VectorY_MatrixCondition(); } template void QLinearWhereVectorX_VectorY_MatrixCondition() { constexpr float scale = 0.039f; constexpr uint8_t zp = 135; OpTester test("QLinearWhere", 1, onnxruntime::kMSDomain); test.AddInput("condition", {2, 2}, {true, false, false, true}, true); RunQLinearWhere( test, {1, 1}, {2, 2}, {1, 2, 2, 1}, // x ,y ,z scale, zp, scale, zp, scale, zp, // x_scale, x_zp, y_scale, y_zp, z_scale, z_zp {2}, {2}, {2, 2}); } TEST(QLinearWhereTest, QLinearWhereVectorX_VectorY_MatrixCondition) { QLinearWhereVectorX_VectorY_MatrixCondition(); QLinearWhereVectorX_VectorY_MatrixCondition(); } } // namespace test } // namespace onnxruntime