1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/random/uniform_on_sphere.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,86 @@
1.4 +/* boost random/uniform_on_sphere.hpp header file
1.5 + *
1.6 + * Copyright Jens Maurer 2000-2001
1.7 + * Distributed under the Boost Software License, Version 1.0. (See
1.8 + * accompanying file LICENSE_1_0.txt or copy at
1.9 + * http://www.boost.org/LICENSE_1_0.txt)
1.10 + *
1.11 + * See http://www.boost.org for most recent version including documentation.
1.12 + *
1.13 + * $Id: uniform_on_sphere.hpp,v 1.11 2004/07/27 03:43:32 dgregor Exp $
1.14 + *
1.15 + * Revision history
1.16 + * 2001-02-18 moved to individual header files
1.17 + */
1.18 +
1.19 +#ifndef BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
1.20 +#define BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
1.21 +
1.22 +#include <vector>
1.23 +#include <algorithm> // std::transform
1.24 +#include <functional> // std::bind2nd, std::divides
1.25 +#include <boost/random/normal_distribution.hpp>
1.26 +
1.27 +namespace boost {
1.28 +
1.29 +template<class RealType = double, class Cont = std::vector<RealType> >
1.30 +class uniform_on_sphere
1.31 +{
1.32 +public:
1.33 + typedef RealType input_type;
1.34 + typedef Cont result_type;
1.35 +
1.36 + explicit uniform_on_sphere(int dim = 2) : _container(dim), _dim(dim) { }
1.37 +
1.38 + // compiler-generated copy ctor and assignment operator are fine
1.39 +
1.40 + void reset() { _normal.reset(); }
1.41 +
1.42 + template<class Engine>
1.43 + const result_type & operator()(Engine& eng)
1.44 + {
1.45 + RealType sqsum = 0;
1.46 + for(typename Cont::iterator it = _container.begin();
1.47 + it != _container.end();
1.48 + ++it) {
1.49 + RealType val = _normal(eng);
1.50 + *it = val;
1.51 + sqsum += val * val;
1.52 + }
1.53 +#ifndef BOOST_NO_STDC_NAMESPACE
1.54 + using std::sqrt;
1.55 +#endif
1.56 + // for all i: result[i] /= sqrt(sqsum)
1.57 + std::transform(_container.begin(), _container.end(), _container.begin(),
1.58 + std::bind2nd(std::divides<RealType>(), sqrt(sqsum)));
1.59 + return _container;
1.60 + }
1.61 +
1.62 +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
1.63 + template<class CharT, class Traits>
1.64 + friend std::basic_ostream<CharT,Traits>&
1.65 + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_on_sphere& sd)
1.66 + {
1.67 + os << sd._dim;
1.68 + return os;
1.69 + }
1.70 +
1.71 + template<class CharT, class Traits>
1.72 + friend std::basic_istream<CharT,Traits>&
1.73 + operator>>(std::basic_istream<CharT,Traits>& is, uniform_on_sphere& sd)
1.74 + {
1.75 + is >> std::ws >> sd._dim;
1.76 + sd._container.resize(sd._dim);
1.77 + return is;
1.78 + }
1.79 +#endif
1.80 +
1.81 +private:
1.82 + normal_distribution<RealType> _normal;
1.83 + result_type _container;
1.84 + int _dim;
1.85 +};
1.86 +
1.87 +} // namespace boost
1.88 +
1.89 +#endif // BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP