#pragma once #include #include #include #include namespace unittest { inline unsigned int hash(unsigned int a) { a = (a+0x7ed55d16) + (a<<12); a = (a^0xc761c23c) ^ (a>>19); a = (a+0x165667b1) + (a<<5); a = (a+0xd3a2646c) ^ (a<<9); a = (a+0xfd7046c5) + (a<<3); a = (a^0xb55a4f09) ^ (a>>16); return a; } template struct generate_random_integer; template struct generate_random_integer::value >::type > { T operator()(unsigned int i) const { THRUST_NS_QUALIFIER::default_random_engine rng(hash(i)); return static_cast(rng()); } }; template struct generate_random_integer::value >::type > { T operator()(unsigned int i) const { THRUST_NS_QUALIFIER::default_random_engine rng(hash(i)); THRUST_NS_QUALIFIER::uniform_int_distribution dist; return static_cast(dist(rng)); } }; template struct generate_random_integer::value >::type > { T operator()(unsigned int i) const { T const min = std::numeric_limits::min(); T const max = std::numeric_limits::max(); THRUST_NS_QUALIFIER::default_random_engine rng(hash(i)); THRUST_NS_QUALIFIER::uniform_real_distribution dist(min, max); return static_cast(dist(rng)); } }; template<> struct generate_random_integer { bool operator()(unsigned int i) const { THRUST_NS_QUALIFIER::default_random_engine rng(hash(i)); THRUST_NS_QUALIFIER::uniform_int_distribution dist(0,1); return dist(rng) == 1; } }; template struct generate_random_sample { T operator()(unsigned int i) const { THRUST_NS_QUALIFIER::default_random_engine rng(hash(i)); THRUST_NS_QUALIFIER::uniform_int_distribution dist(0,20); return static_cast(dist(rng)); } }; template THRUST_NS_QUALIFIER::host_vector random_integers(const size_t N) { THRUST_NS_QUALIFIER::host_vector vec(N); THRUST_NS_QUALIFIER::transform(THRUST_NS_QUALIFIER::counting_iterator(static_cast(0)), THRUST_NS_QUALIFIER::counting_iterator(static_cast(N)), vec.begin(), generate_random_integer()); return vec; } template T random_integer() { return generate_random_integer()(0); } template THRUST_NS_QUALIFIER::host_vector random_samples(const size_t N) { THRUST_NS_QUALIFIER::host_vector vec(N); THRUST_NS_QUALIFIER::transform(THRUST_NS_QUALIFIER::counting_iterator(static_cast(0)), THRUST_NS_QUALIFIER::counting_iterator(static_cast(N)), vec.begin(), generate_random_sample()); return vec; } }; //end namespace unittest