diff options
author | Arnur Nigmetov <nigmetov@tugraz.at> | 2020-03-09 16:43:07 +0100 |
---|---|---|
committer | Arnur Nigmetov <nigmetov@tugraz.at> | 2020-03-09 16:43:07 +0100 |
commit | ca4222ab40f1c6c0d17fb7d43539aa675f640976 (patch) | |
tree | e2a91037ac1d9e8895eafbab54c1c11f0b257c85 /bottleneck/include/dnn/utils.h | |
parent | 7fb44351b487c64f23066a428089ef14a95b4176 (diff) | |
parent | 14e91d6c3ad81a1ec763d75a28f20fb689e5166e (diff) |
Merge README
Diffstat (limited to 'bottleneck/include/dnn/utils.h')
-rw-r--r-- | bottleneck/include/dnn/utils.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bottleneck/include/dnn/utils.h b/bottleneck/include/dnn/utils.h new file mode 100644 index 0000000..f4ce632 --- /dev/null +++ b/bottleneck/include/dnn/utils.h @@ -0,0 +1,47 @@ +#ifndef HERA_BT_DNN_UTILS_H +#define HERA_BT_DNN_UTILS_H + +#include <boost/random/uniform_int.hpp> +#include <boost/foreach.hpp> +#include <boost/typeof/typeof.hpp> + +namespace hera +{ +namespace bt +{ +namespace dnn +{ + +template <typename T, typename... Args> +struct has_coordinates +{ + template <typename C, typename = decltype( std::declval<C>().coordinate(std::declval<Args>()...) )> + static std::true_type test(int); + + template <typename C> + static std::false_type test(...); + + static constexpr bool value = decltype(test<T>(0))::value; +}; + +template<class RandomIt, class UniformRandomNumberGenerator, class SwapFunctor> +void random_shuffle(RandomIt first, RandomIt last, UniformRandomNumberGenerator& g, const SwapFunctor& swap) +{ + size_t n = last - first; + boost::uniform_int<size_t> uniform(0,n); + for (size_t i = n-1; i > 0; --i) + swap(first[i], first[uniform(g,i+1)]); // picks a random number in [0,i] range +} + +template<class RandomIt, class UniformRandomNumberGenerator> +void random_shuffle(RandomIt first, RandomIt last, UniformRandomNumberGenerator& g) +{ + typedef decltype(*first) T; + random_shuffle(first, last, g, [](T& x, T& y) { std::swap(x,y); }); +} + +} // dnn +} // bt +} // hera + +#endif |