Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Eurobot_2012_Secondary by
Gemtm.h
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: Gemtm.h,v 1.9 2007-06-23 15:58:59 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_LOOP_GEMTM_H 00025 #define TVMET_LOOP_GEMTM_H 00026 00027 namespace tvmet { 00028 00029 namespace loop { 00030 00031 00032 /** 00033 * \class gemtm Gemtm.h "tvmet/loop/Gemtm.h" 00034 * \brief class for matrix-matrix product using loop unrolling. 00035 * using formula 00036 * \f[ 00037 * M_1^{T}\,M_2 00038 * \f] 00039 * \par Example: 00040 * \code 00041 * template<class T, std::size_t Rows1, std::size_t Cols1, std::size_t Cols2> 00042 * inline 00043 * void 00044 * prod(const Matrix<T, Rows1, Cols1>& lhs, const Matrix<T, Rows1, Cols2>& rhs, 00045 * Matrix<T, Cols2, Cols1>& dest) 00046 * { 00047 * for (std::size_t i = 0; i != Cols1; ++i) { 00048 * for (std::size_t j = 0; j != Cols2; ++j) { 00049 * dest(i, j) = tvmet::loop::gemtm<Rows1, Cols1, Cols2>::prod(lhs, rhs, i, j); 00050 * } 00051 * } 00052 * } 00053 * \endcode 00054 * \note The number of rows of rhs matrix have to be equal rows of rhs matrix, 00055 * since lhs matrix 1 is transposed. 00056 * The result is a (Cols1 x Cols2) matrix. 00057 */ 00058 template<std::size_t Rows1, std::size_t Cols1, 00059 std::size_t Cols2> 00060 class gemtm 00061 { 00062 gemtm(const gemtm&); 00063 gemtm& operator=(const gemtm&); 00064 00065 private: 00066 enum { 00067 count = Cols1, 00068 N = (count+7)/8 00069 }; 00070 00071 public: 00072 gemtm() { } 00073 00074 public: 00075 template<class E1, class E2> 00076 static inline 00077 typename PromoteTraits< 00078 typename E1::value_type, 00079 typename E2::value_type 00080 >::value_type 00081 prod(const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) { 00082 typename PromoteTraits< 00083 typename E1::value_type, 00084 typename E2::value_type 00085 >::value_type sum(0); 00086 std::size_t k(0); 00087 std::size_t n(N); 00088 00089 // Duff's device 00090 switch(count % 8) { 00091 case 0: do { sum += lhs(k, i) * rhs(k, j); ++k; 00092 case 7: sum += lhs(k, i) * rhs(k, j); ++k; 00093 case 6: sum += lhs(k, i) * rhs(k, j); ++k; 00094 case 5: sum += lhs(k, i) * rhs(k, j); ++k; 00095 case 4: sum += lhs(k, i) * rhs(k, j); ++k; 00096 case 3: sum += lhs(k, i) * rhs(k, j); ++k; 00097 case 2: sum += lhs(k, i) * rhs(k, j); ++k; 00098 case 1: sum += lhs(k, i) * rhs(k, j); ++k; 00099 } while(--n != 0); 00100 } 00101 00102 return sum; 00103 } 00104 }; 00105 00106 00107 } // namespace loop 00108 00109 } // namespace tvmet 00110 00111 #endif /* TVMET_LOOP_GEMTM_H */ 00112 00113 // Local Variables: 00114 // mode:C++ 00115 // tab-width:8 00116 // End:
Generated on Tue Jul 12 2022 21:02:12 by
1.7.2
