SourceForge Logo Tiny Vector Matrix library using Expression Templates Sourceforge Project Page

include/tvmet/MatrixEval.h

Go to the documentation of this file.
00001 /*
00002  * Tiny Vector Matrix Library
00003  * Dense Vector Matrix Libary of Tiny size using Expression Templates
00004  *
00005  * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * $Id: MatrixEval.h,v 1.18 2007-06-23 15:58:58 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_MATRIX_EVAL_H
00025 #define TVMET_MATRIX_EVAL_H
00026 
00027 namespace tvmet {
00028 
00029 
00045 template<class E, std::size_t Rows, std::size_t Cols>
00046 inline
00047 bool all_elements(const XprMatrix<E, Rows, Cols>& e) {
00048   return meta::Matrix<Rows, Cols, 0, 0>::all_elements(e);
00049 }
00050 
00051 
00067 template<class E, std::size_t Rows, std::size_t Cols>
00068 inline
00069 bool any_elements(const XprMatrix<E, Rows, Cols>& e) {
00070   return meta::Matrix<Rows, Cols, 0, 0>::any_elements(e);
00071 }
00072 
00073 
00074 /*
00075  * trinary evaluation functions with matrizes and xpr of
00076  *
00077  * XprMatrix<E1, Rows, Cols> ? Matrix<T2, Rows, Cols> : Matrix<T3, Rows, Cols>
00078  * XprMatrix<E1, Rows, Cols> ? Matrix<T2, Rows, Cols> : XprMatrix<E3, Rows, Cols>
00079  * XprMatrix<E1, Rows, Cols> ? XprMatrix<E2, Rows, Cols> : Matrix<T3, Rows, Cols>
00080  * XprMatrix<E1, Rows, Cols> ? XprMatrix<E2, Rows, Cols> : XprMatrix<E3, Rows, Cols>
00081  */
00082 
00090 template<class E1, class T2, class T3, std::size_t Rows, std::size_t Cols>
00091 inline
00092 XprMatrix<
00093   XprEval<
00094     XprMatrix<E1, Rows, Cols>,
00095     MatrixConstReference<T2, Rows, Cols>,
00096     MatrixConstReference<T3, Rows, Cols>
00097   >,
00098   Rows, Cols
00099 >
00100 eval(const XprMatrix<E1, Rows, Cols>& e1,
00101      const Matrix<T2, Rows, Cols>& m2,
00102      const Matrix<T3, Rows, Cols>& m3) {
00103   typedef XprEval<
00104     XprMatrix<E1, Rows, Cols>,
00105     MatrixConstReference<T2, Rows, Cols>,
00106     MatrixConstReference<T3, Rows, Cols>
00107   >               expr_type;
00108   return XprMatrix<expr_type, Rows, Cols>(
00109     expr_type(e1, m2.const_ref(), m3.const_ref()));
00110 }
00111 
00112 
00120 template<class E1, class T2, class E3, std::size_t Rows, std::size_t Cols>
00121 inline
00122 XprMatrix<
00123   XprEval<
00124     XprMatrix<E1, Rows, Cols>,
00125     MatrixConstReference<T2, Rows, Cols>,
00126     XprMatrix<E3, Rows, Cols>
00127   >,
00128   Rows, Cols
00129 >
00130 eval(const XprMatrix<E1, Rows, Cols>& e1,
00131      const Matrix<T2, Rows, Cols>& m2,
00132      const XprMatrix<E3, Rows, Cols>& e3) {
00133   typedef XprEval<
00134     XprMatrix<E1, Rows, Cols>,
00135     MatrixConstReference<T2, Rows, Cols>,
00136     XprMatrix<E3, Rows, Cols>
00137   >               expr_type;
00138   return XprMatrix<expr_type, Rows, Cols>(
00139     expr_type(e1, m2.const_ref(), e3));
00140 }
00141 
00142 
00150 template<class E1, class E2, class T3, std::size_t Rows, std::size_t Cols>
00151 inline
00152 XprMatrix<
00153   XprEval<
00154     XprMatrix<E1, Rows, Cols>,
00155     XprMatrix<E2, Rows, Cols>,
00156     MatrixConstReference<T3, Rows, Cols>
00157   >,
00158   Rows, Cols
00159 >
00160 eval(const XprMatrix<E1, Rows, Cols>& e1,
00161     const  XprMatrix<E2, Rows, Cols>& e2,
00162      const Matrix<T3, Rows, Cols>& m3) {
00163   typedef XprEval<
00164     XprMatrix<E1, Rows, Cols>,
00165     XprMatrix<E2, Rows, Cols>,
00166     MatrixConstReference<T3, Rows, Cols>
00167   >               expr_type;
00168   return XprMatrix<expr_type, Rows, Cols>(
00169     expr_type(e1, e2, m3.const_ref()));
00170 }
00171 
00172 
00180 template<class E1, class E2, class E3, std::size_t Rows, std::size_t Cols>
00181 inline
00182 XprMatrix<
00183   XprEval<
00184     XprMatrix<E1, Rows, Cols>,
00185     XprMatrix<E2, Rows, Cols>,
00186     XprMatrix<E3, Rows, Cols>
00187   >,
00188   Rows, Cols
00189 >
00190 eval(const XprMatrix<E1, Rows, Cols>& e1,
00191      const XprMatrix<E2, Rows, Cols>& e2,
00192      const XprMatrix<E3, Rows, Cols>& e3) {
00193   typedef XprEval<
00194     XprMatrix<E1, Rows, Cols>,
00195     XprMatrix<E2, Rows, Cols>,
00196     XprMatrix<E3, Rows, Cols>
00197   >               expr_type;
00198   return XprMatrix<expr_type, Rows, Cols>(expr_type(e1, e2, e3));
00199 }
00200 
00201 
00202 /*
00203  * trinary evaluation functions with matrizes, xpr of and POD
00204  *
00205  * XprMatrix<E, Rows, Cols> ? POD1 : POD2
00206  * XprMatrix<E1, Rows, Cols> ? POD : XprMatrix<E3, Rows, Cols>
00207  * XprMatrix<E1, Rows, Cols> ? XprMatrix<E2, Rows, Cols> : POD
00208  */
00209 #define TVMET_IMPLEMENT_MACRO(POD)                    \
00210 template<class E, std::size_t Rows, std::size_t Cols>     \
00211 inline                            \
00212 XprMatrix<                          \
00213   XprEval<                          \
00214     XprMatrix<E, Rows, Cols>,                             \
00215     XprLiteral< POD >,                        \
00216     XprLiteral< POD >                         \
00217   >,                              \
00218   Rows, Cols                \
00219 >                             \
00220 eval(const XprMatrix<E, Rows, Cols>& e, POD x2, POD x3) {         \
00221   typedef XprEval<                        \
00222     XprMatrix<E, Rows, Cols>,                       \
00223     XprLiteral< POD >,                          \
00224     XprLiteral< POD >                         \
00225   >               expr_type;  \
00226   return XprMatrix<expr_type, Rows, Cols>(        \
00227     expr_type(e, XprLiteral< POD >(x2), XprLiteral< POD >(x3)));  \
00228 }                             \
00229                               \
00230 template<class E1, class E3, std::size_t Rows, std::size_t Cols>  \
00231 inline                            \
00232 XprMatrix<                          \
00233   XprEval<                          \
00234     XprMatrix<E1, Rows, Cols>,                      \
00235     XprLiteral< POD >,                        \
00236     XprMatrix<E3, Rows, Cols>                       \
00237   >,                              \
00238   Rows, Cols                \
00239 >                             \
00240 eval(const XprMatrix<E1, Rows, Cols>& e1, POD x2, const XprMatrix<E3, Rows, Cols>& e3) { \
00241   typedef XprEval<                        \
00242     XprMatrix<E1, Rows, Cols>,                      \
00243     XprLiteral< POD >,                          \
00244     XprMatrix<E3, Rows, Cols>                       \
00245   >               expr_type;  \
00246   return XprMatrix<expr_type, Rows, Cols>(        \
00247     expr_type(e1, XprLiteral< POD >(x2), e3));        \
00248 }                             \
00249                               \
00250 template<class E1, class E2, std::size_t Rows, std::size_t Cols>  \
00251 inline                            \
00252 XprMatrix<                          \
00253   XprEval<                          \
00254     XprMatrix<E1, Rows, Cols>,                      \
00255     XprMatrix<E2, Rows, Cols>,                      \
00256     XprLiteral< POD >                         \
00257   >,                              \
00258   Rows, Cols                \
00259 >                             \
00260 eval(const XprMatrix<E1, Rows, Cols>& e1, const XprMatrix<E2, Rows, Cols>& e2, POD x3) { \
00261   typedef XprEval<                        \
00262     XprMatrix<E1, Rows, Cols>,                      \
00263     XprMatrix<E2, Rows, Cols>,                      \
00264     XprLiteral< POD >                         \
00265   >               expr_type;  \
00266   return XprMatrix<expr_type, Rows, Cols>(        \
00267     expr_type(e1, e2, XprLiteral< POD >(x3)));        \
00268 }
00269 
00270 TVMET_IMPLEMENT_MACRO(int)
00271 
00272 #if defined(TVMET_HAVE_LONG_LONG)
00273 TVMET_IMPLEMENT_MACRO(long long int)
00274 #endif
00275 
00276 TVMET_IMPLEMENT_MACRO(float)
00277 TVMET_IMPLEMENT_MACRO(double)
00278 
00279 #if defined(TVMET_HAVE_LONG_DOUBLE)
00280 TVMET_IMPLEMENT_MACRO(long double)
00281 #endif
00282 
00283 #undef TVMET_IMPLEMENT_MACRO
00284 
00285 
00286 /*
00287  * trinary evaluation functions with matrizes, xpr of and complex<> types
00288  *
00289  * XprMatrix<E, Rows, Cols> e, std::complex<T> z2, std::complex<T> z3
00290  * XprMatrix<E1, Rows, Cols> e1, std::complex<T> z2, XprMatrix<E3, Rows, Cols> e3
00291  * XprMatrix<E1, Rows, Cols> e1, XprMatrix<E2, Rows, Cols> e2, std::complex<T> z3
00292  */
00293 #if defined(TVMET_HAVE_COMPLEX)
00294 
00302 template<class E, std::size_t Rows, std::size_t Cols, class T>
00303 inline
00304 XprMatrix<
00305   XprEval<
00306     XprMatrix<E, Rows, Cols>,
00307     XprLiteral< std::complex<T> >,
00308     XprLiteral< std::complex<T> >
00309   >,
00310   Rows, Cols
00311 >
00312 eval(const XprMatrix<E, Rows, Cols>& e, const std::complex<T>& x2, const std::complex<T>& x3) {
00313   typedef XprEval<
00314     XprMatrix<E, Rows, Cols>,
00315     XprLiteral< std::complex<T> >,
00316     XprLiteral< std::complex<T> >
00317   >               expr_type;
00318   return XprMatrix<expr_type, Rows, Cols>(
00319     expr_type(e, XprLiteral< std::complex<T> >(x2), XprLiteral< std::complex<T> >(x3)));
00320 }
00321 
00322 
00330 template<class E1, class E3, std::size_t Rows, std::size_t Cols, class T>
00331 inline
00332 XprMatrix<
00333   XprEval<
00334     XprMatrix<E1, Rows, Cols>,
00335     XprLiteral< std::complex<T> >,
00336     XprMatrix<E3, Rows, Cols>
00337   >,
00338   Rows, Cols
00339 >
00340 eval(const XprMatrix<E1, Rows, Cols>& e1, const std::complex<T>& x2, const XprMatrix<E3, Rows, Cols>& e3) {
00341   typedef XprEval<
00342     XprMatrix<E1, Rows, Cols>,
00343     XprLiteral< std::complex<T> >,
00344     XprMatrix<E3, Rows, Cols>
00345   >               expr_type;
00346   return XprMatrix<expr_type, Rows, Cols>(
00347     expr_type(e1, XprLiteral< std::complex<T> >(x2), e3));
00348 }
00349 
00350 
00358 template<class E1, class E2, std::size_t Rows, std::size_t Cols, class T>
00359 inline
00360 XprMatrix<
00361   XprEval<
00362     XprMatrix<E1, Rows, Cols>,
00363     XprMatrix<E2, Rows, Cols>,
00364     XprLiteral< std::complex<T> >
00365   >,
00366   Rows, Cols
00367 >
00368 eval(const XprMatrix<E1, Rows, Cols>& e1, const XprMatrix<E2, Rows, Cols>& e2, const std::complex<T>& x3) {
00369   typedef XprEval<
00370     XprMatrix<E1, Rows, Cols>,
00371     XprMatrix<E2, Rows, Cols>,
00372     XprLiteral< std::complex<T> >
00373   >               expr_type;
00374   return XprMatrix<expr_type, Rows, Cols>(
00375     expr_type(e1, e2, XprLiteral< std::complex<T> >(x3)));
00376 }
00377 #endif // defined(TVMET_HAVE_COMPLEX)
00378 
00379 
00380 } // namespace tvmet
00381 
00382 #endif // TVMET_MATRIX_EVAL_H
00383 
00384 // Local Variables:
00385 // mode:C++
00386 // tab-width:8
00387 // End:

Author: