summaryrefslogtreecommitdiff
path: root/src/caffe/util/math_functions.cpp
diff options
context:
space:
mode:
authorEvan Shelhamer <shelhamer@imaginarynumber.net>2014-03-21 23:47:01 -0700
committerEvan Shelhamer <shelhamer@imaginarynumber.net>2014-03-22 12:08:26 -0700
commit19bcf2b29bf9e48ff84d18763c6d2b5f41e5bdcd (patch)
treef01b1ac136d60883ec62982fdd86a9ac3e6ffe37 /src/caffe/util/math_functions.cpp
parentaaa26466eb74f94f5d403cf3cc2b5fb6e0a17a06 (diff)
downloadcaffeonacl-19bcf2b29bf9e48ff84d18763c6d2b5f41e5bdcd.tar.gz
caffeonacl-19bcf2b29bf9e48ff84d18763c6d2b5f41e5bdcd.tar.bz2
caffeonacl-19bcf2b29bf9e48ff84d18763c6d2b5f41e5bdcd.zip
Hide boost rng behind facade for osx compatibility
Split boost random number generation from the common Caffe singleton and add a helper function for rng. This resolves a build conflict in OSX between boost rng and nvcc compilation of cuda code. Refer to #165 for a full discussion. Thanks to @satol for suggesting a random number generation facade rather than a total split of cpp and cu code, which is far more involved.
Diffstat (limited to 'src/caffe/util/math_functions.cpp')
-rw-r--r--src/caffe/util/math_functions.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/caffe/util/math_functions.cpp b/src/caffe/util/math_functions.cpp
index 3da4b21b..3d02c5ff 100644
--- a/src/caffe/util/math_functions.cpp
+++ b/src/caffe/util/math_functions.cpp
@@ -1,5 +1,6 @@
// Copyright 2013 Yangqing Jia
// Copyright 2014 kloudkl@github
+// Copyright 2014 Evan Shelhamer
#include <boost/math/special_functions/next.hpp>
#include <boost/random.hpp>
@@ -9,6 +10,7 @@
#include "caffe/common.hpp"
#include "caffe/util/math_functions.hpp"
+#include "caffe/util/rng.hpp"
namespace caffe {
@@ -287,10 +289,9 @@ void caffe_vRngUniform(const int n, Dtype* r,
boost::uniform_real<Dtype> random_distribution(
a, caffe_nextafter<Dtype>(b));
- Caffe::random_generator_t &generator = Caffe::rng_stream();
- boost::variate_generator<Caffe::random_generator_t,
+ boost::variate_generator<caffe::rng_t,
boost::uniform_real<Dtype> > variate_generator(
- generator, random_distribution);
+ caffe_rng(), random_distribution);
for (int i = 0; i < n; ++i) {
r[i] = variate_generator();
@@ -311,10 +312,9 @@ void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a,
CHECK(r);
CHECK_GT(sigma, 0);
boost::normal_distribution<Dtype> random_distribution(a, sigma);
- Caffe::random_generator_t &generator = Caffe::rng_stream();
- boost::variate_generator<Caffe::random_generator_t,
+ boost::variate_generator<caffe::rng_t,
boost::normal_distribution<Dtype> > variate_generator(
- generator, random_distribution);
+ caffe_rng(), random_distribution);
for (int i = 0; i < n; ++i) {
r[i] = variate_generator();
@@ -336,10 +336,9 @@ void caffe_vRngBernoulli(const int n, Dtype* r, const double p) {
CHECK_GE(p, 0);
CHECK_LE(p, 1);
boost::bernoulli_distribution<double> random_distribution(p);
- Caffe::random_generator_t &generator = Caffe::rng_stream();
- boost::variate_generator<Caffe::random_generator_t,
+ boost::variate_generator<caffe::rng_t,
boost::bernoulli_distribution<double> > variate_generator(
- generator, random_distribution);
+ caffe_rng(), random_distribution);
for (int i = 0; i < n; ++i) {
r[i] = variate_generator();