You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/06/20 13:15:56 UTC

[GitHub] [incubator-mxnet] wkcn commented on a change in pull request #15292: Numpy

wkcn commented on a change in pull request #15292: Numpy
URL: https://github.com/apache/incubator-mxnet/pull/15292#discussion_r295797743
 
 

 ##########
 File path: src/operator/numpy/np_gcd_op-inl.h
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ *  Copyright (c) 2019 by Contributors
+ * \file np_gcd_op-inl.h
+ * \brief Function definition of matrix related operators
+ */
+#ifndef MXNET_OPERATOR_NUMPY_NP_GCD_OP_INL_H_
+#define MXNET_OPERATOR_NUMPY_NP_GCD_OP_INL_H_
+
+#include <vector>
+#include "../tensor/broadcast_reduce_op.h"
+
+namespace mxnet {
+namespace op {
+
+template<int req>
+struct gcd_forward {
+  template<typename DType>
+  MSHADOW_XINLINE static void Map(int i,
+                                  DType* out_data,
+                                  const DType* in_data_1,
+                                  const DType* in_data_2) {
+    int a = in_data_1[i];
+    int b = in_data_2[i];
+
+    // minus cases.
+    if (a < 0) {
+       a = -a;
+    }
+
+    // minus cases.
+    if (b < 0) {
+       b = -b;
+    }
+
+    // handle zero-valued cases.
+    int 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 {
+       if (a < b) {
+          a^=b;
 
 Review comment:
   We can call `std::swap` to swap them.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services