File indexing completed on 2025-01-18 09:42:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED
0019 #define BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED
0020
0021
0022 #include <boost/type_traits/integral_constant.hpp>
0023 #include <boost/numeric/ublas/vector.hpp>
0024 #include <boost/numeric/ublas/matrix.hpp>
0025 #include <boost/numeric/ublas/lu.hpp>
0026 #include <boost/numeric/ublas/vector_expression.hpp>
0027 #include <boost/numeric/ublas/matrix_expression.hpp>
0028
0029 #include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
0030 #include <boost/numeric/odeint/algebra/default_operations.hpp>
0031
0032 #include <boost/numeric/odeint/util/is_resizeable.hpp>
0033 #include <boost/numeric/odeint/util/state_wrapper.hpp>
0034
0035
0036
0037
0038
0039 namespace boost { namespace numeric { namespace odeint {
0040
0041 template< typename T , typename A >
0042 struct vector_space_norm_inf< boost::numeric::ublas::vector<T,A> >
0043 {
0044 typedef T result_type;
0045
0046 result_type operator()( const boost::numeric::ublas::vector<T,A> &x ) const
0047 {
0048 return boost::numeric::ublas::norm_inf( x );
0049 }
0050 };
0051
0052
0053 template< class T , class L , class A >
0054 struct vector_space_norm_inf< boost::numeric::ublas::matrix<T,L,A> >
0055 {
0056 typedef T result_type;
0057
0058 result_type operator()( const boost::numeric::ublas::matrix<T,L,A> &x ) const
0059 {
0060 return boost::numeric::ublas::norm_inf( x );
0061 }
0062 };
0063 } } }
0064
0065
0066
0067
0068
0069
0070 namespace boost { namespace numeric { namespace ublas {
0071
0072
0073
0074 template<class T>
0075 struct scalar_abs: public scalar_unary_functor<T> {
0076 typedef typename scalar_unary_functor<T>::value_type value_type;
0077 typedef typename scalar_unary_functor<T>::argument_type argument_type;
0078 typedef typename scalar_unary_functor<T>::result_type result_type;
0079
0080 static BOOST_UBLAS_INLINE
0081 result_type apply (argument_type t) {
0082 using std::abs;
0083 return abs (t);
0084 }
0085 };
0086
0087
0088
0089 template<class E>
0090 BOOST_UBLAS_INLINE
0091 typename vector_unary_traits<E, scalar_abs<typename E::value_type> >::result_type
0092 abs (const vector_expression<E> &e) {
0093 typedef typename vector_unary_traits<E, scalar_abs<typename E::value_type> >::expression_type expression_type;
0094 return expression_type (e ());
0095 }
0096
0097
0098 template<class E>
0099 BOOST_UBLAS_INLINE
0100 typename matrix_unary1_traits<E, scalar_abs<typename E::value_type> >::result_type
0101 abs (const matrix_expression<E> &e) {
0102 typedef typename matrix_unary1_traits<E, scalar_abs<typename E::value_type> >::expression_type expression_type;
0103 return expression_type (e ());
0104 }
0105
0106
0107
0108 template<class E1, class E2>
0109 BOOST_UBLAS_INLINE
0110 typename vector_binary_traits<E1, E2, scalar_divides<typename E1::value_type,
0111 typename E2::value_type> >::result_type
0112 operator / (const vector_expression<E1> &e1,
0113 const vector_expression<E2> &e2) {
0114 typedef typename vector_binary_traits<E1, E2, scalar_divides<typename E1::value_type,
0115 typename E2::value_type> >::expression_type expression_type;
0116 return expression_type (e1 (), e2 ());
0117 }
0118
0119
0120
0121 template<class E1, class E2>
0122 BOOST_UBLAS_INLINE
0123 typename matrix_binary_traits<E1, E2, scalar_divides<typename E1::value_type,
0124 typename E2::value_type> >::result_type
0125 operator / (const matrix_expression<E1> &e1,
0126 const matrix_expression<E2> &e2) {
0127 typedef typename matrix_binary_traits<E1, E2, scalar_divides<typename E1::value_type,
0128 typename E2::value_type> >::expression_type expression_type;
0129 return expression_type (e1 (), e2 ());
0130 }
0131
0132
0133
0134 template<class T1, class E2>
0135 BOOST_UBLAS_INLINE
0136 typename enable_if< is_convertible<T1, typename E2::value_type >,
0137 typename vector_binary_scalar1_traits<const T1, E2, scalar_plus<T1, typename E2::value_type> >::result_type
0138 >::type
0139 operator + (const T1 &e1,
0140 const vector_expression<E2> &e2) {
0141 typedef typename vector_binary_scalar1_traits<const T1, E2, scalar_plus<T1, typename E2::value_type> >::expression_type expression_type;
0142 return expression_type (e1, e2 ());
0143 }
0144
0145
0146
0147 template<class T1, class E2>
0148 BOOST_UBLAS_INLINE
0149 typename enable_if< is_convertible<T1, typename E2::value_type >,
0150 typename matrix_binary_scalar1_traits<const T1, E2, scalar_plus<T1, typename E2::value_type> >::result_type
0151 >::type
0152 operator + (const T1 &e1,
0153 const matrix_expression<E2> &e2) {
0154 typedef typename matrix_binary_scalar1_traits<const T1, E2, scalar_plus<T1, typename E2::value_type> >::expression_type expression_type;
0155 return expression_type (e1, e2 ());
0156 }
0157
0158 } } }
0159
0160
0161
0162
0163
0164 namespace boost {
0165 namespace numeric {
0166 namespace odeint {
0167
0168
0169
0170
0171 template< class T , class A >
0172 struct is_resizeable< boost::numeric::ublas::vector< T , A > >
0173 {
0174 typedef boost::true_type type;
0175 const static bool value = type::value;
0176 };
0177
0178
0179
0180
0181
0182 template< class T , class L , class A >
0183 struct is_resizeable< boost::numeric::ublas::matrix< T , L , A > >
0184 {
0185 typedef boost::true_type type;
0186 const static bool value = type::value;
0187 };
0188
0189
0190
0191
0192
0193 template< class T , class A >
0194 struct is_resizeable< boost::numeric::ublas::permutation_matrix< T , A > >
0195 {
0196 typedef boost::true_type type;
0197 const static bool value = type::value;
0198 };
0199
0200
0201
0202
0203 template< class T , class L , class A , class T2 , class L2 , class A2 >
0204 struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T2 , L2 , A2 > >
0205 {
0206 static bool same_size( const boost::numeric::ublas::matrix< T , L , A > &m1 ,
0207 const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
0208 {
0209 return ( ( m1.size1() == m2.size1() ) && ( m1.size2() == m2.size2() ) );
0210 }
0211 };
0212
0213 template< class T , class L , class A , class T2 , class L2 , class A2 >
0214 struct resize_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T2 , L2 , A2 > >
0215 {
0216 static void resize( boost::numeric::ublas::matrix< T , L , A > &m1 ,
0217 const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
0218 {
0219 m1.resize( m2.size1() , m2.size2() );
0220 }
0221 };
0222
0223
0224
0225
0226 template< class T , class L , class A , class T_V , class A_V >
0227 struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::vector< T_V , A_V > >
0228 {
0229 static bool same_size( const boost::numeric::ublas::matrix< T , L , A > &m ,
0230 const boost::numeric::ublas::vector< T_V , A_V > &v )
0231 {
0232 return ( ( m.size1() == v.size() ) && ( m.size2() == v.size() ) );
0233 }
0234 };
0235
0236 template< class T , class L , class A , class T_V , class A_V >
0237 struct resize_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::vector< T_V , A_V > >
0238 {
0239 static void resize( boost::numeric::ublas::matrix< T , L , A > &m ,
0240 const boost::numeric::ublas::vector< T_V , A_V > &v )
0241 {
0242 m.resize( v.size() , v.size() );
0243 }
0244 };
0245
0246
0247
0248
0249
0250 template< class T , class A , class T_V , class A_V >
0251 struct same_size_impl< boost::numeric::ublas::permutation_matrix< T , A > ,
0252 boost::numeric::ublas::vector< T_V , A_V > >
0253 {
0254 static bool same_size( const boost::numeric::ublas::permutation_matrix< T , A > &m ,
0255 const boost::numeric::ublas::vector< T_V , A_V > &v )
0256 {
0257 return ( m.size() == v.size() );
0258 }
0259 };
0260
0261 template< class T , class A , class T_V , class A_V >
0262 struct resize_impl< boost::numeric::ublas::vector< T_V , A_V > ,
0263 boost::numeric::ublas::permutation_matrix< T , A > >
0264 {
0265 static void resize( const boost::numeric::ublas::vector< T_V , A_V > &v,
0266 boost::numeric::ublas::permutation_matrix< T , A > &m )
0267 {
0268 m.resize( v.size() , v.size() );
0269 }
0270 };
0271
0272
0273
0274
0275
0276
0277
0278 template< class T , class A >
0279 struct state_wrapper< boost::numeric::ublas::permutation_matrix< T , A > >
0280 {
0281 typedef boost::numeric::ublas::permutation_matrix< T , A > state_type;
0282 typedef state_wrapper< state_type > state_wrapper_type;
0283
0284 state_type m_v;
0285
0286 state_wrapper() : m_v( 1 )
0287 { }
0288
0289 };
0290
0291
0292
0293
0294 } } }
0295
0296
0297 #endif