summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Donahue <jeff.donahue@gmail.com>2014-04-08 13:18:29 -0700
committerJeff Donahue <jeff.donahue@gmail.com>2014-04-08 20:17:17 -0700
commitd00279917a5282e8ce6194c87e443623e545033a (patch)
treee0a4c2bb07ad94b7a6e5c3730df80c2e34a6d065 /src
parent078e0bf713bcc4f9178f6694c66b368302448484 (diff)
downloadcaffeonacl-d00279917a5282e8ce6194c87e443623e545033a.tar.gz
caffeonacl-d00279917a5282e8ce6194c87e443623e545033a.tar.bz2
caffeonacl-d00279917a5282e8ce6194c87e443623e545033a.zip
make RNG function outputs the last argument per Google C++ style guidelines
Diffstat (limited to 'src')
-rw-r--r--src/caffe/layers/dropout_layer.cpp2
-rw-r--r--src/caffe/test/test_common.cpp10
-rw-r--r--src/caffe/test/test_random_number_generator.cpp6
-rw-r--r--src/caffe/util/math_functions.cpp30
4 files changed, 23 insertions, 25 deletions
diff --git a/src/caffe/layers/dropout_layer.cpp b/src/caffe/layers/dropout_layer.cpp
index a9dd842e..e0068fed 100644
--- a/src/caffe/layers/dropout_layer.cpp
+++ b/src/caffe/layers/dropout_layer.cpp
@@ -32,7 +32,7 @@ Dtype DropoutLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const int count = bottom[0]->count();
if (Caffe::phase() == Caffe::TRAIN) {
// Create random numbers
- caffe_rng_bernoulli(count, mask, 1. - threshold_);
+ caffe_rng_bernoulli(count, 1. - threshold_, mask);
for (int i = 0; i < count; ++i) {
top_data[i] = bottom_data[i] * mask[i] * scale_;
}
diff --git a/src/caffe/test/test_common.cpp b/src/caffe/test/test_common.cpp
index a043db16..f236d125 100644
--- a/src/caffe/test/test_common.cpp
+++ b/src/caffe/test/test_common.cpp
@@ -36,16 +36,14 @@ TEST_F(CommonTest, TestRandSeedCPU) {
SyncedMemory data_a(10 * sizeof(int));
SyncedMemory data_b(10 * sizeof(int));
Caffe::set_random_seed(1701);
- caffe_rng_bernoulli(10,
- reinterpret_cast<int*>(data_a.mutable_cpu_data()), 0.5);
+ caffe_rng_bernoulli(10, 0.5, static_cast<int*>(data_a.mutable_cpu_data()));
Caffe::set_random_seed(1701);
- caffe_rng_bernoulli(10,
- reinterpret_cast<int*>(data_b.mutable_cpu_data()), 0.5);
+ caffe_rng_bernoulli(10, 0.5, static_cast<int*>(data_b.mutable_cpu_data()));
for (int i = 0; i < 10; ++i) {
- EXPECT_EQ(((const int*)(data_a.cpu_data()))[i],
- ((const int*)(data_b.cpu_data()))[i]);
+ EXPECT_EQ(static_cast<const int*>(data_a.cpu_data())[i],
+ static_cast<const int*>(data_b.cpu_data())[i]);
}
}
diff --git a/src/caffe/test/test_random_number_generator.cpp b/src/caffe/test/test_random_number_generator.cpp
index 664f82f1..d068d03c 100644
--- a/src/caffe/test/test_random_number_generator.cpp
+++ b/src/caffe/test/test_random_number_generator.cpp
@@ -60,7 +60,7 @@ class RandomNumberGeneratorTest : public ::testing::Test {
void RngGaussianTest(const Dtype mu, const Dtype sigma, void* cpu_data) {
Dtype* rng_data = static_cast<Dtype*>(cpu_data);
- caffe_rng_gaussian(sample_size_, rng_data, mu, sigma);
+ caffe_rng_gaussian(sample_size_, mu, sigma, rng_data);
const Dtype true_mean = mu;
const Dtype true_std = sigma;
// Check that sample mean roughly matches true mean.
@@ -90,7 +90,7 @@ class RandomNumberGeneratorTest : public ::testing::Test {
void RngUniformTest(const Dtype lower, const Dtype upper, void* cpu_data) {
CHECK_GE(upper, lower);
Dtype* rng_data = static_cast<Dtype*>(cpu_data);
- caffe_rng_uniform(sample_size_, rng_data, lower, upper);
+ caffe_rng_uniform(sample_size_, lower, upper, rng_data);
const Dtype true_mean = (lower + upper) / 2;
const Dtype true_std = (upper - lower) / sqrt(12);
// Check that sample mean roughly matches true mean.
@@ -128,7 +128,7 @@ class RandomNumberGeneratorTest : public ::testing::Test {
void RngBernoulliTest(const Dtype p, void* cpu_data) {
int* rng_data = static_cast<int*>(cpu_data);
- caffe_rng_bernoulli(sample_size_, rng_data, p);
+ caffe_rng_bernoulli(sample_size_, p, rng_data);
const Dtype true_mean = p;
const Dtype true_std = sqrt(p * (1 - p));
const Dtype bound = this->mean_bound(true_std);
diff --git a/src/caffe/util/math_functions.cpp b/src/caffe/util/math_functions.cpp
index a524ed3d..c26675f8 100644
--- a/src/caffe/util/math_functions.cpp
+++ b/src/caffe/util/math_functions.cpp
@@ -315,8 +315,7 @@ template
double caffe_nextafter(const double b);
template <typename Dtype>
-void caffe_rng_uniform(const int n, Dtype* r,
- const Dtype a, const Dtype b) {
+void caffe_rng_uniform(const int n, const Dtype a, const Dtype b, Dtype* r) {
CHECK_GE(n, 0);
CHECK(r);
CHECK_LE(a, b);
@@ -330,15 +329,16 @@ void caffe_rng_uniform(const int n, Dtype* r,
}
template
-void caffe_rng_uniform<float>(const int n, float* r,
- const float a, const float b);
+void caffe_rng_uniform<float>(const int n, const float a, const float b,
+ float* r);
+
template
-void caffe_rng_uniform<double>(const int n, double* r,
- const double a, const double b);
+void caffe_rng_uniform<double>(const int n, const double a, const double b,
+ double* r);
template <typename Dtype>
-void caffe_rng_gaussian(const int n, Dtype* r, const Dtype a,
- const Dtype sigma) {
+void caffe_rng_gaussian(const int n, const Dtype a,
+ const Dtype sigma, Dtype* r) {
CHECK_GE(n, 0);
CHECK(r);
CHECK_GT(sigma, 0);
@@ -352,15 +352,15 @@ void caffe_rng_gaussian(const int n, Dtype* r, const Dtype a,
}
template
-void caffe_rng_gaussian<float>(const int n, float* r, const float a,
- const float sigma);
+void caffe_rng_gaussian<float>(const int n, const float mu,
+ const float sigma, float* r);
template
-void caffe_rng_gaussian<double>(const int n, double* r, const double a,
- const double sigma);
+void caffe_rng_gaussian<double>(const int n, const double mu,
+ const double sigma, double* r);
template <typename Dtype>
-void caffe_rng_bernoulli(const int n, int* r, const Dtype p) {
+void caffe_rng_bernoulli(const int n, const Dtype p, int* r) {
CHECK_GE(n, 0);
CHECK(r);
CHECK_GE(p, 0);
@@ -375,10 +375,10 @@ void caffe_rng_bernoulli(const int n, int* r, const Dtype p) {
}
template
-void caffe_rng_bernoulli<double>(const int n, int* r, const double p);
+void caffe_rng_bernoulli<double>(const int n, const double p, int* r);
template
-void caffe_rng_bernoulli<float>(const int n, int* r, const float p);
+void caffe_rng_bernoulli<float>(const int n, const float p, int* r);
template <>
float caffe_cpu_dot<float>(const int n, const float* x, const float* y) {