template<typename Dtype>
void caffe_gpu_sign(const int n, const Dtype* x, Dtype* y);
-// returns a nonzero value is the input has its sign bit set.
-DEFINE_CAFFE_CPU_UNARY_FUNC(signbit, y[i] = std::signbit(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
+using std::signbit;
+DEFINE_CAFFE_CPU_UNARY_FUNC(sgnbit, y[i] = signbit(x[i]));
template<typename Dtype>
-void caffe_gpu_signbit(const int n, const Dtype* x, Dtype* y);
+void caffe_gpu_sgnbit(const int n, const Dtype* x, Dtype* y);
DEFINE_CAFFE_CPU_UNARY_FUNC(fabs, y[i] = std::fabs(x[i]));
}
}
-TYPED_TEST(MathFunctionsTest, TestSignbitCPU){
+TYPED_TEST(MathFunctionsTest, TestSgnbitCPU){
int n = this->blob_bottom_->count();
const TypeParam* x = this->blob_bottom_->cpu_data();
- caffe_cpu_signbit<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());
+ caffe_cpu_sgnbit<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());
const TypeParam* signbits = this->blob_bottom_->cpu_diff();
for (int i = 0; i < n; ++i) {
CHECK_EQ(signbits[i], x[i] < 0 ? 1 : 0);
}
}
-TYPED_TEST(MathFunctionsTest, TestSignbitGPU){
+TYPED_TEST(MathFunctionsTest, TestSgnbitGPU){
int n = this->blob_bottom_->count();
- caffe_gpu_signbit<TypeParam>(n, this->blob_bottom_->gpu_data(),
+ caffe_gpu_sgnbit<TypeParam>(n, this->blob_bottom_->gpu_data(),
this->blob_bottom_->mutable_gpu_diff());
const TypeParam* signbits = this->blob_bottom_->cpu_diff();
const TypeParam* x = this->blob_bottom_->cpu_data();
}
DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sign, y[index] = (Dtype(0) < x[index]) - (x[index] < Dtype(0)));
-DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(signbit, y[index] = signbit(x[index]));
+DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sgnbit, y[index] = signbit(x[index]));
DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(fabs, y[index] = fabs(x[index]));
} // namespace caffe