ChaiBapchya commented on a change in pull request #12749: [MXNET-1029] Feature 
request: randint operator
URL: https://github.com/apache/incubator-mxnet/pull/12749#discussion_r235504598
 
 

 ##########
 File path: src/operator/random/sample_op.h
 ##########
 @@ -694,13 +751,47 @@ inline bool SampleOpType(const nnvm::NodeAttrs& attrs,
   }
   bool dtype_ok = (dtype == kFloat16) || (dtype == kFloat32) ||
   (dtype == kFloat64);
-  CHECK_EQ(dtype_ok, true) << "Output type must be float16, float32, or 
float64: dtype is "
+  CHECK_EQ(dtype_ok, true) << "Output type must be float16, float32, float64: 
dtype is "
   << dtype_out << " vs " << kFloat16 << " or " << kFloat32 << " or "
   << kFloat64;
   TYPE_ASSIGN_CHECK(*out_type, 0, dtype);
   return true;
 }
 
+template<>
+inline bool SampleOpType<SampleRandIntParam>(const nnvm::NodeAttrs& attrs,
+                         std::vector<int> *in_type,
+                         std::vector<int> *out_type) {
+  const SampleRandIntParam& param = 
nnvm::get<SampleRandIntParam>(attrs.parsed);
+  CHECK_EQ(in_type->size(), 0);
+  CHECK_EQ(out_type->size(), 1);
+  int dtype = -1;
+  int dtype_out = (*out_type)[0];
+  if (dtype_out != -1) {
+    // Output type can be inferred, use it and make sure it matches
+    dtype = dtype_out;
+    if (param.dtype != -1) {
+      // dtype given in args, check that it matches the output type
+      CHECK_EQ(dtype_out, param.dtype) << "Output type does not match 
requested type: "
+      << dtype_out << " vs " << param.dtype;
+    }
+  } else {
+    // Output type can't be inferred
+    if (param.dtype != -1) {
+      // Use dtype given in args
+      dtype = param.dtype;
+    } else {
+      // Use default
+      dtype = kFloat32;
+    }
+  }
+  bool dtype_ok = (dtype == kInt32) || (dtype == kInt64);
+  CHECK_EQ(dtype_ok, true) << "Output type must be int32, int64: dtype is "
 
 Review comment:
   Done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to