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

include/tvmet/xpr/Matrix.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: Matrix.h,v 1.26 2007-06-23 15:59:00 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_XPR_MATRIX_H
00025 #define TVMET_XPR_MATRIX_H
00026 
00027 #include <tvmet/meta/Matrix.h>
00028 #include <tvmet/loop/Matrix.h>
00029 
00030 namespace tvmet {
00031 
00032 
00033 /* forwards */
00034 template <class T, std::size_t Rows, std::size_t Cols> class Matrix;
00035 
00049 template<class E, std::size_t NRows, std::size_t NCols>
00050 class XprMatrix
00051   : public TvmetBase< XprMatrix<E, NRows, NCols> >
00052 {
00053   XprMatrix();
00054   XprMatrix& operator=(const XprMatrix&);
00055 
00056 public:
00058   enum {
00059     Rows = NRows,     
00060     Cols = NCols,     
00061     Size = Rows * Cols      
00062   };
00063 
00064 public:
00066   enum {
00067     ops_assign = Rows * Cols,
00068     ops        = E::ops,
00069     use_meta   = ops_assign < TVMET_COMPLEXITY_M_ASSIGN_TRIGGER ? true : false
00070   };
00071 
00072 public:
00073   typedef typename E::value_type      value_type;
00074 
00075 public:
00077   explicit XprMatrix(const E& e)
00078     : m_expr(e)
00079   { }
00080 
00082 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
00083   XprMatrix(const XprMatrix& rhs)
00084     : m_expr(rhs.m_expr)
00085   { }
00086 #endif
00087 
00089   value_type operator()(std::size_t i, std::size_t j) const {
00090     TVMET_RT_CONDITION((i < Rows) && (j < Cols), "XprMatrix Bounce Violation")
00091     return m_expr(i, j);
00092   }
00093 
00094 private:
00096   template<class Dest, class Src, class Assign>
00097   static inline
00098   void do_assign(dispatch<true>, Dest& dest, const Src& src, const Assign& assign_fn) {
00099     meta::Matrix<Rows, Cols, 0, 0>::assign(dest, src, assign_fn);
00100   }
00101 
00103   template<class Dest, class Src, class Assign>
00104   static inline
00105   void do_assign(dispatch<false>, Dest& dest, const Src& src, const Assign& assign_fn) {
00106     loop::Matrix<Rows, Cols>::assign(dest, src, assign_fn);
00107   }
00108 
00109 public:
00111   template<class Dest, class Assign>
00112   void assign_to(Dest& dest, const Assign& assign_fn) const {
00113     /* here is a way for caching, since each complex 'Node'
00114        is of type XprMatrix. */
00115     do_assign(dispatch<use_meta>(), dest, *this, assign_fn);
00116   }
00117 
00118 public: // debugging Xpr parse tree
00119   void print_xpr(std::ostream& os, std::size_t l=0) const {
00120     os << IndentLevel(l++)
00121        << "XprMatrix["
00122        << (use_meta ? "M" :  "L") << ", O=" << ops << "]<"
00123        << std::endl;
00124     m_expr.print_xpr(os, l);
00125     os << IndentLevel(l)
00126        << "R=" << Rows << ", C=" << Cols << std::endl;
00127     os << IndentLevel(--l) << ">"
00128        << ((l != 0) ? "," : "") << std::endl;
00129   }
00130 
00131 private:
00132   const E           m_expr;
00133 };
00134 
00135 
00136 } // namespace tvmet
00137 
00138 #include <tvmet/Functional.h>
00139 
00140 #include <tvmet/xpr/BinOperator.h>
00141 #include <tvmet/xpr/UnOperator.h>
00142 #include <tvmet/xpr/Literal.h>
00143 
00144 #include <tvmet/xpr/Identity.h>
00145 
00146 #include <tvmet/xpr/MMProduct.h>
00147 #include <tvmet/xpr/MMProductTransposed.h>
00148 #include <tvmet/xpr/MMtProduct.h>
00149 #include <tvmet/xpr/MtMProduct.h>
00150 #include <tvmet/xpr/MVProduct.h>
00151 #include <tvmet/xpr/MtVProduct.h>
00152 #include <tvmet/xpr/MatrixTranspose.h>
00153 
00154 #include <tvmet/xpr/MatrixFunctions.h>
00155 #include <tvmet/xpr/MatrixBinaryFunctions.h>
00156 #include <tvmet/xpr/MatrixUnaryFunctions.h>
00157 #include <tvmet/xpr/MatrixOperators.h>
00158 #include <tvmet/xpr/Eval.h>
00159 
00160 #endif // TVMET_XPR_MATRIX_H
00161 
00162 // Local Variables:
00163 // mode:C++
00164 // tab-width:8
00165 // End:

Author: