piiswrong commented on a change in pull request #8012: Proper float64 support 
for unary elemwise operators (mshadow_op.h)
URL: https://github.com/apache/incubator-mxnet/pull/8012#discussion_r143344056
 
 

 ##########
 File path: src/operator/mshadow_op.h
 ##########
 @@ -141,213 +186,223 @@ struct xelu_grad {
 struct elu {
   template<typename DType>
   MSHADOW_XINLINE static DType Map(DType x, DType a) {
-    return DType(x > DType(0.0f) ? x : a * (expf(x) - DType(1.0f)));
+    float af(static_cast<float>(a));
+    return x > DType(0) ? x : DType(af * math::expm1f(x));
   }
 };
 
 struct elu_grad {
   template<typename DType>
   MSHADOW_XINLINE static DType Map(DType x, DType a) {
-    return DType(x > DType(0.0f) ? DType(1.0f) : a + x);
+    return x > DType(0) ? DType(1) : DType(a + x);
   }
 };
 
-struct tanh {
-  template<typename DType>
-  MSHADOW_XINLINE static DType Map(DType a) {
-    return DType(tanhf( a ));
-  }
-};
+MAP_MATH_FUNC1(tanh);
 
 struct tanh_grad {
   template<typename DType>
   MSHADOW_XINLINE static DType Map(DType a) {
-    return DType(DType(1.0f) - a * a);
+    float af(static_cast<float>(a));
+    return DType(1.0f - af * af);
   }
 };
 
+template<>
+MSHADOW_XINLINE double tanh_grad::Map<double>(double a) {
 
 Review comment:
   why is this needed?
 
----------------------------------------------------------------
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