hzfan commented on a change in pull request #18053: [Numpy] New FFIs for 
Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#discussion_r409993623
 
 

 ##########
 File path: src/api/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -89,4 +89,50 @@ MXNET_REGISTER_API("_npi.mean")
   }
 });
 
+MXNET_REGISTER_API("_npi.prod")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_prod");
+  nnvm::NodeAttrs attrs;
+  op::NumpyReduceAxesParam param;
+  if (args[1].type_code() == kNull) {
+    param.axis = dmlc::optional<mxnet::Tuple<int>>();
+  } else if (args[1].type_code() == kDLInt) {
+    param.axis = Tuple<int>(1, args[1].operator int64_t());
+  } else {
+    param.axis = Tuple<int>(args[1].operator ObjectRef());
+  }
+  if (args[2].type_code() == kNull) {
+    param.dtype = dmlc::optional<int>();
+  } else {
+    param.dtype = String2MXNetTypeWithBool(args[2].operator std::string());
+  }
+  if (args[3].type_code() == kNull) {
+    param.keepdims = false;
+  } else {
+    param.keepdims = args[3].operator bool();
+  }
+  if (args[4].type_code() == kNull) {
+    param.initial = dmlc::optional<double>();
+  } else {
+    param.initial = args[4].operator double();
+  }
+  attrs.op = op;
+  attrs.parsed = std::move(param);
+  SetAttrDict<op::NumpyReduceAxesParam>(&attrs);
+  // inputs
+  NDArray* inputs[] = {args[0].operator mxnet::NDArray*()};
+  int num_inputs = 1;
+  // outputs
+  NDArray* out = args[5].operator mxnet::NDArray*();
+  NDArray** outputs = out == nullptr ? nullptr : &out;
+  int num_outputs = out != nullptr;
+  auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, 
outputs);
+  if (out) {
+    *ret = PythonArg(3);
 
 Review comment:
   `PythonArg(5)`. Here we specify the argument in `_api_intenral.prod` instead 
of `_op.prod`

----------------------------------------------------------------
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

Reply via email to