haojin2 commented on a change in pull request #17254: [numpy] change unary infer type URL: https://github.com/apache/incubator-mxnet/pull/17254#discussion_r365557162
########## File path: src/operator/tensor/elemwise_binary_op.h ########## @@ -525,6 +525,68 @@ class ElemwiseBinaryOp : public OpBase { }); } + template<typename xpu, typename OP> + static void ComputeMixedTypeIn(const nnvm::NodeAttrs &attrs, + const OpContext &ctx, + const std::vector<TBlob> &inputs, + const std::vector<OpReqType> &req, + const std::vector<TBlob> &outputs) { + using namespace mxnet_op; + if (req[0] == kNullOp) return; + Stream<xpu> *s = ctx.get_stream<xpu>(); + CHECK_EQ(inputs.size(), 2U); + CHECK_EQ(outputs.size(), 1U); + if (!mxnet::common::is_float(inputs[1].type_flag_)) { + LOG(FATAL) << "Operator " << attrs.op->name << + " does not support type " << inputs[1].type_flag_; + } + if (outputs[0].type_flag_ == mshadow::kBool) { + LOG(FATAL) << "Operator " << attrs.op->name << " does not support boolean type"; + } + MXNET_ASSIGN_REQ_SWITCH(req[0], Req, { + MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, { + const size_t size = (minthree(outputs[0].Size(), inputs[0].Size(), inputs[1].Size()) + + DataType<DType>::kLanes - 1) / DataType<DType>::kLanes; + if (size != 0) { + Kernel<mxnet_op::op_with_req<OP, Req>, xpu>::Launch(s, size, + outputs[0].dptr<DType>(), + inputs[0].dptr<DType>(), inputs[1].dptr<DType>()); + } + }); + }); + } + + template<typename xpu, typename OP> + static void ComputeMixedTypeInOut(const nnvm::NodeAttrs &attrs, + const OpContext &ctx, + const std::vector<TBlob> &inputs, + const std::vector<OpReqType> &req, + const std::vector<TBlob> &outputs) { + using namespace mxnet_op; + if (req[0] == kNullOp) return; + Stream<xpu> *s = ctx.get_stream<xpu>(); + CHECK_EQ(inputs.size(), 3U); + CHECK_EQ(outputs.size(), 1U); + if (!mxnet::common::is_float(inputs[1].type_flag_)) { + LOG(FATAL) << "Operator " << attrs.op->name << + " does not support type " << inputs[1].type_flag_; + } + if (outputs[0].type_flag_ == mshadow::kBool) { + LOG(FATAL) << "Operator " << attrs.op->name << " does not support boolean type"; + } + MXNET_ASSIGN_REQ_SWITCH(req[0], Req, { + MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, { Review comment: use `MXNET_REAL_TYPE_SWITCH` here since you already excluded the integer case. ---------------------------------------------------------------- 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