diff --git a/onnxruntime/core/providers/cpu/nn/pool_base.h b/onnxruntime/core/providers/cpu/nn/pool_base.h index 3d1edfbdaf..f4d0082866 100644 --- a/onnxruntime/core/providers/cpu/nn/pool_base.h +++ b/onnxruntime/core/providers/cpu/nn/pool_base.h @@ -88,7 +88,7 @@ class LpPool { template static void Process(const T& x_data, T& y_data, const PoolProcessContext& cxt) { - y_data += static_cast(std::pow(std::abs(x_data), cxt.p_)); + y_data += static_cast(std::pow(x_data, cxt.p_)); } template diff --git a/onnxruntime/test/providers/cpu/nn/pool_op_test.cc b/onnxruntime/test/providers/cpu/nn/pool_op_test.cc index b9db7ad47f..f84da5cf9a 100644 --- a/onnxruntime/test/providers/cpu/nn/pool_op_test.cc +++ b/onnxruntime/test/providers/cpu/nn/pool_op_test.cc @@ -1264,6 +1264,25 @@ TEST(PoolTest, LpPool) { test.Run(); } +TEST(PoolTest, LpPoolWithNegativeNumbers) { + OpTester test("LpPool"); + + test.AddAttribute("p", static_cast(1)); + test.AddAttribute("auto_pad", ""); + test.AddAttribute("strides", std::vector{2}); + test.AddAttribute("pads", vector{0, 0}); + test.AddAttribute("kernel_shape", vector{2}); + + std::vector x_vals = {0.2f, -0.6f}; + std::vector x_dims = {1, 1, 2}; + std::vector expected_dims = {1, 1, 1}; + std::vector expected_vals = {-0.4f}; + + test.AddInput("X", x_dims, x_vals); + test.AddOutput("Y", expected_dims, expected_vals); + test.Run(); +} + TEST(PoolTest, GlobalLpPool) { OpTester test("GlobalLpPool"); test.AddAttribute("p", static_cast(3));