Skip to content

Commit

Permalink
Test broadcasting scalar NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve committed Jul 28, 2024
1 parent f4a6d48 commit 51ed042
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,28 @@ TEST(MathOpTest, Min_12_Float_Nan_with_scalar) {
}
}

TEST(MathOpTest, Min_12_Float_with_scalar_Nan) {
OpTester test("Min", 12);
test.AddInput<float>("data_1", {2, 2},
{0.25f, -0.25f, -0.5f, 0.5f});
test.AddInput<float>("data_2", {1}, {std::numeric_limits<float>::quiet_NaN()});
test.AddOutput<float>("min", {2, 2},
{std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN()});
if (nullptr != DefaultCpuExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
if (nullptr != DefaultCudaExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCudaExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
}

TEST(MathOpTest, Min_12_Double) {
OpTester test("Min", 12);
test.AddInput<double>("data_0", {1, 3},
Expand Down Expand Up @@ -1636,6 +1658,28 @@ TEST(MathOpTest, Min_12_Double_Nan_with_scalar) {
}
}

TEST(MathOpTest, Min_12_Double_with_scalar_Nan) {
OpTester test("Min", 12);
test.AddInput<double>("data_1", {2, 2},
{0.25, -0.25, -0.5, 0.5});
test.AddInput<double>("data_2", {1}, {std::numeric_limits<double>::quiet_NaN()});
test.AddOutput<double>("min", {2, 2},
{std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN()});
if (nullptr != DefaultCpuExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
if (nullptr != DefaultCudaExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCudaExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
}

TEST(MathOpTest, Min_12_Int32) {
OpTester test("Min", 12);
test.AddInput<int32_t>("data_0", {1, 3},
Expand Down Expand Up @@ -1780,6 +1824,23 @@ TEST(MathOpTest, Min_12_MLFloat16_Nan_with_scalar) {
}
}

TEST(MathOpTest, Min_12_MLFloat16_with_scalar_Nan) {
OpTester test("Min", 12);
test.AddInput<MLFloat16>("data_1", {2, 2},
MakeMLFloat16({0.25f, -0.25f, -0.5f, 0.5f}));
test.AddInput<MLFloat16>("data_2", {1}, MakeMLFloat16({std::numeric_limits<float>::quiet_NaN()}));
test.AddOutput<MLFloat16>("min", {2, 2},
MakeMLFloat16({std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN()}));
if (nullptr != DefaultCpuExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
}

TEST(MathOpTest, Max_6) {
OpTester test("Max", 6);
std::vector<int64_t> dims{3, 3};
Expand Down Expand Up @@ -1915,6 +1976,28 @@ TEST(MathOpTest, Max_12_Float_Nan_with_scalar) {
}
}

TEST(MathOpTest, Max_12_Float_with_scalar_Nan) {
OpTester test("Max", 12);
test.AddInput<float>("data_1", {2, 2},
{0.25f, -0.25f, -0.5f, 0.5f});
test.AddInput<float>("data_2", {1}, {std::numeric_limits<float>::quiet_NaN()});
test.AddOutput<float>("max", {2, 2},
{std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN()});
if (nullptr != DefaultCpuExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
if (nullptr != DefaultCudaExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCudaExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
}

TEST(MathOpTest, Max_12_Double) {
OpTester test("Max", 12);
test.AddInput<double>("data_0", {1, 3},
Expand Down Expand Up @@ -1979,6 +2062,28 @@ TEST(MathOpTest, Max_12_Double_Nan_with_scalar) {
}
}

TEST(MathOpTest, Max_12_Double_with_scalar_Nan) {
OpTester test("Max", 12);
test.AddInput<double>("data_1", {2, 2},
{0.25, -0.25, -0.5, 0.5});
test.AddInput<double>("data_2", {1}, {std::numeric_limits<double>::quiet_NaN()});
test.AddOutput<double>("max", {2, 2},
{std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN()});
if (nullptr != DefaultCpuExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
if (nullptr != DefaultCudaExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCudaExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
}

TEST(MathOpTest, Max_12_Int32) {
OpTester test("Max", 12);
test.AddInput<int32_t>("data_0", {1, 3},
Expand Down Expand Up @@ -2123,6 +2228,23 @@ TEST(MathOpTest, Max_12_MLFloat16_Nan_with_scalar) {
}
}

TEST(MathOpTest, Max_12_MLFloat16_with_scalar_Nan) {
OpTester test("Max", 12);
test.AddInput<MLFloat16>("data_1", {2, 2},
MakeMLFloat16({0.25f, -0.25f, -0.5f, 0.5f}));
test.AddInput<MLFloat16>("data_2", {1}, MakeMLFloat16({std::numeric_limits<float>::quiet_NaN()}));
test.AddOutput<MLFloat16>("max", {2, 2},
MakeMLFloat16({std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN()}));
if (nullptr != DefaultCpuExecutionProvider()) {
std::vector<std::unique_ptr<IExecutionProvider>> execution_providers;
execution_providers.push_back(DefaultCpuExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &execution_providers);
}
}

TEST(MathOpTest, Not) {
OpTester test("Not");
std::vector<int64_t> dims{2};
Expand Down

0 comments on commit 51ed042

Please sign in to comment.