reminisce commented on a change in pull request #17358: np.broadcast_to extension URL: https://github.com/apache/incubator-mxnet/pull/17358#discussion_r368206533
########## File path: src/operator/numpy/np_broadcast_reduce_op_value.cc ########## @@ -467,17 +467,21 @@ bool NumpyBroadcastToShape(const nnvm::NodeAttrs& attrs, mxnet::TShape& ishape = (*in_attrs)[0]; if (!mxnet::shape_is_known(ishape)) return false; const BroadcastToParam& param = nnvm::get<BroadcastToParam>(attrs.parsed); - CHECK(mxnet::shape_is_known(param.shape)) - << "the objective shape for broadcasting array must be known"; CHECK_LE(ishape.ndim(), param.shape.ndim()) << "shape " << ishape << " is not broadcastable to " << param.shape; + TShape pshape = param.shape; for (int i = param.shape.ndim() - 1; i >= 0; --i) { int j = i - param.shape.ndim() + ishape.ndim(); if (j < 0) break; - CHECK(ishape[j] == param.shape[i] || ishape[j] == 1) - << "shape " << ishape << " is not broadcastable to " << param.shape; + if (pshape[i] == -2) { + pshape[i] = ishape[j]; + } + CHECK(ishape[j] == pshape[i] || ishape[j] == 1) + << "shape " << ishape << " is not broadcastable to " << pshape; } - SHAPE_ASSIGN_CHECK(*out_attrs, 0, param.shape); + CHECK(mxnet::shape_is_known(pshape)) Review comment: `-1` does not mean copying dim size in NumPy; it actually means deducing shape with the available information. The point is we should not `CHECK(mxnet::shape_is_known(pshape))` since it implies that the destination shape is unknown which is different from NumPy semantics. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services