compute_algebra.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/external/compute/compute_algebra.hpp
  4. [begin_description]
  5. An algebra for Boost.Compute vectors.
  6. [end_description]
  7. Copyright 2009-2011 Karsten Ahnert
  8. Copyright 2009-2011 Mario Mulansky
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_ALGEBRA_HPP_DEFINED
  14. #define BOOST_NUMERIC_ODEINT_EXTERNAL_COMPUTE_COMPUTE_ALGEBRA_HPP_DEFINED
  15. #include <boost/preprocessor/repetition.hpp>
  16. #include <boost/compute.hpp>
  17. namespace boost {
  18. namespace numeric {
  19. namespace odeint {
  20. struct compute_algebra
  21. {
  22. #define BOOST_ODEINT_COMPUTE_STATE_PARAM(z, n, unused) \
  23. StateType ## n &s ## n,
  24. #define BOOST_ODEINT_COMPUTE_ALGEBRA(z, n, unused) \
  25. template< BOOST_PP_ENUM_PARAMS(n, class StateType), class Operation > \
  26. static void for_each ## n( \
  27. BOOST_PP_REPEAT(n, BOOST_ODEINT_COMPUTE_STATE_PARAM, ~) \
  28. Operation op \
  29. ) \
  30. { \
  31. op( BOOST_PP_ENUM_PARAMS(n, s) ); \
  32. }
  33. BOOST_PP_REPEAT_FROM_TO(3, 9, BOOST_ODEINT_COMPUTE_ALGEBRA, ~)
  34. #undef BOOST_ODEINT_COMPUTE_ALGEBRA
  35. #undef BOOST_ODEINT_COMPUTE_STATE_PARAM
  36. template < class S >
  37. static typename S::value_type norm_inf( const S &s ) {
  38. typedef typename S::value_type value_type;
  39. BOOST_COMPUTE_FUNCTION(value_type, max_abs, (value_type, value_type),
  40. {
  41. return max(_1, fabs(_2));
  42. });
  43. return boost::compute::accumulate(s.begin(), s.end(), value_type(), max_abs);
  44. }
  45. };
  46. } // odeint
  47. } // numeric
  48. } // boost
  49. #endif