test_uniform_on_sphere.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* test_uniform_on_sphere.cpp
  2. *
  3. * Copyright Steven Watanabe 2011
  4. * Distributed under the Boost Software License, Version 1.0. (See
  5. * accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * $Id$
  9. *
  10. */
  11. #include <boost/random/uniform_on_sphere.hpp>
  12. #include <boost/random/uniform_int.hpp>
  13. #include <boost/math/distributions/uniform.hpp>
  14. #include <cmath>
  15. class uniform_on_sphere_test {
  16. public:
  17. typedef double result_type;
  18. uniform_on_sphere_test(int dims, int x, int y)
  19. : impl(dims), idx1(x), idx2(y) {}
  20. template<class Engine>
  21. result_type operator()(Engine& rng) {
  22. const boost::random::uniform_on_sphere<>::result_type& tmp = impl(rng);
  23. // This should be uniformly distributed in [-pi,pi)
  24. return std::atan2(tmp[idx1], tmp[idx2]);
  25. }
  26. private:
  27. boost::random::uniform_on_sphere<> impl;
  28. int idx1, idx2;
  29. };
  30. static const double pi = 3.14159265358979323846;
  31. #define BOOST_RANDOM_DISTRIBUTION uniform_on_sphere_test
  32. #define BOOST_RANDOM_DISTRIBUTION_NAME uniform_on_sphere
  33. #define BOOST_MATH_DISTRIBUTION boost::math::uniform
  34. #define BOOST_RANDOM_ARG1_TYPE double
  35. #define BOOST_RANDOM_ARG1_NAME n
  36. #define BOOST_RANDOM_ARG1_DEFAULT 6
  37. #define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_int<>(2, n)
  38. #define BOOST_RANDOM_DISTRIBUTION_INIT (n, 0, n-1)
  39. #define BOOST_MATH_DISTRIBUTION_INIT (-pi, pi)
  40. #include "test_real_distribution.ipp"