array_algebra.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/algebra/array_algebra.hpp
  4. [begin_description]
  5. Algebra for Arrays. Highly specialized for odeint. Const arguments are
  6. introduce to work with odeint.
  7. The Array algebra can be used for Array structures with two template
  8. parameters:
  9. Array<T, N>
  10. [end_description]
  11. Copyright 2011-2013 Mario Mulansky
  12. Copyright 2011-2012 Karsten Ahnert
  13. Distributed under the Boost Software License, Version 1.0.
  14. (See accompanying file LICENSE_1_0.txt or
  15. copy at http://www.boost.org/LICENSE_1_0.txt)
  16. */
  17. #ifndef BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
  18. #define BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED
  19. #include <algorithm>
  20. #include <boost/array.hpp>
  21. #include <boost/numeric/odeint/algebra/norm_result_type.hpp>
  22. namespace boost {
  23. namespace numeric {
  24. namespace odeint {
  25. struct array_algebra
  26. {
  27. //template< typename T , size_t dim , class Op >
  28. template < template < typename, size_t > class Array, typename T,
  29. size_t dim, class Op >
  30. static void for_each1( Array< T, dim > &s1, Op op )
  31. {
  32. for( size_t i=0 ; i<dim ; ++i )
  33. op( s1[i] );
  34. }
  35. template < template < typename, size_t > class Array, typename T,
  36. size_t dim, class Op >
  37. static void for_each2( Array< T, dim > &s1, const Array< T, dim > &s2,
  38. Op op )
  39. {
  40. for( size_t i=0 ; i<dim ; ++i )
  41. op( s1[i] , s2[i] );
  42. }
  43. template < template < typename, size_t > class Array, typename T,
  44. size_t dim, class Op >
  45. static void for_each3( Array< T , dim > &s1 ,
  46. const Array< T , dim > &s2 ,
  47. const Array< T , dim > &s3 , Op op )
  48. {
  49. for( size_t i=0 ; i<dim ; ++i )
  50. op( s1[i] , s2[i] , s3[i] );
  51. }
  52. /* different const signature - required for the scale_sum_swap2 operation */
  53. template < template < typename, size_t > class Array, typename T,
  54. size_t dim, class Op >
  55. static void for_each3( Array< T , dim > &s1 ,
  56. Array< T , dim > &s2 ,
  57. const Array< T , dim > &s3 , Op op )
  58. {
  59. for( size_t i=0 ; i<dim ; ++i )
  60. op( s1[i] , s2[i] , s3[i] );
  61. }
  62. template < template < typename, size_t > class Array, typename T,
  63. size_t dim, class Op >
  64. static void for_each4( Array< T , dim > &s1 ,
  65. const Array< T , dim > &s2 ,
  66. const Array< T , dim > &s3 ,
  67. const Array< T , dim > &s4 , Op op )
  68. {
  69. for( size_t i=0 ; i<dim ; ++i )
  70. op( s1[i] , s2[i] , s3[i] , s4[i] );
  71. }
  72. template < template < typename, size_t > class Array, typename T,
  73. size_t dim, class Op >
  74. static void for_each5( Array< T , dim > &s1 ,
  75. const Array< T , dim > &s2 ,
  76. const Array< T , dim > &s3 ,
  77. const Array< T , dim > &s4 ,
  78. const Array< T , dim > &s5 , Op op )
  79. {
  80. for( size_t i=0 ; i<dim ; ++i )
  81. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] );
  82. }
  83. template < template < typename, size_t > class Array, typename T,
  84. size_t dim, class Op >
  85. static void for_each6( Array< T , dim > &s1 ,
  86. const Array< T , dim > &s2 ,
  87. const Array< T , dim > &s3 ,
  88. const Array< T , dim > &s4 ,
  89. const Array< T , dim > &s5 ,
  90. const Array< T , dim > &s6 , Op op )
  91. {
  92. for( size_t i=0 ; i<dim ; ++i )
  93. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] );
  94. }
  95. template < template < typename, size_t > class Array, typename T,
  96. size_t dim, class Op >
  97. static void for_each7( Array< T , dim > &s1 ,
  98. const Array< T , dim > &s2 ,
  99. const Array< T , dim > &s3 ,
  100. const Array< T , dim > &s4 ,
  101. const Array< T , dim > &s5 ,
  102. const Array< T , dim > &s6 ,
  103. const Array< T , dim > &s7 , Op op )
  104. {
  105. for( size_t i=0 ; i<dim ; ++i )
  106. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] );
  107. }
  108. template < template < typename, size_t > class Array, typename T,
  109. size_t dim, class Op >
  110. static void for_each8( Array< T , dim > &s1 ,
  111. const Array< T , dim > &s2 ,
  112. const Array< T , dim > &s3 ,
  113. const Array< T , dim > &s4 ,
  114. const Array< T , dim > &s5 ,
  115. const Array< T , dim > &s6 ,
  116. const Array< T , dim > &s7 ,
  117. const Array< T , dim > &s8 , Op op )
  118. {
  119. for( size_t i=0 ; i<dim ; ++i )
  120. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] );
  121. }
  122. template < template < typename, size_t > class Array, typename T,
  123. size_t dim, class Op >
  124. static void for_each9( Array< T , dim > &s1 ,
  125. const Array< T , dim > &s2 ,
  126. const Array< T , dim > &s3 ,
  127. const Array< T , dim > &s4 ,
  128. const Array< T , dim > &s5 ,
  129. const Array< T , dim > &s6 ,
  130. const Array< T , dim > &s7 ,
  131. const Array< T , dim > &s8 ,
  132. const Array< T , dim > &s9 , Op op )
  133. {
  134. for( size_t i=0 ; i<dim ; ++i )
  135. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] );
  136. }
  137. template < template < typename, size_t > class Array, typename T,
  138. size_t dim, class Op >
  139. static void for_each10( Array< T , dim > &s1 ,
  140. const Array< T , dim > &s2 ,
  141. const Array< T , dim > &s3 ,
  142. const Array< T , dim > &s4 ,
  143. const Array< T , dim > &s5 ,
  144. const Array< T , dim > &s6 ,
  145. const Array< T , dim > &s7 ,
  146. const Array< T , dim > &s8 ,
  147. const Array< T , dim > &s9 ,
  148. const Array< T , dim > &s10 , Op op )
  149. {
  150. for( size_t i=0 ; i<dim ; ++i )
  151. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] );
  152. }
  153. template < template < typename, size_t > class Array, typename T,
  154. size_t dim, class Op >
  155. static void for_each11( Array< T , dim > &s1 ,
  156. const Array< T , dim > &s2 ,
  157. const Array< T , dim > &s3 ,
  158. const Array< T , dim > &s4 ,
  159. const Array< T , dim > &s5 ,
  160. const Array< T , dim > &s6 ,
  161. const Array< T , dim > &s7 ,
  162. const Array< T , dim > &s8 ,
  163. const Array< T , dim > &s9 ,
  164. const Array< T , dim > &s10 ,
  165. const Array< T , dim > &s11 , Op op )
  166. {
  167. for( size_t i=0 ; i<dim ; ++i )
  168. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] );
  169. }
  170. template < template < typename, size_t > class Array, typename T,
  171. size_t dim, class Op >
  172. static void for_each12( Array< T , dim > &s1 ,
  173. const Array< T , dim > &s2 ,
  174. const Array< T , dim > &s3 ,
  175. const Array< T , dim > &s4 ,
  176. const Array< T , dim > &s5 ,
  177. const Array< T , dim > &s6 ,
  178. const Array< T , dim > &s7 ,
  179. const Array< T , dim > &s8 ,
  180. const Array< T , dim > &s9 ,
  181. const Array< T , dim > &s10 ,
  182. const Array< T , dim > &s11 ,
  183. const Array< T , dim > &s12 , Op op )
  184. {
  185. for( size_t i=0 ; i<dim ; ++i )
  186. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] );
  187. }
  188. template < template < typename, size_t > class Array, typename T,
  189. size_t dim, class Op >
  190. static void for_each13( Array< T , dim > &s1 ,
  191. const Array< T , dim > &s2 ,
  192. const Array< T , dim > &s3 ,
  193. const Array< T , dim > &s4 ,
  194. const Array< T , dim > &s5 ,
  195. const Array< T , dim > &s6 ,
  196. const Array< T , dim > &s7 ,
  197. const Array< T , dim > &s8 ,
  198. const Array< T , dim > &s9 ,
  199. const Array< T , dim > &s10 ,
  200. const Array< T , dim > &s11 ,
  201. const Array< T , dim > &s12 ,
  202. const Array< T , dim > &s13 , Op op )
  203. {
  204. for( size_t i=0 ; i<dim ; ++i )
  205. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] );
  206. }
  207. template < template < typename, size_t > class Array, typename T,
  208. size_t dim, class Op >
  209. static void for_each14( Array< T , dim > &s1 ,
  210. const Array< T , dim > &s2 ,
  211. const Array< T , dim > &s3 ,
  212. const Array< T , dim > &s4 ,
  213. const Array< T , dim > &s5 ,
  214. const Array< T , dim > &s6 ,
  215. const Array< T , dim > &s7 ,
  216. const Array< T , dim > &s8 ,
  217. const Array< T , dim > &s9 ,
  218. const Array< T , dim > &s10 ,
  219. const Array< T , dim > &s11 ,
  220. const Array< T , dim > &s12 ,
  221. const Array< T , dim > &s13 ,
  222. const Array< T , dim > &s14 , Op op )
  223. {
  224. for( size_t i=0 ; i<dim ; ++i )
  225. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] , s14[i] );
  226. }
  227. template < template < typename, size_t > class Array, typename T,
  228. size_t dim, class Op >
  229. static void for_each15( Array< T , dim > &s1 ,
  230. const Array< T , dim > &s2 ,
  231. const Array< T , dim > &s3 ,
  232. const Array< T , dim > &s4 ,
  233. const Array< T , dim > &s5 ,
  234. const Array< T , dim > &s6 ,
  235. const Array< T , dim > &s7 ,
  236. const Array< T , dim > &s8 ,
  237. const Array< T , dim > &s9 ,
  238. const Array< T , dim > &s10 ,
  239. const Array< T , dim > &s11 ,
  240. const Array< T , dim > &s12 ,
  241. const Array< T , dim > &s13 ,
  242. const Array< T , dim > &s14 ,
  243. const Array< T , dim > &s15 , Op op )
  244. {
  245. for( size_t i=0 ; i<dim ; ++i )
  246. op( s1[i] , s2[i] , s3[i] , s4[i] , s5[i] , s6[i] , s7[i] , s8[i] , s9[i] , s10[i] , s11[i] , s12[i] , s13[i] , s14[i] , s15[i] );
  247. }
  248. template < template < typename, size_t > class Array, typename T,
  249. size_t dim>
  250. static typename norm_result_type< Array< T , dim > >::type norm_inf( const Array< T , dim > &s )
  251. {
  252. BOOST_USING_STD_MAX();
  253. using std::abs;
  254. typedef typename norm_result_type< Array< T , dim > >::type result_type;
  255. result_type init = static_cast< result_type >( 0 );
  256. for( size_t i=0 ; i<dim ; ++i )
  257. init = max BOOST_PREVENT_MACRO_SUBSTITUTION ( init , static_cast< result_type >(abs(s[i])) );
  258. return init;
  259. }
  260. };
  261. }
  262. }
  263. }
  264. #endif // BOOST_NUMERIC_ODEINT_ALGEBRA_ARRAY_ALGEBRA_HPP_INCLUDED