ublas_wrapper.hpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/util/ublas_wrapper.hpp
  4. [begin_description]
  5. Resizing for ublas::vector and ublas::matrix
  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_UTIL_UBLAS_WRAPPER_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED
  15. #include <boost/type_traits/integral_constant.hpp>
  16. #include <boost/numeric/ublas/vector.hpp>
  17. #include <boost/numeric/ublas/matrix.hpp>
  18. #include <boost/numeric/ublas/lu.hpp>
  19. #include <boost/numeric/odeint/util/is_resizeable.hpp>
  20. #include <boost/numeric/odeint/util/state_wrapper.hpp>
  21. namespace boost {
  22. namespace numeric {
  23. namespace odeint {
  24. /*
  25. * resizeable specialization for boost::numeric::ublas::vector
  26. */
  27. template< class T , class A >
  28. struct is_resizeable< boost::numeric::ublas::vector< T , A > >
  29. {
  30. typedef boost::true_type type;
  31. const static bool value = type::value;
  32. };
  33. /*
  34. * resizeable specialization for boost::numeric::ublas::matrix
  35. */
  36. template< class T , class L , class A >
  37. struct is_resizeable< boost::numeric::ublas::matrix< T , L , A > >
  38. {
  39. typedef boost::true_type type;
  40. const static bool value = type::value;
  41. };
  42. /*
  43. * resizeable specialization for boost::numeric::ublas::permutation_matrix
  44. */
  45. template< class T , class A >
  46. struct is_resizeable< boost::numeric::ublas::permutation_matrix< T , A > >
  47. {
  48. typedef boost::true_type type;
  49. const static bool value = type::value;
  50. };
  51. // specialization for ublas::matrix
  52. // same size and resize specialization for matrix-matrix resizing
  53. template< class T , class L , class A , class T2 , class L2 , class A2 >
  54. struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T2 , L2 , A2 > >
  55. {
  56. static bool same_size( const boost::numeric::ublas::matrix< T , L , A > &m1 ,
  57. const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
  58. {
  59. return ( ( m1.size1() == m2.size1() ) && ( m1.size2() == m2.size2() ) );
  60. }
  61. };
  62. template< class T , class L , class A , class T2 , class L2 , class A2 >
  63. struct resize_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T2 , L2 , A2 > >
  64. {
  65. static void resize( boost::numeric::ublas::matrix< T , L , A > &m1 ,
  66. const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
  67. {
  68. m1.resize( m2.size1() , m2.size2() );
  69. }
  70. };
  71. // same size and resize specialization for matrix-vector resizing
  72. template< class T , class L , class A , class T_V , class A_V >
  73. struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::vector< T_V , A_V > >
  74. {
  75. static bool same_size( const boost::numeric::ublas::matrix< T , L , A > &m ,
  76. const boost::numeric::ublas::vector< T_V , A_V > &v )
  77. {
  78. return ( ( m.size1() == v.size() ) && ( m.size2() == v.size() ) );
  79. }
  80. };
  81. template< class T , class L , class A , class T_V , class A_V >
  82. struct resize_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::vector< T_V , A_V > >
  83. {
  84. static void resize( boost::numeric::ublas::matrix< T , L , A > &m ,
  85. const boost::numeric::ublas::vector< T_V , A_V > &v )
  86. {
  87. m.resize( v.size() , v.size() );
  88. }
  89. };
  90. // specialization for ublas::permutation_matrix
  91. // same size and resize specialization for matrix-vector resizing
  92. template< class T , class A , class T_V , class A_V >
  93. struct same_size_impl< boost::numeric::ublas::permutation_matrix< T , A > , boost::numeric::ublas::vector< T_V , A_V > >
  94. {
  95. static bool same_size( const boost::numeric::ublas::permutation_matrix< T , A > &m ,
  96. const boost::numeric::ublas::vector< T_V , A_V > &v )
  97. {
  98. return ( m.size() == v.size() ); // && ( m.size2() == v.size() ) );
  99. }
  100. };
  101. template< class T , class A , class T_V , class A_V >
  102. struct resize_impl< boost::numeric::ublas::vector< T_V , A_V > , boost::numeric::ublas::permutation_matrix< T , A > >
  103. {
  104. static void resize( const boost::numeric::ublas::vector< T_V , A_V > &v,
  105. boost::numeric::ublas::permutation_matrix< T , A > &m )
  106. {
  107. m.resize( v.size() , v.size() );
  108. }
  109. };
  110. template< class T , class A >
  111. struct state_wrapper< boost::numeric::ublas::permutation_matrix< T , A > > // with resizing
  112. {
  113. typedef boost::numeric::ublas::permutation_matrix< T , A > state_type;
  114. typedef state_wrapper< state_type > state_wrapper_type;
  115. state_type m_v;
  116. state_wrapper() : m_v( 1 ) // permutation matrix constructor requires a size, choose 1 as default
  117. { }
  118. };
  119. } } }
  120. //// all specializations done, ready to include state_wrapper
  121. //
  122. //#include <boost/numeric/odeint/util/state_wrapper.hpp>
  123. //
  124. //namespace boost {
  125. //namespace numeric {
  126. //namespace odeint {
  127. //
  128. ///* specialization for permutation matrices wrapper because we need to change the construction */
  129. //template< class T , class A >
  130. //struct state_wrapper< boost::numeric::ublas::permutation_matrix< T , A > , true > // with resizing
  131. //{
  132. // typedef boost::numeric::ublas::permutation_matrix< T , A > state_type;
  133. // typedef state_wrapper< state_type > state_wrapper_type;
  134. // //typedef typename V::value_type value_type;
  135. // typedef boost::true_type is_resizeable;
  136. //
  137. // state_type m_v;
  138. //
  139. // state_wrapper() : m_v( 1 ) // permutation matrix constructor requires a size, choose 1 as default
  140. // { }
  141. //
  142. // template< class T_V , class A_V >
  143. // bool same_size( const boost::numeric::ublas::vector< T_V , A_V > &x )
  144. // {
  145. // return boost::numeric::odeint::same_size( m_v , x );
  146. // }
  147. //
  148. // template< class T_V , class A_V >
  149. // bool resize( const boost::numeric::ublas::vector< T_V , A_V > &x )
  150. // {
  151. // //standard resizing done like for std::vector
  152. // if( !same_size( x ) )
  153. // {
  154. // boost::numeric::odeint::resize( m_v , x );
  155. // return true;
  156. // } else
  157. // return false;
  158. // }
  159. //};
  160. //
  161. //}
  162. //}
  163. //}
  164. /*
  165. * preparing ublas::matrix for boost::range, such that ublas::matrix can be used in all steppers with the range algebra
  166. */
  167. namespace boost
  168. {
  169. template< class T , class L , class A >
  170. struct range_mutable_iterator< boost::numeric::ublas::matrix< T , L , A > >
  171. {
  172. typedef typename boost::numeric::ublas::matrix< T , L , A >::array_type::iterator type;
  173. };
  174. template< class T , class L , class A >
  175. struct range_const_iterator< boost::numeric::ublas::matrix< T , L , A > >
  176. {
  177. typedef typename boost::numeric::ublas::matrix< T , L , A >::array_type::const_iterator type;
  178. };
  179. } // namespace boost
  180. namespace boost { namespace numeric { namespace ublas {
  181. template< class T , class L , class A >
  182. inline typename matrix< T , L , A >::array_type::iterator
  183. range_begin( matrix< T , L , A > &x )
  184. {
  185. return x.data().begin();
  186. }
  187. template< class T , class L , class A >
  188. inline typename matrix< T , L , A >::array_type::const_iterator
  189. range_begin( const matrix< T , L , A > &x )
  190. {
  191. return x.data().begin();
  192. }
  193. template< class T , class L , class A >
  194. inline typename matrix< T , L , A >::array_type::iterator
  195. range_end( matrix< T , L , A > &x )
  196. {
  197. return x.data().end();
  198. }
  199. template< class T , class L , class A >
  200. inline typename matrix< T , L , A >::array_type::const_iterator
  201. range_end( const matrix< T , L , A > &x )
  202. {
  203. return x.data().end();
  204. }
  205. } } } // namespace boost::numeric::ublas
  206. #endif // BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED