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

include/tvmet/util/General.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: General.h,v 1.13 2007-06-23 15:58:59 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_UTIL_GENERAL_H
00025 #define TVMET_UTIL_GENERAL_H
00026 
00027 
00029 namespace tvmet {
00030 template<class T, std::size_t Rows, std::size_t Cols> class Matrix;
00031 template<class T, std::size_t Sz> class Vector;
00032 }
00033 
00034 namespace tvmet {
00035 
00036 namespace util {
00037 
00038 /*
00039  * \defgroup _util_function
00040  * \brief Usefull utility functions
00041  */
00042 
00048 template<class T, std::size_t Rows, std::size_t Cols>
00049 inline
00050 void
00051 Gemm(const Matrix<T, Rows, Cols>& m1, const Matrix<T, Rows, Cols>& m2,
00052      Matrix<T, Rows, Cols>& m3)
00053 {
00054   for (std::size_t i = 0; i < Rows; ++i) {
00055     for (std::size_t j = 0; j < Cols; ++j) {
00056       T sum(0);
00057       for (std::size_t k = 0; k < Cols; ++k) {
00058   sum += m1(i,k) * m2(k,j);
00059       }
00060       m3(i,j) = sum;
00061     }
00062   }
00063 }
00064 
00065 
00071 template<class T, std::size_t Rows, std::size_t Cols>
00072 inline
00073 void
00074 Gemv(const Matrix<T, Rows, Cols>& m, const Vector<T, Cols>& v,
00075      Vector<T, Cols>& v2)
00076 {
00077   for (std::size_t i = 0; i < Rows; ++i){
00078     v2(i) = T(0); // clean up before use
00079     for (std::size_t j = 0; j < Cols; ++j) {
00080       v2(i) += m(i,j) * v(j);
00081       }
00082   }
00083 }
00084 
00085 
00091 template<class T, std::size_t Sz>
00092 inline
00093 void
00094 Gevvmul(const Vector<T, Sz>& v1, const Vector<T, Sz>& v2,
00095        Vector<T, Sz>& v3)
00096 {
00097   for(std::size_t i = 0; i < Sz; ++i)
00098     v3(i) = v1(i) * v2(i);
00099 }
00100 
00101 
00107 template<class T, std::size_t Sz>
00108 inline
00109 void
00110 Gevvadd(const Vector<T, Sz>& v1, const Vector<T, Sz>& v2,
00111   Vector<T, Sz>& v3)
00112 {
00113   for(std::size_t i = 0; i < Sz; ++i)
00114     v3(i) = v1(i) + v2(i);
00115 }
00116 
00117 } // namespace util
00118 
00119 } // namespace tvmet
00120 
00121 #endif // TVMET_UTIL_GENERAL_H
00122 
00123 // Local Variables:
00124 // mode:C++
00125 // tab-width:8
00126 // End:

Author: