comparison DEPENDENCIES/generic/include/boost/numeric/odeint/util/ublas_wrapper.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*
2 [auto_generated]
3 boost/numeric/odeint/util/ublas_wrapper.hpp
4
5 [begin_description]
6 Resizing for ublas::vector and ublas::matrix
7 [end_description]
8
9 Copyright 2009-2011 Karsten Ahnert
10 Copyright 2009-2011 Mario Mulansky
11
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
15 */
16
17
18 #ifndef BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED
19 #define BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED
20
21
22 #include <boost/type_traits/integral_constant.hpp>
23 #include <boost/numeric/ublas/vector.hpp>
24 #include <boost/numeric/ublas/matrix.hpp>
25 #include <boost/numeric/ublas/lu.hpp>
26
27 #include <boost/numeric/odeint/util/is_resizeable.hpp>
28 #include <boost/numeric/odeint/util/state_wrapper.hpp>
29
30 namespace boost {
31 namespace numeric {
32 namespace odeint {
33
34 /*
35 * resizeable specialization for boost::numeric::ublas::vector
36 */
37 template< class T , class A >
38 struct is_resizeable< boost::numeric::ublas::vector< T , A > >
39 {
40 typedef boost::true_type type;
41 const static bool value = type::value;
42 };
43
44
45 /*
46 * resizeable specialization for boost::numeric::ublas::matrix
47 */
48 template< class T , class L , class A >
49 struct is_resizeable< boost::numeric::ublas::matrix< T , L , A > >
50 {
51 typedef boost::true_type type;
52 const static bool value = type::value;
53 };
54
55
56 /*
57 * resizeable specialization for boost::numeric::ublas::permutation_matrix
58 */
59 template< class T , class A >
60 struct is_resizeable< boost::numeric::ublas::permutation_matrix< T , A > >
61 {
62 typedef boost::true_type type;
63 const static bool value = type::value;
64 };
65
66
67 // specialization for ublas::matrix
68 // same size and resize specialization for matrix-matrix resizing
69 template< class T , class L , class A , class T2 , class L2 , class A2 >
70 struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T2 , L2 , A2 > >
71 {
72 static bool same_size( const boost::numeric::ublas::matrix< T , L , A > &m1 ,
73 const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
74 {
75 return ( ( m1.size1() == m2.size1() ) && ( m1.size2() == m2.size2() ) );
76 }
77 };
78
79 template< class T , class L , class A , class T2 , class L2 , class A2 >
80 struct resize_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T2 , L2 , A2 > >
81 {
82 static void resize( boost::numeric::ublas::matrix< T , L , A > &m1 ,
83 const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
84 {
85 m1.resize( m2.size1() , m2.size2() );
86 }
87 };
88
89
90
91 // same size and resize specialization for matrix-vector resizing
92 template< class T , class L , class A , class T_V , class A_V >
93 struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::vector< T_V , A_V > >
94 {
95 static bool same_size( const boost::numeric::ublas::matrix< T , L , A > &m ,
96 const boost::numeric::ublas::vector< T_V , A_V > &v )
97 {
98 return ( ( m.size1() == v.size() ) && ( m.size2() == v.size() ) );
99 }
100 };
101
102 template< class T , class L , class A , class T_V , class A_V >
103 struct resize_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::vector< T_V , A_V > >
104 {
105 static void resize( boost::numeric::ublas::matrix< T , L , A > &m ,
106 const boost::numeric::ublas::vector< T_V , A_V > &v )
107 {
108 m.resize( v.size() , v.size() );
109 }
110 };
111
112
113
114 // specialization for ublas::permutation_matrix
115 // same size and resize specialization for matrix-vector resizing
116 template< class T , class A , class T_V , class A_V >
117 struct same_size_impl< boost::numeric::ublas::permutation_matrix< T , A > , boost::numeric::ublas::vector< T_V , A_V > >
118 {
119 static bool same_size( const boost::numeric::ublas::permutation_matrix< T , A > &m ,
120 const boost::numeric::ublas::vector< T_V , A_V > &v )
121 {
122 return ( m.size() == v.size() ); // && ( m.size2() == v.size() ) );
123 }
124 };
125
126 template< class T , class A , class T_V , class A_V >
127 struct resize_impl< boost::numeric::ublas::vector< T_V , A_V > , boost::numeric::ublas::permutation_matrix< T , A > >
128 {
129 static void resize( const boost::numeric::ublas::vector< T_V , A_V > &v,
130 boost::numeric::ublas::permutation_matrix< T , A > &m )
131 {
132 m.resize( v.size() , v.size() );
133 }
134 };
135
136
137
138
139
140
141
142 template< class T , class A >
143 struct state_wrapper< boost::numeric::ublas::permutation_matrix< T , A > > // with resizing
144 {
145 typedef boost::numeric::ublas::permutation_matrix< T , A > state_type;
146 typedef state_wrapper< state_type > state_wrapper_type;
147
148 state_type m_v;
149
150 state_wrapper() : m_v( 1 ) // permutation matrix constructor requires a size, choose 1 as default
151 { }
152
153 };
154
155
156
157
158 } } }
159
160 //// all specializations done, ready to include state_wrapper
161 //
162 //#include <boost/numeric/odeint/util/state_wrapper.hpp>
163 //
164 //namespace boost {
165 //namespace numeric {
166 //namespace odeint {
167 //
168 ///* specialization for permutation matrices wrapper because we need to change the construction */
169 //template< class T , class A >
170 //struct state_wrapper< boost::numeric::ublas::permutation_matrix< T , A > , true > // with resizing
171 //{
172 // typedef boost::numeric::ublas::permutation_matrix< T , A > state_type;
173 // typedef state_wrapper< state_type > state_wrapper_type;
174 // //typedef typename V::value_type value_type;
175 // typedef boost::true_type is_resizeable;
176 //
177 // state_type m_v;
178 //
179 // state_wrapper() : m_v( 1 ) // permutation matrix constructor requires a size, choose 1 as default
180 // { }
181 //
182 // template< class T_V , class A_V >
183 // bool same_size( const boost::numeric::ublas::vector< T_V , A_V > &x )
184 // {
185 // return boost::numeric::odeint::same_size( m_v , x );
186 // }
187 //
188 // template< class T_V , class A_V >
189 // bool resize( const boost::numeric::ublas::vector< T_V , A_V > &x )
190 // {
191 // //standard resizing done like for std::vector
192 // if( !same_size( x ) )
193 // {
194 // boost::numeric::odeint::resize( m_v , x );
195 // return true;
196 // } else
197 // return false;
198 // }
199 //};
200 //
201 //}
202 //}
203 //}
204
205
206 /*
207 * preparing ublas::matrix for boost::range, such that ublas::matrix can be used in all steppers with the range algebra
208 */
209
210 namespace boost
211 {
212 template< class T , class L , class A >
213 struct range_mutable_iterator< boost::numeric::ublas::matrix< T , L , A > >
214 {
215 typedef typename boost::numeric::ublas::matrix< T , L , A >::array_type::iterator type;
216 };
217
218 template< class T , class L , class A >
219 struct range_const_iterator< boost::numeric::ublas::matrix< T , L , A > >
220 {
221 typedef typename boost::numeric::ublas::matrix< T , L , A >::array_type::const_iterator type;
222 };
223
224 } // namespace boost
225
226
227 namespace boost { namespace numeric { namespace ublas {
228
229 template< class T , class L , class A >
230 inline typename matrix< T , L , A >::array_type::iterator
231 range_begin( matrix< T , L , A > &x )
232 {
233 return x.data().begin();
234 }
235
236 template< class T , class L , class A >
237 inline typename matrix< T , L , A >::array_type::const_iterator
238 range_begin( const matrix< T , L , A > &x )
239 {
240 return x.data().begin();
241 }
242
243 template< class T , class L , class A >
244 inline typename matrix< T , L , A >::array_type::iterator
245 range_end( matrix< T , L , A > &x )
246 {
247 return x.data().end();
248 }
249
250 template< class T , class L , class A >
251 inline typename matrix< T , L , A >::array_type::const_iterator
252 range_end( const matrix< T , L , A > &x )
253 {
254 return x.data().end();
255 }
256
257 } } } // namespace boost::numeric::ublas
258
259
260 #endif // BOOST_NUMERIC_ODEINT_UTIL_UBLAS_WRAPPER_HPP_INCLUDED