Fixed CPPLint errors related to math funtions
authorKai Li <kaili_kloud@163.com>
Tue, 18 Mar 2014 07:22:14 +0000 (15:22 +0800)
committerKai Li <kaili_kloud@163.com>
Sun, 23 Mar 2014 13:41:25 +0000 (21:41 +0800)
include/caffe/util/math_functions.hpp
src/caffe/test/test_math_functions.cpp
src/caffe/util/math_functions.cu

index b18a058..81097ef 100644 (file)
@@ -4,9 +4,9 @@
 #ifndef CAFFE_UTIL_MATH_FUNCTIONS_H_
 #define CAFFE_UTIL_MATH_FUNCTIONS_H_
 
-#include <cmath> // for std::fabs
-#include <math.h> // for signbit
 #include <cublas_v2.h>
+#include <math.h>  // for signbit
+#include <cmath>  // for std::fabs
 
 #include "caffe/util/mkl_alternate.hpp"
 
@@ -159,11 +159,13 @@ __global__ void name##_kernel(const int n, const Dtype* x, Dtype* y) { \
 } \
 template <> \
 void caffe_gpu_##name<float>(const int n, const float* x, float* y) { \
+  /* NOLINT_NEXT_LINE(whitespace/operators) */ \
   name##_kernel<float><<<CAFFE_GET_BLOCKS(n), CAFFE_CUDA_NUM_THREADS>>>( \
       n, x, y); \
 } \
 template <> \
 void caffe_gpu_##name<double>(const int n, const double* x, double* y) { \
+  /* NOLINT_NEXT_LINE(whitespace/operators) */ \
   name##_kernel<double><<<CAFFE_GET_BLOCKS(n), CAFFE_CUDA_NUM_THREADS>>>( \
       n, x, y); \
 }
index 9a68d87..ca059a9 100644 (file)
@@ -1,7 +1,10 @@
 // Copyright 2014 kloudkl@github
 
-#include <stdint.h> // for uint32_t & uint64_t
-#include <cmath> // for std::fabs
+#include <stdint.h>  // for uint32_t & uint64_t
+#include <time.h>
+#include <climits>
+#include <cmath>  // for std::fabs
+#include <cstdlib>  // for rand_r
 
 #include "gtest/gtest.h"
 #include "caffe/blob.hpp"
