00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef BOOST_NUMERIC_BINDINGS_TRAITS_MATRIX_RAW_HPP
00011 #define BOOST_NUMERIC_BINDINGS_TRAITS_MATRIX_RAW_HPP
00012
00013 #include <cstddef>
00014 #include <boost/numeric/ublas/config.hpp>
00015 #ifndef BOOST_UBLAS_HAVE_BINDINGS
00016 # include <boost/numeric/ublas/matrix.hpp>
00017 #endif
00018
00019 namespace boost { namespace numeric { namespace bindings { namespace traits {
00020
00021 namespace ublas = boost::numeric::ublas;
00022
00023
00024
00025 template <typename M>
00026 BOOST_UBLAS_INLINE
00027 int matrix_size1 (const M &m) {
00028 return (int) m.size1();
00029 }
00030 template <typename M>
00031 BOOST_UBLAS_INLINE
00032 int matrix_size2 (const M &m) {
00033 return (int) m.size2();
00034 }
00035
00036 #if 0
00037
00038 template <typename M>
00039 BOOST_UBLAS_INLINE
00040 int matrix_size1 (const ublas::matrix_reference<M> &m) {
00041 return matrix_size1 (m.expression());
00042 }
00043 template <typename M>
00044 BOOST_UBLAS_INLINE
00045 int matrix_size2 (const ublas::matrix_reference<M> &m) {
00046 return matrix_size2 (m.expression());
00047 }
00048 #endif // 0
00049
00050
00051 template <typename T, typename F, typename A>
00052 BOOST_UBLAS_INLINE
00053 int matrix_storage_size (const ublas::matrix<T,F,A>& m) {
00054 return (int) (m.size1() * m.size2());
00055 }
00056 template <typename T, std::size_t M, std::size_t N>
00057 BOOST_UBLAS_INLINE
00058 int matrix_storage_size (const ublas::c_matrix<T, M, N> &m) {
00059 return (int) (M * N);
00060 }
00061
00062
00063 template <typename T, typename F, typename A>
00064 BOOST_UBLAS_INLINE
00065 int leading_dimension (const ublas::matrix<T,F,A> &m, ublas::row_major_tag) {
00066 return (int) m.size2();
00067 }
00068 template <typename T, typename F, typename A>
00069 BOOST_UBLAS_INLINE
00070 int leading_dimension (const ublas::matrix<T,F,A> &m, ublas::column_major_tag) {
00071 return (int) m.size1();
00072 }
00073 template <typename T, typename F, typename A>
00074 BOOST_UBLAS_INLINE
00075 int leading_dimension (const ublas::matrix<T,F,A> &m) {
00076 typedef ublas::matrix<T,F,A> matrix_t;
00077 return bindings::traits::leading_dimension
00078 (m, BOOST_UBLAS_TYPENAME matrix_t::orientation_category());
00079 }
00080 template <typename M>
00081 BOOST_UBLAS_INLINE
00082 int leading_dimension (const ublas::matrix_reference<M> &m) {
00083 return bindings::traits::leading_dimension (m.expression());
00084 }
00085 template <typename M>
00086 BOOST_UBLAS_INLINE
00087 int leading_dimension (const ublas::matrix_range<M> &m) {
00088 return bindings::traits::leading_dimension (m.data());
00089 }
00090 template <typename T, std::size_t M, std::size_t N>
00091 BOOST_UBLAS_INLINE
00092 int leading_dimension (const ublas::c_matrix<T, M, N> &m) {
00093 return (int) N;
00094 }
00095
00096
00097
00098
00099 #if 0
00100
00101 template <typename M>
00102 BOOST_UBLAS_INLINE
00103 int matrix_stride1 (const M &m) {
00104 typedef typename M::functor_type functor_type;
00105 return (int) functor_type::one1 (m.size1(), m.size2());
00106 }
00107 template <typename M>
00108 BOOST_UBLAS_INLINE
00109 int matrix_stride2 (const M &m) {
00110 typedef typename M::functor_type functor_type;
00111 return (int) functor_type::one2 (m.size1(), m.size2());
00112 }
00113 #endif // 0
00114
00115 template <typename M, typename F, typename A>
00116 BOOST_UBLAS_INLINE
00117 int matrix_stride1 (const ublas::matrix<M,F,A> &m) {
00118 return (int) F::one1 (m.size1(), m.size2());
00119 }
00120 template <typename M, typename F, typename A>
00121 BOOST_UBLAS_INLINE
00122 int matrix_stride2 (const ublas::matrix<M,F,A> &m) {
00123 return (int) F::one2 (m.size1(), m.size2());
00124 }
00125 template <typename M>
00126 BOOST_UBLAS_INLINE
00127 int matrix_stride1 (const ublas::matrix_reference<M> &m) {
00128 return matrix_stride1 (m.expression());
00129 }
00130 template <typename M>
00131 BOOST_UBLAS_INLINE
00132 int matrix_stride2 (const ublas::matrix_reference<M> &m) {
00133 return matrix_stride2 (m.expression());
00134 }
00135 template <typename T, std::size_t M, std::size_t N>
00136 BOOST_UBLAS_INLINE
00137 int matrix_stride1 (const ublas::c_matrix<T, M, N> &m) { return (int) N; }
00138 template <typename T, std::size_t M, std::size_t N>
00139 BOOST_UBLAS_INLINE
00140 int matrix_stride2 (const ublas::c_matrix<T, M, N> &m) { return 1; }
00141 template <typename M>
00142 BOOST_UBLAS_INLINE
00143 int matrix_stride1 (const ublas::matrix_range<M> &m) {
00144 return matrix_stride1 (m.data());
00145 }
00146 template <typename M>
00147 BOOST_UBLAS_INLINE
00148 int matrix_stride2 (const ublas::matrix_range<M> &m) {
00149 return matrix_stride2 (m.data());
00150 }
00151 template <typename M>
00152 BOOST_UBLAS_INLINE
00153 int matrix_stride1 (const ublas::matrix_slice<M> &m) {
00154 return (int) (m.stride1() * matrix_stride1 (m.data()));
00155 }
00156 template <typename M>
00157 BOOST_UBLAS_INLINE
00158 int matrix_stride2 (const ublas::matrix_slice<M> &m) {
00159 return (int) (m.stride2() * matrix_stride2 (m.data()));
00160 }
00161 template <typename M>
00162 BOOST_UBLAS_INLINE
00163 int vector_stride (const ublas::matrix_row<M> &v) {
00164 return matrix_stride2 (v.data());
00165 }
00166 template <typename M>
00167 BOOST_UBLAS_INLINE
00168 int vector_stride (const ublas::matrix_column<M> &v) {
00169 return matrix_stride1 (v.data());
00170 }
00171
00172
00173
00174
00175 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00176 template <typename T, typename F, typename A>
00177 BOOST_UBLAS_INLINE
00178 typename ublas::matrix<T,F,A>::const_pointer
00179 matrix_storage (const ublas::matrix<T,F,A> &m) {
00180 return &m.data().begin()[0];
00181 }
00182 #endif
00183
00184
00185 template <typename T, typename F, typename A>
00186 BOOST_UBLAS_INLINE
00187 typename ublas::matrix<T,F,A>::const_pointer
00188 matrix_storage_const (const ublas::matrix<T,F,A> &m) {
00189 return &m.data().begin()[0];
00190 }
00191 template <typename T, typename F, typename A>
00192 BOOST_UBLAS_INLINE
00193 typename ublas::matrix<T,F,A>::pointer
00194 matrix_storage (ublas::matrix<T,F,A> &m) {
00195 return &m.data().begin()[0];
00196 }
00197
00198 #if 0
00199
00200 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00201 template <typename M>
00202 BOOST_UBLAS_INLINE
00203 typename M::const_pointer matrix_storage (const M &m) {
00204 return &m.data().begin()[0];
00205 }
00206 #endif
00207
00208
00209 template <typename M>
00210 BOOST_UBLAS_INLINE
00211 typename M::const_pointer matrix_storage_const (const M &m) {
00212 return &m.data().begin()[0];
00213 }
00214 template <typename M>
00215 BOOST_UBLAS_INLINE
00216 typename M::pointer matrix_storage (M &m) {
00217 return &m.data().begin()[0];
00218 }
00219 #endif // 0
00220
00221 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00222 template <typename M>
00223 BOOST_UBLAS_INLINE
00224 typename M::const_pointer
00225 matrix_storage (const ublas::matrix_reference<M> &m) {
00226 return matrix_storage (m.expression ());
00227 }
00228 #endif
00229
00230
00231 template <typename M>
00232 BOOST_UBLAS_INLINE
00233 typename M::const_pointer
00234 matrix_storage_const (const ublas::matrix_reference<M> &m) {
00235 return matrix_storage_const (m.expression ());
00236 }
00237 template <typename M>
00238 BOOST_UBLAS_INLINE
00239 typename M::pointer matrix_storage (ublas::matrix_reference<M> &m) {
00240 return matrix_storage (m.expression ());
00241 }
00242
00243 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00244 template <typename T, std::size_t M, std::size_t N>
00245 BOOST_UBLAS_INLINE
00246 typename ublas::c_matrix<T, M, N>::const_pointer
00247 matrix_storage (const ublas::c_matrix<T, M, N> &m) {
00248 return m.data();
00249 }
00250 #endif
00251 #ifndef BOOST_MSVC
00252
00253
00254 template <typename T, std::size_t M, std::size_t N>
00255 BOOST_UBLAS_INLINE
00256 typename ublas::c_matrix<T, M, N>::const_pointer
00257 matrix_storage_const (const ublas::c_matrix<T, M, N> &m) {
00258 return m.data();
00259 }
00260 template <typename T, std::size_t M, std::size_t N>
00261 BOOST_UBLAS_INLINE
00262 typename ublas::c_matrix<T, M, N>::pointer
00263 matrix_storage (ublas::c_matrix<T, M, N> &m) {
00264 return m.data();
00265 }
00266 #endif
00267
00268 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00269 template <typename M>
00270 BOOST_UBLAS_INLINE
00271 typename M::const_pointer
00272 matrix_storage (const ublas::matrix_range<M> &m) {
00273 return matrix_storage (m.data())
00274 + m.start1() * matrix_stride1 (m.data())
00275 + m.start2() * matrix_stride2 (m.data());
00276 }
00277 template <typename M>
00278 BOOST_UBLAS_INLINE
00279 typename M::const_pointer
00280 matrix_storage (const ublas::matrix_slice<M> &m) {
00281 return matrix_storage (m.data())
00282 + m.start1() * matrix_stride1 (m.data ())
00283 + m.start2() * matrix_stride2 (m.data ());
00284 }
00285 #endif
00286
00287
00288 template <typename M>
00289 BOOST_UBLAS_INLINE
00290 typename M::const_pointer
00291 matrix_storage_const (const ublas::matrix_range<M> &m) {
00292 return matrix_storage_const (m.data())
00293 + m.start1() * matrix_stride1 (m.data ())
00294 + m.start2() * matrix_stride2 (m.data ());
00295 }
00296 template <typename M>
00297 BOOST_UBLAS_INLINE
00298 typename M::const_pointer
00299 matrix_storage_const (const ublas::matrix_slice<M> &m) {
00300 return matrix_storage_const (m.data())
00301 + m.start1() * matrix_stride1 (m.data ())
00302 + m.start2() * matrix_stride2 (m.data ());
00303 }
00304 template <typename M>
00305 BOOST_UBLAS_INLINE
00306 typename M::pointer matrix_storage (ublas::matrix_range<M> &m) {
00307 return matrix_storage (m.data())
00308 + m.start1() * matrix_stride1 (m.data ())
00309 + m.start2() * matrix_stride2 (m.data ());
00310 }
00311 template <typename M>
00312 BOOST_UBLAS_INLINE
00313 typename M::pointer matrix_storage (ublas::matrix_slice<M> &m) {
00314 return matrix_storage (m.data())
00315 + m.start1() * matrix_stride1 (m.data ())
00316 + m.start2() * matrix_stride2 (m.data ());
00317 }
00318
00319 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00320 template <typename M>
00321 BOOST_UBLAS_INLINE
00322 typename M::const_pointer
00323 vector_storage (const ublas::matrix_row<M> &v) {
00324 return matrix_storage (v.data())
00325 + v.index() * matrix_stride1 (v.data());
00326 }
00327 template <typename M>
00328 BOOST_UBLAS_INLINE
00329 typename M::const_pointer
00330 vector_storage (const ublas::matrix_column<M> &v) {
00331 return matrix_storage (v.data())
00332 + v.index() * matrix_stride2 (v.data());
00333 }
00334 #endif
00335
00336
00337 template <typename M>
00338 BOOST_UBLAS_INLINE
00339 typename M::const_pointer
00340 vector_storage_const (const ublas::matrix_row<M> &v) {
00341 return matrix_storage_const (v.data())
00342 + v.index() * matrix_stride1 (v.data());
00343 }
00344 template <typename M>
00345 BOOST_UBLAS_INLINE
00346 typename M::const_pointer
00347 vector_storage_const (const ublas::matrix_column<M> &v) {
00348 return matrix_storage_const (v.data())
00349 + v.index() * matrix_stride2 (v.data());
00350 }
00351 template <typename M>
00352 BOOST_UBLAS_INLINE
00353 typename M::pointer vector_storage (ublas::matrix_row<M> &v) {
00354 return matrix_storage (v.data())
00355 + v.index() * matrix_stride1 (v.data());
00356 }
00357 template <typename M>
00358 BOOST_UBLAS_INLINE
00359 typename M::pointer vector_storage (ublas::matrix_column<M> &v) {
00360 return matrix_storage (v.data())
00361 + v.index() * matrix_stride2 (v.data());
00362 }
00363
00364 }}}}
00365
00366 #ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_NO_SYMMETRIC_TRAITS
00367
00368 #include <boost/numeric/bindings/traits/symm_herm_raw.hpp>
00369
00370 #endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_NO_SYMMETRIC_TRAITS
00371
00372 #endif // BOOST_NUMERIC_BINDINGS_TRAITS_MATRIX_RAW_HPP