access2rohit commented on a change in pull request #19547:
URL: https://github.com/apache/incubator-mxnet/pull/19547#discussion_r569007106



##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -3021,6 +3021,7 @@ def hybrid_forward(self, F, a, b, *args, **kwargs):
                       [[_np.float16, _np.float32, _np.float64], [_np.int32]]),
         'power': (1.0, 3.0, [lambda y, x1, x2: _np.power(x1, x2 - 1.0) * x2],
                              [lambda y, x1, x2: _np.power(x1, x2) * 
_np.log(x1)]),
+        'gcd': (-100, 100, [None], None, [[_np.int32]]),

Review comment:
       Can you tell me what is the test case here ? I didn't understand i/p and 
expected o/p 

##########
File path: src/common/cuda/rtc/forward_functions-inl.h
##########
@@ -541,6 +541,49 @@ lcm(const DType a, const DType2 b) {
   }
 }
 
+template <typename DType, typename DType2>
+__device__ inline typename type_util::mixed_type<DType, DType2>::type
+gcd(const DType a, const DType2 b) {
+  if (type_util::is_integral<DType>::value &&
+      type_util::is_integral<DType2>::value) {
+    DType A = a;
+    DType2 B = b;
+    // minus cases.
+    if (a < 0) {
+      A = -a;
+    }
+    if (b < 0) {
+      B = -b;
+    }
+    // handle zero-valued cases.
+    DType c;
+    if (a == 0 && b != 0) {
+      c = B;
+    } else if (b == 0 && a != 0) {
+      c = A;
+    } else if (a == 0 && b == 0) {
+      c = 0;
+    } else {
+      DType tmp;
+      if (A < B) {
+        tmp = A;
+        A = B;
+        B = tmp;
+      }
+      while (A % B != 0) {

Review comment:
       if the code executes in GPU it might be better to convert 
   `a%b = a - Floor(a/b) * b`
   this is a lot faster on GPU plus save the a%b in a variable instead of 
evaluating in the while loop 




----------------------------------------------------------------
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:
[email protected]


Reply via email to