From ed87e1b7216d234cd270a9963417bd22297f9ebd Mon Sep 17 00:00:00 2001 From: Olivia Jain Date: Thu, 3 Mar 2022 10:44:46 -0800 Subject: [PATCH] Change axis to 0D in cumsum tests. (#10715) * changing axis to 0 * if def for openvino * removing extra header * include changes * pass in 0D scalar * Add comment explaining change. --- .../test/providers/cpu/math/cumsum_test.cc | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/onnxruntime/test/providers/cpu/math/cumsum_test.cc b/onnxruntime/test/providers/cpu/math/cumsum_test.cc index cf2da21538..2149e27472 100644 --- a/onnxruntime/test/providers/cpu/math/cumsum_test.cc +++ b/onnxruntime/test/providers/cpu/math/cumsum_test.cc @@ -12,7 +12,12 @@ namespace test { TEST(CumSumTest, _1DTest) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); + // Pass in 0D Axis for all OpenVINO tests, and keep one 1D Axis test for coverage. + #ifdef USE_OPENVINO + test.AddInput("axis", {}, {0}); + #else test.AddInput("axis", {1}, {0}); + #endif test.AddOutput("y", {5}, {1., 3., 6., 10., 15.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -20,7 +25,7 @@ TEST(CumSumTest, _1DTestFloat16) { if (DefaultCudaExecutionProvider().get() != nullptr) { OpTester test("CumSum", 14, onnxruntime::kOnnxDomain); test.AddInput("x", {3}, {MLFloat16(math::floatToHalf(1.0f)), MLFloat16(math::floatToHalf(2.0f)), MLFloat16(math::floatToHalf(3.0f))}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {3}, {MLFloat16(math::floatToHalf(1.0f)), MLFloat16(math::floatToHalf(3.0f)), MLFloat16(math::floatToHalf(6.0f))}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider, kCpuExecutionProvider}); } @@ -28,14 +33,14 @@ TEST(CumSumTest, _1DTestFloat16) { TEST(CumSumTest, _1DTestInvalidAxis) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {-3}); + test.AddInput("axis", {}, {-3}); test.AddOutput("y", {5}, {1., 3., 6., 10., 15.}); test.Run(OpTester::ExpectResult::kExpectFailure, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _1DTestNegAxis) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {-1}); + test.AddInput("axis", {}, {-1}); test.AddOutput("y", {5}, {1., 3., 6., 10., 15.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -43,21 +48,21 @@ TEST(CumSumTest, _1DTestExclusive) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("exclusive", 1); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {0., 1., 3., 6., 10.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _2DTestAxis0) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {2, 3}, {1., 2., 3., 4., 5., 6.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {2, 3}, {1., 2., 3., 5., 7., 9.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _2DTestAxis1) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {2, 3}, {1., 2., 3., 4., 5., 6.}); - test.AddInput("axis", {1}, {1}); + test.AddInput("axis", {}, {1}); test.AddOutput("y", {2, 3}, {1., 3., 6., 4., 9., 15.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -65,7 +70,7 @@ TEST(CumSumTest, _2DTestExclusiveAxis0) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3}, {1., 2., 3., 4., 5., 6.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {2, 3}, {0., 0., 0., 1., 2., 3}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -73,28 +78,28 @@ TEST(CumSumTest, _2DTestExclusiveAxis1) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3}, {1., 2., 3., 4., 5., 6.}); - test.AddInput("axis", {1}, {1}); + test.AddInput("axis", {}, {1}); test.AddOutput("y", {2, 3}, {0., 1., 3., 0., 4., 9.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _3DTestAxis0) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 14., 16., 18., 20., 22., 24., 26., 28., 30., 32., 34., 36.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _3DTestAxis1) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {1}); + test.AddInput("axis", {}, {1}); test.AddOutput("y", {2, 3, 4}, {1., 2., 3., 4., 6., 8., 10., 12., 15., 18., 21., 24., 13., 14., 15., 16., 30., 32., 34., 36., 51., 54., 57., 60.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _3DTestAxis2) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {2}); + test.AddInput("axis", {}, {2}); test.AddOutput("y", {2, 3, 4}, {1., 3., 6., 10., 5., 11., 18., 26., 9., 19., 30., 42., 13., 27., 42., 58., 17., 35., 54., 74., 21., 43., 66., 90.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -102,7 +107,7 @@ TEST(CumSumTest, _3DTestAxis0Exclusive) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {2, 3, 4}, {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -110,7 +115,7 @@ TEST(CumSumTest, _3DTestAxis1Exclusive) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {1}); + test.AddInput("axis", {}, {1}); test.AddOutput("y", {2, 3, 4}, {0., 0., 0., 0., 1., 2., 3., 4., 6., 8., 10., 12., 0., 0., 0., 0., 13., 14., 15., 16., 30., 32., 34., 36.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -118,7 +123,7 @@ TEST(CumSumTest, _3DTestAxis2Exclusive) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {2}); + test.AddInput("axis", {}, {2}); test.AddOutput("y", {2, 3, 4}, {0., 1., 3., 6., 0., 5., 11., 18., 0., 9., 19., 30., 0., 13., 27., 42., 0., 17., 35., 54., 0., 21., 43., 66.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -126,7 +131,7 @@ TEST(CumSumTest, _1DTestReverse) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("reverse", 1); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {15., 14., 12., 9., 5.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -135,7 +140,7 @@ TEST(CumSumTest, _1DTestReverseExclusive) { test.AddAttribute("exclusive", 1); test.AddAttribute("reverse", 1); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {14., 12., 9., 5., 0.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -143,7 +148,7 @@ TEST(CumSumTest, _3DTestAxis0Reverse) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("reverse", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {2, 3, 4}, {14., 16., 18., 20., 22., 24., 26., 28., 30., 32., 34., 36., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -151,7 +156,7 @@ TEST(CumSumTest, _3DTestAxis1Reverse) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("reverse", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {1}); + test.AddInput("axis", {}, {1}); test.AddOutput("y", {2, 3, 4}, {15., 18., 21., 24., 14., 16., 18., 20., 9., 10., 11., 12., 51., 54., 57., 60., 38., 40., 42., 44., 21., 22., 23., 24.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -159,7 +164,7 @@ TEST(CumSumTest, _3DTestAxis2Reverse) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddAttribute("reverse", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {2}); + test.AddInput("axis", {}, {2}); test.AddOutput("y", {2, 3, 4}, {10., 9., 7., 4., 26., 21., 15., 8., 42., 33., 23., 12., 58., 45., 31., 16., 74., 57., 39., 20., 90., 69., 47., 24.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -168,7 +173,7 @@ TEST(CumSumTest, _3DTestAxis0ReverseExclusive) { test.AddAttribute("reverse", 1); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {2, 3, 4}, {13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -177,7 +182,7 @@ TEST(CumSumTest, _3DTestAxis1ReverseExclusive) { test.AddAttribute("reverse", 1); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {1}); + test.AddInput("axis", {}, {1}); test.AddOutput("y", {2, 3, 4}, {14., 16., 18., 20., 9., 10., 11., 12., 0., 0., 0., 0., 38., 40., 42., 44., 21., 22., 23., 24., 0., 0., 0., 0.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } @@ -186,35 +191,35 @@ TEST(CumSumTest, _3DTestAxis2ReverseExclusive) { test.AddAttribute("reverse", 1); test.AddAttribute("exclusive", 1); test.AddInput("x", {2, 3, 4}, {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.}); - test.AddInput("axis", {1}, {2}); + test.AddInput("axis", {}, {2}); test.AddOutput("y", {2, 3, 4}, {9., 7., 4., 0., 21., 15., 8., 0., 33., 23., 12., 0., 45., 31., 16., 0., 57., 39., 20., 0., 69., 47., 24., 0.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _1DTestInt32) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1, 2, 3, 4, 5}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {1, 3, 6, 10, 15}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _1DTestInt64) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1, 2, 3, 4, 5}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {1, 3, 6, 10, 15}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _1DTestdouble) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {1., 3., 6., 10., 15.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } TEST(CumSumTest, _1DTestdouble_WithInt64Axis) { OpTester test("CumSum", 11, onnxruntime::kOnnxDomain); test.AddInput("x", {5}, {1., 2., 3., 4., 5.}); - test.AddInput("axis", {1}, {0}); + test.AddInput("axis", {}, {0}); test.AddOutput("y", {5}, {1., 3., 6., 10., 15.}); test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); }