clean up cpu signbit definition
authorJonathan L Long <jonlong@cs.berkeley.edu>
Thu, 21 Aug 2014 03:06:11 +0000 (20:06 -0700)
committerJonathan L Long <jonlong@cs.berkeley.edu>
Thu, 21 Aug 2014 03:06:11 +0000 (20:06 -0700)
The redundant "caffe_signbit" function was used as a circumlocution
around CUDA's signbit macro; we can just add extra parens to prevent
macro expansion.

include/caffe/util/math_functions.hpp
src/caffe/util/math_functions.cpp

index f4310bf..62467fb 100644 (file)
@@ -137,11 +137,10 @@ inline char caffe_sign(Dtype val) {
 DEFINE_CAFFE_CPU_UNARY_FUNC(sign, y[i] = caffe_sign<Dtype>(x[i]));
 
 // This returns a nonzero value if the input has its sign bit set.
-// The name sngbit is meant to avoid conflicts with std::signbit in the macro
-bool caffe_signbit(float arg);
-bool caffe_signbit(double arg);
-bool caffe_signbit(long double arg);
-DEFINE_CAFFE_CPU_UNARY_FUNC(sgnbit, y[i] = caffe_signbit(x[i]));
+// The name sngbit is meant to avoid conflicts with std::signbit in the macro.
+// The extra parens are needed because CUDA < 6.5 defines signbit as a macro,
+// and we don't want that to expand here when CUDA headers are also included.
+DEFINE_CAFFE_CPU_UNARY_FUNC(sgnbit, y[i] = (std::signbit)(x[i]));
 
 DEFINE_CAFFE_CPU_UNARY_FUNC(fabs, y[i] = std::fabs(x[i]));
 
index 7016e63..0338155 100644 (file)
@@ -387,16 +387,4 @@ void caffe_cpu_scale<double>(const int n, const double alpha, const double *x,
   cblas_dscal(n, alpha, y, 1);
 }
 
-
-using std::signbit;
-bool caffe_signbit(float arg) {
-    return signbit(arg);
-}
-bool caffe_signbit(double arg) {
-    return signbit(arg);
-}
-bool caffe_signbit(long double arg) {
-    return signbit(arg);
-}
-
 }  // namespace caffe