From 410a535646b4bdcf1716e221f5745a55612b0dcb Mon Sep 17 00:00:00 2001 From: qingqing01 Date: Fri, 17 Jan 2020 23:14:30 +0800 Subject: [PATCH] Fix infer_shape in compling for elementwise_op (#22291) (#22353) --- .../fluid/operators/elementwise/elementwise_op_function.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/operators/elementwise/elementwise_op_function.h b/paddle/fluid/operators/elementwise/elementwise_op_function.h index 644bda34a0..3710e008ca 100644 --- a/paddle/fluid/operators/elementwise/elementwise_op_function.h +++ b/paddle/fluid/operators/elementwise/elementwise_op_function.h @@ -143,10 +143,11 @@ inline void GetBroadcastDimsArrays(const framework::DDim &x_dims, "the shape of Y = [%s]. Received [%d] in X is not equal to " "[%d] in Y", x_dims, y_dims, x_dims_array[i], y_dims_array[i]); - if (x_dims_array[i] == -1 || y_dims_array[i] == -1) { - out_dims_array[i] = -1; - } else { + if ((x_dims_array[i] > 1 || y_dims_array[i] > 1) || + (x_dims_array[i] == 1 && y_dims_array[i] == 1)) { out_dims_array[i] = std::max(x_dims_array[i], y_dims_array[i]); + } else { + out_dims_array[i] = -1; } } } -- GitLab