[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #16124: [numpy] [tvm] operator true_divide

2019-09-14 Thread GitBox
reminisce commented on a change in pull request #16124: [numpy] [tvm] operator 
true_divide
URL: https://github.com/apache/incubator-mxnet/pull/16124#discussion_r324447425
 
 

 ##
 File path: src/operator/numpy/np_true_divide.cc
 ##
 @@ -41,19 +46,97 @@ bool TrueDivideType(const nnvm::NodeAttrs& attrs,
 const int lhs_dtype = in_attrs->at(0);
 const int rhs_dtype = in_attrs->at(1);
 CHECK_EQ(lhs_dtype, rhs_dtype)
-<< "_true_divide currently only supports same dtype for dividend and 
divisor";
+  << "_true_divide currently only supports same dtype for dividend and 
divisor";
   }
-  auto is_float = [](const int dtype) {
-return dtype == mshadow::kFloat32 || dtype == mshadow::kFloat64 || dtype 
== mshadow::kFloat16;
-  };
-
-  for (const int dtype : *in_attrs) {
-CHECK(is_float(dtype)) << "_true_divide currently only supports float 
dtype";
+  if (IsIntType(in_attrs->at(0))) {
+TYPE_ASSIGN_CHECK(*out_attrs, 0, mshadow::kFloat64);
 
 Review comment:
   We use `float32` as default dtype.


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


[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #16124: [numpy] [tvm] operator true_divide

2019-09-14 Thread GitBox
reminisce commented on a change in pull request #16124: [numpy] [tvm] operator 
true_divide
URL: https://github.com/apache/incubator-mxnet/pull/16124#discussion_r324447266
 
 

 ##
 File path: contrib/tvmop/core/umath.py
 ##
 @@ -0,0 +1,112 @@
+ # 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.
+import tvm
+from .. import defop, AllTypes, AllTypesButHalf
+
+def compute_true_divide(dtype, ndim):
+A = tvm.placeholder([tvm.var() for _ in range(ndim)], name='A', 
dtype=dtype)
+B = tvm.placeholder([tvm.var() for _ in range(ndim)], name='B', 
dtype=dtype)
+if dtype in ["float16", "float32", "float64"]:
+C = tvm.compute([tvm.var() for _ in range(ndim)],
+lambda *index: A[index] / B[index], name='C')
+else:
+C = tvm.compute([tvm.var() for _ in range(ndim)],
+lambda *index: A[index].astype("float64") /
 
 Review comment:
   This always produces fp64 dtype as output. We should support allowing users 
to set desired float dtypes. Also note that in numpy (divide/true_divide), it's 
not allowed to set integer dtype for outputs.


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


[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #16124: [numpy] [tvm] operator true_divide

2019-09-14 Thread GitBox
reminisce commented on a change in pull request #16124: [numpy] [tvm] operator 
true_divide
URL: https://github.com/apache/incubator-mxnet/pull/16124#discussion_r324447266
 
 

 ##
 File path: contrib/tvmop/core/umath.py
 ##
 @@ -0,0 +1,112 @@
+ # 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.
+import tvm
+from .. import defop, AllTypes, AllTypesButHalf
+
+def compute_true_divide(dtype, ndim):
+A = tvm.placeholder([tvm.var() for _ in range(ndim)], name='A', 
dtype=dtype)
+B = tvm.placeholder([tvm.var() for _ in range(ndim)], name='B', 
dtype=dtype)
+if dtype in ["float16", "float32", "float64"]:
+C = tvm.compute([tvm.var() for _ in range(ndim)],
+lambda *index: A[index] / B[index], name='C')
+else:
+C = tvm.compute([tvm.var() for _ in range(ndim)],
+lambda *index: A[index].astype("float64") /
 
 Review comment:
   This always produces fp64 dtype as output. We should support allowing users 
to set desired output dtype.


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


[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #16124: [numpy] [tvm] operator true_divide

2019-09-08 Thread GitBox
reminisce commented on a change in pull request #16124: [numpy] [tvm] operator 
true_divide
URL: https://github.com/apache/incubator-mxnet/pull/16124#discussion_r322070283
 
 

 ##
 File path: src/operator/numpy/np_true_divide.h
 ##
 @@ -0,0 +1,84 @@
+/*
+ * 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_true_divide.h
+ */
+#ifndef MXNET_OPERATOR_NUMPY_NP_TRUE_DIVIDE_H_
+#define MXNET_OPERATOR_NUMPY_NP_TRUE_DIVIDE_H_
+
+#include "../tensor/elemwise_binary_broadcast_op.h"
+#include "../tensor/elemwise_binary_scalar_op.h"
+
+namespace mxnet {
+namespace op {
+
+inline bool IsIntType(const int dtype) {
+  return (dtype == mshadow::kUint8 ||
+  dtype == mshadow::kInt32 ||
+  dtype == mshadow::kInt8 ||
+  dtype == mshadow::kInt64);
+}
+
+template
+void BinaryBroadcastBackwardUseInFloat(const nnvm::NodeAttrs& attrs,
+   const OpContext& ctx,
+   const std::vector& inputs,
+   const std::vector& req,
+   const std::vector& outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
+  }
+  BinaryBroadcastBackwardUseIn(attrs, ctx, inputs, req, 
outputs);
+}
+
+template
+void BinaryScalarOpComputeFloat(const nnvm::NodeAttrs &attrs,
+const OpContext &ctx,
+const std::vector &inputs,
+const std::vector &req,
+const std::vector &outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
+  }
+  BinaryScalarOp::Compute(attrs, ctx, inputs, req, outputs);
+}
+
+template
+void BinaryScalarOpBackwardFloat(const nnvm::NodeAttrs &attrs,
+const OpContext &ctx,
+const std::vector &inputs,
+const std::vector &req,
+const std::vector &outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
 
 Review comment:
   Please use
   ```cpp
   CHECK(!IsIntType(outputs[0].type_flag_) << error_message;
   ```


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


[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #16124: [numpy] [tvm] operator true_divide

2019-09-08 Thread GitBox
reminisce commented on a change in pull request #16124: [numpy] [tvm] operator 
true_divide
URL: https://github.com/apache/incubator-mxnet/pull/16124#discussion_r322070128
 
 

 ##
 File path: src/operator/numpy/np_true_divide.h
 ##
 @@ -0,0 +1,84 @@
+/*
+ * 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_true_divide.h
+ */
+#ifndef MXNET_OPERATOR_NUMPY_NP_TRUE_DIVIDE_H_
+#define MXNET_OPERATOR_NUMPY_NP_TRUE_DIVIDE_H_
+
+#include "../tensor/elemwise_binary_broadcast_op.h"
+#include "../tensor/elemwise_binary_scalar_op.h"
+
+namespace mxnet {
+namespace op {
+
+inline bool IsIntType(const int dtype) {
+  return (dtype == mshadow::kUint8 ||
+  dtype == mshadow::kInt32 ||
+  dtype == mshadow::kInt8 ||
+  dtype == mshadow::kInt64);
+}
+
+template
+void BinaryBroadcastBackwardUseInFloat(const nnvm::NodeAttrs& attrs,
+   const OpContext& ctx,
+   const std::vector& inputs,
+   const std::vector& req,
+   const std::vector& outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
+  }
+  BinaryBroadcastBackwardUseIn(attrs, ctx, inputs, req, 
outputs);
+}
+
+template
+void BinaryScalarOpComputeFloat(const nnvm::NodeAttrs &attrs,
+const OpContext &ctx,
+const std::vector &inputs,
+const std::vector &req,
+const std::vector &outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
+  }
+  BinaryScalarOp::Compute(attrs, ctx, inputs, req, outputs);
+}
+
+template
+void BinaryScalarOpBackwardFloat(const nnvm::NodeAttrs &attrs,
+const OpContext &ctx,
+const std::vector &inputs,
+const std::vector &req,
+const std::vector &outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
 
 Review comment:
   Please use
   ```cpp
   LOG(FATAL) << error_message;
   ```


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


[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #16124: [numpy] [tvm] operator true_divide

2019-09-08 Thread GitBox
reminisce commented on a change in pull request #16124: [numpy] [tvm] operator 
true_divide
URL: https://github.com/apache/incubator-mxnet/pull/16124#discussion_r322070128
 
 

 ##
 File path: src/operator/numpy/np_true_divide.h
 ##
 @@ -0,0 +1,84 @@
+/*
+ * 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_true_divide.h
+ */
+#ifndef MXNET_OPERATOR_NUMPY_NP_TRUE_DIVIDE_H_
+#define MXNET_OPERATOR_NUMPY_NP_TRUE_DIVIDE_H_
+
+#include "../tensor/elemwise_binary_broadcast_op.h"
+#include "../tensor/elemwise_binary_scalar_op.h"
+
+namespace mxnet {
+namespace op {
+
+inline bool IsIntType(const int dtype) {
+  return (dtype == mshadow::kUint8 ||
+  dtype == mshadow::kInt32 ||
+  dtype == mshadow::kInt8 ||
+  dtype == mshadow::kInt64);
+}
+
+template
+void BinaryBroadcastBackwardUseInFloat(const nnvm::NodeAttrs& attrs,
+   const OpContext& ctx,
+   const std::vector& inputs,
+   const std::vector& req,
+   const std::vector& outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
+  }
+  BinaryBroadcastBackwardUseIn(attrs, ctx, inputs, req, 
outputs);
+}
+
+template
+void BinaryScalarOpComputeFloat(const nnvm::NodeAttrs &attrs,
+const OpContext &ctx,
+const std::vector &inputs,
+const std::vector &req,
+const std::vector &outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
+  }
+  BinaryScalarOp::Compute(attrs, ctx, inputs, req, outputs);
+}
+
+template
+void BinaryScalarOpBackwardFloat(const nnvm::NodeAttrs &attrs,
+const OpContext &ctx,
+const std::vector &inputs,
+const std::vector &req,
+const std::vector &outputs) {
+  if (IsIntType(outputs[0].type_flag_)) {
+std::ostringstream os;
+os << "Cannot compute ingrad if type of input is `int`.\n";
+throw::mxnet::op::InferTypeError(os.str(), 0);
 
 Review comment:
   Please use
   ```cpp
   LOG(FATAL) << error_message;
   ```


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