/usr/include/caffe/util/rng.hpp is in libcaffe-cpu-dev 1.0.0~rc4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #ifndef CAFFE_RNG_CPP_HPP_
#define CAFFE_RNG_CPP_HPP_
#include <algorithm>
#include <iterator>
#include "boost/random/mersenne_twister.hpp"
#include "boost/random/uniform_int.hpp"
#include "caffe/common.hpp"
namespace caffe {
typedef boost::mt19937 rng_t;
inline rng_t* caffe_rng() {
return static_cast<caffe::rng_t*>(Caffe::rng_stream().generator());
}
// Fisher–Yates algorithm
template <class RandomAccessIterator, class RandomGenerator>
inline void shuffle(RandomAccessIterator begin, RandomAccessIterator end,
RandomGenerator* gen) {
typedef typename std::iterator_traits<RandomAccessIterator>::difference_type
difference_type;
typedef typename boost::uniform_int<difference_type> dist_type;
difference_type length = std::distance(begin, end);
if (length <= 0) return;
for (difference_type i = length - 1; i > 0; --i) {
dist_type dist(0, i);
std::iter_swap(begin + i, begin + dist(*gen));
}
}
template <class RandomAccessIterator>
inline void shuffle(RandomAccessIterator begin, RandomAccessIterator end) {
shuffle(begin, end, caffe_rng());
}
} // namespace caffe
#endif // CAFFE_RNG_HPP_
|