@@ -23,8 +26,8 @@ class MathFunctionsTest : public ::testing::Test {
 
   virtual void SetUp() {
     Caffe::set_random_seed(1701);
-    this->blob_bottom_->Reshape(100, 70, 50, 30);
-    this->blob_top_->Reshape(100, 70, 50, 30);
+    this->blob_bottom_->Reshape(11, 17, 19, 23);
+    this->blob_top_->Reshape(11, 17, 19, 23);
     // fill the values
     FillerParameter filler_param;
     GaussianFiller<Dtype> filler(filler_param);
@@ -67,7 +70,7 @@ REF_HAMMING_DIST(double, uint64_t);
 typedef ::testing::Types<float, double> Dtypes;
 TYPED_TEST_CASE(MathFunctionsTest, Dtypes);
 
-TYPED_TEST(MathFunctionsTest, TestHammingDistance){
+TYPED_TEST(MathFunctionsTest, TestHammingDistance) {
   int n = this->blob_bottom_->count();
   const TypeParam* x = this->blob_bottom_->cpu_data();
   const TypeParam* y = this->blob_top_->cpu_data();
@@ -75,7 +78,7 @@ TYPED_TEST(MathFunctionsTest, TestHammingDistance){
            caffe_hamming_distance<TypeParam>(n, x, y));
 }
 
-TYPED_TEST(MathFunctionsTest, TestAsumCPU){
+TYPED_TEST(MathFunctionsTest, TestAsumCPU) {
   int n = this->blob_bottom_->count();
   const TypeParam* x = this->blob_bottom_->cpu_data();
   TypeParam std_asum = 0;
@@ -86,7 +89,7 @@ TYPED_TEST(MathFunctionsTest, TestAsumCPU){
   CHECK_LT((cpu_asum - std_asum) / std_asum, 1e-2);
 }
 
-TYPED_TEST(MathFunctionsTest, TestAsumGPU){
+TYPED_TEST(MathFunctionsTest, TestAsumGPU) {
   int n = this->blob_bottom_->count();
   const TypeParam* x = this->blob_bottom_->cpu_data();
   TypeParam std_asum = 0;
@@ -98,7 +101,7 @@ TYPED_TEST(MathFunctionsTest, TestAsumGPU){
   CHECK_LT((gpu_asum - std_asum) / std_asum, 1e-2);
 }
 
-TYPED_TEST(MathFunctionsTest, TestSignCPU){
+TYPED_TEST(MathFunctionsTest, TestSignCPU) {
   int n = this->blob_bottom_->count();
   const TypeParam* x = this->blob_bottom_->cpu_data();
   caffe_cpu_sign<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());
@@ -108,7 +111,7 @@ TYPED_TEST(MathFunctionsTest, TestSignCPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestSignGPU){
+TYPED_TEST(MathFunctionsTest, TestSignGPU) {
   int n = this->blob_bottom_->count();
   caffe_gpu_sign<TypeParam>(n, this->blob_bottom_->gpu_data(),
                             this->blob_bottom_->mutable_gpu_diff());
@@ -119,7 +122,7 @@ TYPED_TEST(MathFunctionsTest, TestSignGPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestSgnbitCPU){
+TYPED_TEST(MathFunctionsTest, TestSgnbitCPU) {
   int n = this->blob_bottom_->count();
   const TypeParam* x = this->blob_bottom_->cpu_data();
   caffe_cpu_sgnbit<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());
@@ -129,7 +132,7 @@ TYPED_TEST(MathFunctionsTest, TestSgnbitCPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestSgnbitGPU){
+TYPED_TEST(MathFunctionsTest, TestSgnbitGPU) {
   int n = this->blob_bottom_->count();
   caffe_gpu_sgnbit<TypeParam>(n, this->blob_bottom_->gpu_data(),
                             this->blob_bottom_->mutable_gpu_diff());
@@ -140,7 +143,7 @@ TYPED_TEST(MathFunctionsTest, TestSgnbitGPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestFabsCPU){
+TYPED_TEST(MathFunctionsTest, TestFabsCPU) {
   int n = this->blob_bottom_->count();
   const TypeParam* x = this->blob_bottom_->cpu_data();
   caffe_cpu_fabs<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());
@@ -150,7 +153,7 @@ TYPED_TEST(MathFunctionsTest, TestFabsCPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestFabsGPU){
+TYPED_TEST(MathFunctionsTest, TestFabsGPU) {
   int n = this->blob_bottom_->count();
   caffe_gpu_fabs<TypeParam>(n, this->blob_bottom_->gpu_data(),
                             this->blob_bottom_->mutable_gpu_diff());
@@ -161,8 +164,9 @@ TYPED_TEST(MathFunctionsTest, TestFabsGPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestScaleCPU){
+TYPED_TEST(MathFunctionsTest, TestScaleCPU) {
   int n = this->blob_bottom_->count();
+  // NOLINT_NEXT_LINE(runtime/threadsafe_fn)
   TypeParam alpha = this->blob_bottom_->cpu_diff()[rand() %
                                                this->blob_bottom_->count()];
   caffe_cpu_scale<TypeParam>(n, alpha, this->blob_bottom_->cpu_data(),
@@ -174,8 +178,9 @@ TYPED_TEST(MathFunctionsTest, TestScaleCPU){
   }
 }
 
-TYPED_TEST(MathFunctionsTest, TestScaleGPU){
+TYPED_TEST(MathFunctionsTest, TestScaleGPU) {
   int n = this->blob_bottom_->count();
+  // NOLINT_NEXT_LINE(runtime/threadsafe_fn)
   TypeParam alpha = this->blob_bottom_->cpu_diff()[rand() %
                                                this->blob_bottom_->count()];
   caffe_gpu_scale<TypeParam>(n, alpha, this->blob_bottom_->gpu_data(),
@@ -187,4 +192,4 @@ TYPED_TEST(MathFunctionsTest, TestScaleGPU){
   }
 }
 
-}
+}  // namespace caffe
index 2cf1cfc..85753aa 100644 (file)
@@ -1,10 +1,10 @@
 // Copyright 2013 Yangqing Jia
 // Copyright 2014 kloudkl@github
 
+#include <math_functions.h>  // CUDA's, not caffe's, for fabs, signbit
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
-#include <math_functions.h> // CUDA's, not caffe's, for fabs, signbit
 
 #include "caffe/common.hpp"
 #include "caffe/util/math_functions.hpp"
@@ -35,7 +35,8 @@ void caffe_gpu_mul<double>(const int N, const double* a,
       N, a, b, y);
 }
 
-DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sign, y[index] = (Dtype(0) < x[index]) - (x[index] < Dtype(0)));
+DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sign, y[index] = (Dtype(0) < x[index])
+                                      - (x[index] < Dtype(0)));
 DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sgnbit, y[index] = signbit(x[index]));
 DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(fabs, y[index] = fabs(x[index]));