1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Muhammad Junaid Muzammil <mjunaidmuzammil@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://kylelutz.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #define BOOST_TEST_MODULE TestThreefry
12 #include <boost/test/unit_test.hpp>
14 #include <boost/compute/random/threefry_engine.hpp>
15 #include <boost/compute/container/vector.hpp>
17 #include <boost/compute/random/uniform_real_distribution.hpp>
19 #include "check_macros.hpp"
20 #include "context_setup.hpp"
22 BOOST_AUTO_TEST_CASE(generate_uint
)
24 using boost::compute::uint_
;
26 boost::compute::threefry_engine
<> random_engine(queue
);
27 boost::compute::vector
<uint_
> random_values(19, context
);
29 random_engine
.generate(random_values
.begin(), random_values
.end(), queue
);
32 uint_
, 19, random_values
,
55 BOOST_AUTO_TEST_CASE(generate_float
)
57 using boost::compute::float_
;
59 boost::compute::threefry_engine
<> random_engine(queue
);
60 boost::compute::uniform_real_distribution
<float_
> random_distribution(0.f
, 4.f
);
62 boost::compute::vector
<float_
> random_values(1024, context
);
63 random_distribution
.generate(
64 random_values
.begin(), random_values
.end(), random_engine
, queue
67 std::vector
<float_
> random_values_host(1024);
69 random_values
.begin(), random_values
.end(),
70 random_values_host
.begin(),
76 for(size_t i
= 0; i
< random_values_host
.size(); i
++)
78 BOOST_CHECK_LT(random_values_host
[i
], 4.0f
);
79 BOOST_CHECK_GE(random_values_host
[i
], 0.0f
);
80 sum
+= random_values_host
[i
];
82 double mean
= sum
/ random_values_host
.size();
83 // For 1024 it can be 10% off
84 BOOST_CHECK_CLOSE(mean
, 2.0f
, 10.0);
87 BOOST_AUTO_TEST_SUITE_END()