This is the Tiny Vector Matrix Expression Templates library found at http://tvmet.sourceforge.net. It is the fastest and most compact matrix lib out there (for < 10x10 matricies). I have done some minor tweaks to make it compile for mbed. For examples and hints on how to use, see: http://tvmet.sourceforge.net/usage.html
Dependents: Eurobot_2012_Secondary
xpr/MatrixFunctions.h@0:feb4117d16d8, 2012-03-28 (annotated)
- Committer:
- madcowswe
- Date:
- Wed Mar 28 15:53:45 2012 +0000
- Revision:
- 0:feb4117d16d8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
madcowswe | 0:feb4117d16d8 | 1 | /* |
madcowswe | 0:feb4117d16d8 | 2 | * Tiny Vector Matrix Library |
madcowswe | 0:feb4117d16d8 | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
madcowswe | 0:feb4117d16d8 | 4 | * |
madcowswe | 0:feb4117d16d8 | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
madcowswe | 0:feb4117d16d8 | 6 | * |
madcowswe | 0:feb4117d16d8 | 7 | * This library is free software; you can redistribute it and/or |
madcowswe | 0:feb4117d16d8 | 8 | * modify it under the terms of the GNU lesser General Public |
madcowswe | 0:feb4117d16d8 | 9 | * License as published by the Free Software Foundation; either |
madcowswe | 0:feb4117d16d8 | 10 | * version 2.1 of the License, or (at your option) any later version. |
madcowswe | 0:feb4117d16d8 | 11 | * |
madcowswe | 0:feb4117d16d8 | 12 | * This library is distributed in the hope that it will be useful, |
madcowswe | 0:feb4117d16d8 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
madcowswe | 0:feb4117d16d8 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
madcowswe | 0:feb4117d16d8 | 15 | * lesser General Public License for more details. |
madcowswe | 0:feb4117d16d8 | 16 | * |
madcowswe | 0:feb4117d16d8 | 17 | * You should have received a copy of the GNU lesser General Public |
madcowswe | 0:feb4117d16d8 | 18 | * License along with this library; if not, write to the Free Software |
madcowswe | 0:feb4117d16d8 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
madcowswe | 0:feb4117d16d8 | 20 | * |
madcowswe | 0:feb4117d16d8 | 21 | * $Id: MatrixFunctions.h,v 1.44 2007-06-23 15:59:00 opetzold Exp $ |
madcowswe | 0:feb4117d16d8 | 22 | */ |
madcowswe | 0:feb4117d16d8 | 23 | |
madcowswe | 0:feb4117d16d8 | 24 | #ifndef TVMET_XPR_MATRIX_FUNCTIONS_H |
madcowswe | 0:feb4117d16d8 | 25 | #define TVMET_XPR_MATRIX_FUNCTIONS_H |
madcowswe | 0:feb4117d16d8 | 26 | |
madcowswe | 0:feb4117d16d8 | 27 | namespace tvmet { |
madcowswe | 0:feb4117d16d8 | 28 | |
madcowswe | 0:feb4117d16d8 | 29 | |
madcowswe | 0:feb4117d16d8 | 30 | /* forwards */ |
madcowswe | 0:feb4117d16d8 | 31 | template<class T, std::size_t Rows, std::size_t Cols> class Matrix; |
madcowswe | 0:feb4117d16d8 | 32 | template<class T, std::size_t Sz> class Vector; |
madcowswe | 0:feb4117d16d8 | 33 | template<class E, std::size_t Sz> class XprVector; |
madcowswe | 0:feb4117d16d8 | 34 | template<class E> class XprMatrixTranspose; |
madcowswe | 0:feb4117d16d8 | 35 | template<class E, std::size_t Sz> class XprMatrixDiag; |
madcowswe | 0:feb4117d16d8 | 36 | template<class E, std::size_t Rows, std::size_t Cols> class XprMatrixRow; |
madcowswe | 0:feb4117d16d8 | 37 | template<class E, std::size_t Rows, std::size_t Cols> class XprMatrixCol; |
madcowswe | 0:feb4117d16d8 | 38 | |
madcowswe | 0:feb4117d16d8 | 39 | |
madcowswe | 0:feb4117d16d8 | 40 | /********************************************************* |
madcowswe | 0:feb4117d16d8 | 41 | * PART I: DECLARATION |
madcowswe | 0:feb4117d16d8 | 42 | *********************************************************/ |
madcowswe | 0:feb4117d16d8 | 43 | |
madcowswe | 0:feb4117d16d8 | 44 | |
madcowswe | 0:feb4117d16d8 | 45 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 46 | * Matrix arithmetic functions add, sub, mul and div |
madcowswe | 0:feb4117d16d8 | 47 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 48 | |
madcowswe | 0:feb4117d16d8 | 49 | |
madcowswe | 0:feb4117d16d8 | 50 | /* |
madcowswe | 0:feb4117d16d8 | 51 | * function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>) |
madcowswe | 0:feb4117d16d8 | 52 | */ |
madcowswe | 0:feb4117d16d8 | 53 | #define TVMET_DECLARE_MACRO(NAME) \ |
madcowswe | 0:feb4117d16d8 | 54 | template<class E1, class E2, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 55 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 56 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 57 | Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 58 | XprMatrix<E1, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 59 | XprMatrix<E2, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 60 | >, \ |
madcowswe | 0:feb4117d16d8 | 61 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 62 | > \ |
madcowswe | 0:feb4117d16d8 | 63 | NAME (const XprMatrix<E1, Rows, Cols>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 64 | const XprMatrix<E2, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 65 | |
madcowswe | 0:feb4117d16d8 | 66 | TVMET_DECLARE_MACRO(add) // per se element wise |
madcowswe | 0:feb4117d16d8 | 67 | TVMET_DECLARE_MACRO(sub) // per se element wise |
madcowswe | 0:feb4117d16d8 | 68 | namespace element_wise { |
madcowswe | 0:feb4117d16d8 | 69 | TVMET_DECLARE_MACRO(mul) // not defined for matrizes |
madcowswe | 0:feb4117d16d8 | 70 | TVMET_DECLARE_MACRO(div) // not defined for matrizes |
madcowswe | 0:feb4117d16d8 | 71 | } |
madcowswe | 0:feb4117d16d8 | 72 | |
madcowswe | 0:feb4117d16d8 | 73 | #undef TVMET_DECLARE_MACRO |
madcowswe | 0:feb4117d16d8 | 74 | |
madcowswe | 0:feb4117d16d8 | 75 | |
madcowswe | 0:feb4117d16d8 | 76 | /* |
madcowswe | 0:feb4117d16d8 | 77 | * function(XprMatrix<E, Rows, Cols>, POD) |
madcowswe | 0:feb4117d16d8 | 78 | * function(POD, XprMatrix<E, Rows, Cols>) |
madcowswe | 0:feb4117d16d8 | 79 | * Note: - operations +,-,*,/ are per se element wise |
madcowswe | 0:feb4117d16d8 | 80 | */ |
madcowswe | 0:feb4117d16d8 | 81 | #define TVMET_DECLARE_MACRO(NAME, POD) \ |
madcowswe | 0:feb4117d16d8 | 82 | template<class E, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 83 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 84 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 85 | Fcnl_##NAME<typename E::value_type, POD >, \ |
madcowswe | 0:feb4117d16d8 | 86 | XprMatrix<E, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 87 | XprLiteral< POD > \ |
madcowswe | 0:feb4117d16d8 | 88 | >, \ |
madcowswe | 0:feb4117d16d8 | 89 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 90 | > \ |
madcowswe | 0:feb4117d16d8 | 91 | NAME (const XprMatrix<E, Rows, Cols>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 92 | POD rhs) TVMET_CXX_ALWAYS_INLINE; \ |
madcowswe | 0:feb4117d16d8 | 93 | \ |
madcowswe | 0:feb4117d16d8 | 94 | template<class E, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 95 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 96 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 97 | Fcnl_##NAME< POD, typename E::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 98 | XprLiteral< POD >, \ |
madcowswe | 0:feb4117d16d8 | 99 | XprMatrix<E, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 100 | >, \ |
madcowswe | 0:feb4117d16d8 | 101 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 102 | > \ |
madcowswe | 0:feb4117d16d8 | 103 | NAME (POD lhs, \ |
madcowswe | 0:feb4117d16d8 | 104 | const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 105 | |
madcowswe | 0:feb4117d16d8 | 106 | TVMET_DECLARE_MACRO(add, int) |
madcowswe | 0:feb4117d16d8 | 107 | TVMET_DECLARE_MACRO(sub, int) |
madcowswe | 0:feb4117d16d8 | 108 | TVMET_DECLARE_MACRO(mul, int) |
madcowswe | 0:feb4117d16d8 | 109 | TVMET_DECLARE_MACRO(div, int) |
madcowswe | 0:feb4117d16d8 | 110 | |
madcowswe | 0:feb4117d16d8 | 111 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 0:feb4117d16d8 | 112 | TVMET_DECLARE_MACRO(add, long long int) |
madcowswe | 0:feb4117d16d8 | 113 | TVMET_DECLARE_MACRO(sub, long long int) |
madcowswe | 0:feb4117d16d8 | 114 | TVMET_DECLARE_MACRO(mul, long long int) |
madcowswe | 0:feb4117d16d8 | 115 | TVMET_DECLARE_MACRO(div, long long int) |
madcowswe | 0:feb4117d16d8 | 116 | #endif |
madcowswe | 0:feb4117d16d8 | 117 | |
madcowswe | 0:feb4117d16d8 | 118 | TVMET_DECLARE_MACRO(add, float) |
madcowswe | 0:feb4117d16d8 | 119 | TVMET_DECLARE_MACRO(sub, float) |
madcowswe | 0:feb4117d16d8 | 120 | TVMET_DECLARE_MACRO(mul, float) |
madcowswe | 0:feb4117d16d8 | 121 | TVMET_DECLARE_MACRO(div, float) |
madcowswe | 0:feb4117d16d8 | 122 | |
madcowswe | 0:feb4117d16d8 | 123 | TVMET_DECLARE_MACRO(add, double) |
madcowswe | 0:feb4117d16d8 | 124 | TVMET_DECLARE_MACRO(sub, double) |
madcowswe | 0:feb4117d16d8 | 125 | TVMET_DECLARE_MACRO(mul, double) |
madcowswe | 0:feb4117d16d8 | 126 | TVMET_DECLARE_MACRO(div, double) |
madcowswe | 0:feb4117d16d8 | 127 | |
madcowswe | 0:feb4117d16d8 | 128 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 0:feb4117d16d8 | 129 | TVMET_DECLARE_MACRO(add, long double) |
madcowswe | 0:feb4117d16d8 | 130 | TVMET_DECLARE_MACRO(sub, long double) |
madcowswe | 0:feb4117d16d8 | 131 | TVMET_DECLARE_MACRO(mul, long double) |
madcowswe | 0:feb4117d16d8 | 132 | TVMET_DECLARE_MACRO(div, long double) |
madcowswe | 0:feb4117d16d8 | 133 | #endif |
madcowswe | 0:feb4117d16d8 | 134 | |
madcowswe | 0:feb4117d16d8 | 135 | #undef TVMET_DECLARE_MACRO |
madcowswe | 0:feb4117d16d8 | 136 | |
madcowswe | 0:feb4117d16d8 | 137 | |
madcowswe | 0:feb4117d16d8 | 138 | #if defined(TVMET_HAVE_COMPLEX) |
madcowswe | 0:feb4117d16d8 | 139 | /* |
madcowswe | 0:feb4117d16d8 | 140 | * function(XprMatrix<E, Rows, Cols>, complex<T>) |
madcowswe | 0:feb4117d16d8 | 141 | * function(complex<T>, XprMatrix<E, Rows, Cols>) |
madcowswe | 0:feb4117d16d8 | 142 | * Note: - operations +,-,*,/ are per se element wise |
madcowswe | 0:feb4117d16d8 | 143 | * \todo type promotion |
madcowswe | 0:feb4117d16d8 | 144 | */ |
madcowswe | 0:feb4117d16d8 | 145 | #define TVMET_DECLARE_MACRO(NAME) \ |
madcowswe | 0:feb4117d16d8 | 146 | template<class E, class T, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 147 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 148 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 149 | Fcnl_##NAME<typename E::value_type, std::complex<T> >, \ |
madcowswe | 0:feb4117d16d8 | 150 | XprMatrix<E, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 151 | XprLiteral< std::complex<T> > \ |
madcowswe | 0:feb4117d16d8 | 152 | >, \ |
madcowswe | 0:feb4117d16d8 | 153 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 154 | > \ |
madcowswe | 0:feb4117d16d8 | 155 | NAME (const XprMatrix<E, Rows, Cols>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 156 | const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE; \ |
madcowswe | 0:feb4117d16d8 | 157 | \ |
madcowswe | 0:feb4117d16d8 | 158 | template<class T, class E, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 159 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 160 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 161 | Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 162 | XprLiteral< std::complex<T> >, \ |
madcowswe | 0:feb4117d16d8 | 163 | XprMatrix<E, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 164 | >, \ |
madcowswe | 0:feb4117d16d8 | 165 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 166 | > \ |
madcowswe | 0:feb4117d16d8 | 167 | NAME (const std::complex<T>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 168 | const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 169 | |
madcowswe | 0:feb4117d16d8 | 170 | TVMET_DECLARE_MACRO(add) |
madcowswe | 0:feb4117d16d8 | 171 | TVMET_DECLARE_MACRO(sub) |
madcowswe | 0:feb4117d16d8 | 172 | TVMET_DECLARE_MACRO(mul) |
madcowswe | 0:feb4117d16d8 | 173 | TVMET_DECLARE_MACRO(div) |
madcowswe | 0:feb4117d16d8 | 174 | |
madcowswe | 0:feb4117d16d8 | 175 | #undef TVMET_DECLARE_MACRO |
madcowswe | 0:feb4117d16d8 | 176 | |
madcowswe | 0:feb4117d16d8 | 177 | #endif // defined(TVMET_HAVE_COMPLEX) |
madcowswe | 0:feb4117d16d8 | 178 | |
madcowswe | 0:feb4117d16d8 | 179 | |
madcowswe | 0:feb4117d16d8 | 180 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 181 | * matrix prod( ... ) functions |
madcowswe | 0:feb4117d16d8 | 182 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 183 | |
madcowswe | 0:feb4117d16d8 | 184 | |
madcowswe | 0:feb4117d16d8 | 185 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 186 | class E2, std::size_t Cols2> |
madcowswe | 0:feb4117d16d8 | 187 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 188 | XprMMProduct< |
madcowswe | 0:feb4117d16d8 | 189 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 190 | XprMatrix<E2, Cols1, Cols2>, Cols2 |
madcowswe | 0:feb4117d16d8 | 191 | >, |
madcowswe | 0:feb4117d16d8 | 192 | Rows1, Cols2 // return Dim |
madcowswe | 0:feb4117d16d8 | 193 | > |
madcowswe | 0:feb4117d16d8 | 194 | prod(const XprMatrix<E1, Rows1, Cols1>& lhs, |
madcowswe | 0:feb4117d16d8 | 195 | const XprMatrix<E2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 196 | |
madcowswe | 0:feb4117d16d8 | 197 | |
madcowswe | 0:feb4117d16d8 | 198 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 199 | class E2, std::size_t Cols2> |
madcowswe | 0:feb4117d16d8 | 200 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 201 | XprMMProductTransposed< |
madcowswe | 0:feb4117d16d8 | 202 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 203 | XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
madcowswe | 0:feb4117d16d8 | 204 | >, |
madcowswe | 0:feb4117d16d8 | 205 | Cols2, Rows1 // return Dim |
madcowswe | 0:feb4117d16d8 | 206 | > |
madcowswe | 0:feb4117d16d8 | 207 | trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, |
madcowswe | 0:feb4117d16d8 | 208 | const XprMatrix<E2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 209 | |
madcowswe | 0:feb4117d16d8 | 210 | |
madcowswe | 0:feb4117d16d8 | 211 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 212 | class E2, std::size_t Cols2> // Rows2 = Rows1 |
madcowswe | 0:feb4117d16d8 | 213 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 214 | XprMtMProduct< |
madcowswe | 0:feb4117d16d8 | 215 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 216 | XprMatrix<E2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2) |
madcowswe | 0:feb4117d16d8 | 217 | >, |
madcowswe | 0:feb4117d16d8 | 218 | Cols1, Cols2 // return Dim |
madcowswe | 0:feb4117d16d8 | 219 | > |
madcowswe | 0:feb4117d16d8 | 220 | MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, |
madcowswe | 0:feb4117d16d8 | 221 | const XprMatrix<E2, Rows1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 222 | |
madcowswe | 0:feb4117d16d8 | 223 | |
madcowswe | 0:feb4117d16d8 | 224 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 225 | class E2, std::size_t Rows2> // Cols2 = Cols1 |
madcowswe | 0:feb4117d16d8 | 226 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 227 | XprMMtProduct< |
madcowswe | 0:feb4117d16d8 | 228 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 229 | XprMatrix<E2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1) |
madcowswe | 0:feb4117d16d8 | 230 | >, |
madcowswe | 0:feb4117d16d8 | 231 | Rows1, Rows2 // return Dim |
madcowswe | 0:feb4117d16d8 | 232 | > |
madcowswe | 0:feb4117d16d8 | 233 | MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, |
madcowswe | 0:feb4117d16d8 | 234 | const XprMatrix<E2, Rows2, Cols1>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 235 | |
madcowswe | 0:feb4117d16d8 | 236 | |
madcowswe | 0:feb4117d16d8 | 237 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 238 | * matrix-vector specific prod( ... ) functions |
madcowswe | 0:feb4117d16d8 | 239 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 240 | |
madcowswe | 0:feb4117d16d8 | 241 | |
madcowswe | 0:feb4117d16d8 | 242 | template<class E1, std::size_t Rows, std::size_t Cols, |
madcowswe | 0:feb4117d16d8 | 243 | class E2> |
madcowswe | 0:feb4117d16d8 | 244 | XprVector< |
madcowswe | 0:feb4117d16d8 | 245 | XprMVProduct< |
madcowswe | 0:feb4117d16d8 | 246 | XprMatrix<E1, Rows, Cols>, Rows, Cols, |
madcowswe | 0:feb4117d16d8 | 247 | XprVector<E2, Cols> |
madcowswe | 0:feb4117d16d8 | 248 | >, |
madcowswe | 0:feb4117d16d8 | 249 | Rows |
madcowswe | 0:feb4117d16d8 | 250 | > |
madcowswe | 0:feb4117d16d8 | 251 | prod(const XprMatrix<E1, Rows, Cols>& lhs, |
madcowswe | 0:feb4117d16d8 | 252 | const XprVector<E2, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 253 | |
madcowswe | 0:feb4117d16d8 | 254 | |
madcowswe | 0:feb4117d16d8 | 255 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 256 | * matrix specific functions |
madcowswe | 0:feb4117d16d8 | 257 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 258 | |
madcowswe | 0:feb4117d16d8 | 259 | |
madcowswe | 0:feb4117d16d8 | 260 | template<class E, std::size_t Rows, std::size_t Cols> |
madcowswe | 0:feb4117d16d8 | 261 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 262 | XprMatrixTranspose< |
madcowswe | 0:feb4117d16d8 | 263 | XprMatrix<E, Rows, Cols> |
madcowswe | 0:feb4117d16d8 | 264 | >, |
madcowswe | 0:feb4117d16d8 | 265 | Cols, Rows |
madcowswe | 0:feb4117d16d8 | 266 | > |
madcowswe | 0:feb4117d16d8 | 267 | trans(const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 268 | |
madcowswe | 0:feb4117d16d8 | 269 | |
madcowswe | 0:feb4117d16d8 | 270 | template<class E, std::size_t Sz> |
madcowswe | 0:feb4117d16d8 | 271 | typename NumericTraits<typename E::value_type>::sum_type |
madcowswe | 0:feb4117d16d8 | 272 | trace(const XprMatrix<E, Sz, Sz>& m) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 273 | |
madcowswe | 0:feb4117d16d8 | 274 | |
madcowswe | 0:feb4117d16d8 | 275 | template<class E, std::size_t Rows, std::size_t Cols> |
madcowswe | 0:feb4117d16d8 | 276 | XprVector< |
madcowswe | 0:feb4117d16d8 | 277 | XprMatrixRow< |
madcowswe | 0:feb4117d16d8 | 278 | XprMatrix<E, Rows, Cols>, |
madcowswe | 0:feb4117d16d8 | 279 | Rows, Cols |
madcowswe | 0:feb4117d16d8 | 280 | >, |
madcowswe | 0:feb4117d16d8 | 281 | Cols |
madcowswe | 0:feb4117d16d8 | 282 | > |
madcowswe | 0:feb4117d16d8 | 283 | row(const XprMatrix<E, Rows, Cols>& m, |
madcowswe | 0:feb4117d16d8 | 284 | std::size_t no) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 285 | |
madcowswe | 0:feb4117d16d8 | 286 | |
madcowswe | 0:feb4117d16d8 | 287 | template<class E, std::size_t Rows, std::size_t Cols> |
madcowswe | 0:feb4117d16d8 | 288 | XprVector< |
madcowswe | 0:feb4117d16d8 | 289 | XprMatrixCol< |
madcowswe | 0:feb4117d16d8 | 290 | XprMatrix<E, Rows, Cols>, |
madcowswe | 0:feb4117d16d8 | 291 | Rows, Cols |
madcowswe | 0:feb4117d16d8 | 292 | >, |
madcowswe | 0:feb4117d16d8 | 293 | Rows |
madcowswe | 0:feb4117d16d8 | 294 | > |
madcowswe | 0:feb4117d16d8 | 295 | col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 296 | |
madcowswe | 0:feb4117d16d8 | 297 | |
madcowswe | 0:feb4117d16d8 | 298 | template<class E, std::size_t Sz> |
madcowswe | 0:feb4117d16d8 | 299 | XprVector< |
madcowswe | 0:feb4117d16d8 | 300 | XprMatrixDiag< |
madcowswe | 0:feb4117d16d8 | 301 | XprMatrix<E, Sz, Sz>, |
madcowswe | 0:feb4117d16d8 | 302 | Sz |
madcowswe | 0:feb4117d16d8 | 303 | >, |
madcowswe | 0:feb4117d16d8 | 304 | Sz |
madcowswe | 0:feb4117d16d8 | 305 | > |
madcowswe | 0:feb4117d16d8 | 306 | diag(const XprMatrix<E, Sz, Sz>& m) TVMET_CXX_ALWAYS_INLINE; |
madcowswe | 0:feb4117d16d8 | 307 | |
madcowswe | 0:feb4117d16d8 | 308 | |
madcowswe | 0:feb4117d16d8 | 309 | /********************************************************* |
madcowswe | 0:feb4117d16d8 | 310 | * PART II: IMPLEMENTATION |
madcowswe | 0:feb4117d16d8 | 311 | *********************************************************/ |
madcowswe | 0:feb4117d16d8 | 312 | |
madcowswe | 0:feb4117d16d8 | 313 | |
madcowswe | 0:feb4117d16d8 | 314 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 315 | * Matrix arithmetic functions add, sub, mul and div |
madcowswe | 0:feb4117d16d8 | 316 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 317 | |
madcowswe | 0:feb4117d16d8 | 318 | |
madcowswe | 0:feb4117d16d8 | 319 | /* |
madcowswe | 0:feb4117d16d8 | 320 | * function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>) |
madcowswe | 0:feb4117d16d8 | 321 | */ |
madcowswe | 0:feb4117d16d8 | 322 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
madcowswe | 0:feb4117d16d8 | 323 | template<class E1, class E2, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 324 | inline \ |
madcowswe | 0:feb4117d16d8 | 325 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 326 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 327 | Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 328 | XprMatrix<E1, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 329 | XprMatrix<E2, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 330 | >, \ |
madcowswe | 0:feb4117d16d8 | 331 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 332 | > \ |
madcowswe | 0:feb4117d16d8 | 333 | NAME (const XprMatrix<E1, Rows, Cols>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 334 | const XprMatrix<E2, Rows, Cols>& rhs) { \ |
madcowswe | 0:feb4117d16d8 | 335 | typedef XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 336 | Fcnl_##NAME<typename E1::value_type, typename E2::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 337 | XprMatrix<E1, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 338 | XprMatrix<E2, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 339 | > expr_type; \ |
madcowswe | 0:feb4117d16d8 | 340 | return XprMatrix<expr_type, Rows, Cols>(expr_type(lhs, rhs)); \ |
madcowswe | 0:feb4117d16d8 | 341 | } |
madcowswe | 0:feb4117d16d8 | 342 | |
madcowswe | 0:feb4117d16d8 | 343 | TVMET_IMPLEMENT_MACRO(add) // per se element wise |
madcowswe | 0:feb4117d16d8 | 344 | TVMET_IMPLEMENT_MACRO(sub) // per se element wise |
madcowswe | 0:feb4117d16d8 | 345 | namespace element_wise { |
madcowswe | 0:feb4117d16d8 | 346 | TVMET_IMPLEMENT_MACRO(mul) // not defined for matrizes |
madcowswe | 0:feb4117d16d8 | 347 | TVMET_IMPLEMENT_MACRO(div) // not defined for matrizes |
madcowswe | 0:feb4117d16d8 | 348 | } |
madcowswe | 0:feb4117d16d8 | 349 | |
madcowswe | 0:feb4117d16d8 | 350 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 0:feb4117d16d8 | 351 | |
madcowswe | 0:feb4117d16d8 | 352 | |
madcowswe | 0:feb4117d16d8 | 353 | /* |
madcowswe | 0:feb4117d16d8 | 354 | * function(XprMatrix<E, Rows, Cols>, POD) |
madcowswe | 0:feb4117d16d8 | 355 | * function(POD, XprMatrix<E, Rows, Cols>) |
madcowswe | 0:feb4117d16d8 | 356 | * Note: - operations +,-,*,/ are per se element wise |
madcowswe | 0:feb4117d16d8 | 357 | */ |
madcowswe | 0:feb4117d16d8 | 358 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
madcowswe | 0:feb4117d16d8 | 359 | template<class E, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 360 | inline \ |
madcowswe | 0:feb4117d16d8 | 361 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 362 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 363 | Fcnl_##NAME<typename E::value_type, POD >, \ |
madcowswe | 0:feb4117d16d8 | 364 | XprMatrix<E, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 365 | XprLiteral< POD > \ |
madcowswe | 0:feb4117d16d8 | 366 | >, \ |
madcowswe | 0:feb4117d16d8 | 367 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 368 | > \ |
madcowswe | 0:feb4117d16d8 | 369 | NAME (const XprMatrix<E, Rows, Cols>& lhs, POD rhs) { \ |
madcowswe | 0:feb4117d16d8 | 370 | typedef XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 371 | Fcnl_##NAME<typename E::value_type, POD >, \ |
madcowswe | 0:feb4117d16d8 | 372 | XprMatrix<E, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 373 | XprLiteral< POD > \ |
madcowswe | 0:feb4117d16d8 | 374 | > expr_type; \ |
madcowswe | 0:feb4117d16d8 | 375 | return XprMatrix<expr_type, Rows, Cols>( \ |
madcowswe | 0:feb4117d16d8 | 376 | expr_type(lhs, XprLiteral< POD >(rhs))); \ |
madcowswe | 0:feb4117d16d8 | 377 | } \ |
madcowswe | 0:feb4117d16d8 | 378 | \ |
madcowswe | 0:feb4117d16d8 | 379 | template<class E, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 380 | inline \ |
madcowswe | 0:feb4117d16d8 | 381 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 382 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 383 | Fcnl_##NAME< POD, typename E::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 384 | XprLiteral< POD >, \ |
madcowswe | 0:feb4117d16d8 | 385 | XprMatrix<E, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 386 | >, \ |
madcowswe | 0:feb4117d16d8 | 387 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 388 | > \ |
madcowswe | 0:feb4117d16d8 | 389 | NAME (POD lhs, const XprMatrix<E, Rows, Cols>& rhs) { \ |
madcowswe | 0:feb4117d16d8 | 390 | typedef XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 391 | Fcnl_##NAME< POD, typename E::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 392 | XprLiteral< POD >, \ |
madcowswe | 0:feb4117d16d8 | 393 | XprMatrix<E, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 394 | > expr_type; \ |
madcowswe | 0:feb4117d16d8 | 395 | return XprMatrix<expr_type, Rows, Cols>( \ |
madcowswe | 0:feb4117d16d8 | 396 | expr_type(XprLiteral< POD >(lhs), rhs)); \ |
madcowswe | 0:feb4117d16d8 | 397 | } |
madcowswe | 0:feb4117d16d8 | 398 | |
madcowswe | 0:feb4117d16d8 | 399 | TVMET_IMPLEMENT_MACRO(add, int) |
madcowswe | 0:feb4117d16d8 | 400 | TVMET_IMPLEMENT_MACRO(sub, int) |
madcowswe | 0:feb4117d16d8 | 401 | TVMET_IMPLEMENT_MACRO(mul, int) |
madcowswe | 0:feb4117d16d8 | 402 | TVMET_IMPLEMENT_MACRO(div, int) |
madcowswe | 0:feb4117d16d8 | 403 | |
madcowswe | 0:feb4117d16d8 | 404 | #if defined(TVMET_HAVE_LONG_LONG) |
madcowswe | 0:feb4117d16d8 | 405 | TVMET_IMPLEMENT_MACRO(add, long long int) |
madcowswe | 0:feb4117d16d8 | 406 | TVMET_IMPLEMENT_MACRO(sub, long long int) |
madcowswe | 0:feb4117d16d8 | 407 | TVMET_IMPLEMENT_MACRO(mul, long long int) |
madcowswe | 0:feb4117d16d8 | 408 | TVMET_IMPLEMENT_MACRO(div, long long int) |
madcowswe | 0:feb4117d16d8 | 409 | #endif |
madcowswe | 0:feb4117d16d8 | 410 | |
madcowswe | 0:feb4117d16d8 | 411 | TVMET_IMPLEMENT_MACRO(add, float) |
madcowswe | 0:feb4117d16d8 | 412 | TVMET_IMPLEMENT_MACRO(sub, float) |
madcowswe | 0:feb4117d16d8 | 413 | TVMET_IMPLEMENT_MACRO(mul, float) |
madcowswe | 0:feb4117d16d8 | 414 | TVMET_IMPLEMENT_MACRO(div, float) |
madcowswe | 0:feb4117d16d8 | 415 | |
madcowswe | 0:feb4117d16d8 | 416 | TVMET_IMPLEMENT_MACRO(add, double) |
madcowswe | 0:feb4117d16d8 | 417 | TVMET_IMPLEMENT_MACRO(sub, double) |
madcowswe | 0:feb4117d16d8 | 418 | TVMET_IMPLEMENT_MACRO(mul, double) |
madcowswe | 0:feb4117d16d8 | 419 | TVMET_IMPLEMENT_MACRO(div, double) |
madcowswe | 0:feb4117d16d8 | 420 | |
madcowswe | 0:feb4117d16d8 | 421 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
madcowswe | 0:feb4117d16d8 | 422 | TVMET_IMPLEMENT_MACRO(add, long double) |
madcowswe | 0:feb4117d16d8 | 423 | TVMET_IMPLEMENT_MACRO(sub, long double) |
madcowswe | 0:feb4117d16d8 | 424 | TVMET_IMPLEMENT_MACRO(mul, long double) |
madcowswe | 0:feb4117d16d8 | 425 | TVMET_IMPLEMENT_MACRO(div, long double) |
madcowswe | 0:feb4117d16d8 | 426 | #endif |
madcowswe | 0:feb4117d16d8 | 427 | |
madcowswe | 0:feb4117d16d8 | 428 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 0:feb4117d16d8 | 429 | |
madcowswe | 0:feb4117d16d8 | 430 | |
madcowswe | 0:feb4117d16d8 | 431 | #if defined(TVMET_HAVE_COMPLEX) |
madcowswe | 0:feb4117d16d8 | 432 | /* |
madcowswe | 0:feb4117d16d8 | 433 | * function(XprMatrix<E, Rows, Cols>, complex<T>) |
madcowswe | 0:feb4117d16d8 | 434 | * function(complex<T>, XprMatrix<E, Rows, Cols>) |
madcowswe | 0:feb4117d16d8 | 435 | * Note: - operations +,-,*,/ are per se element wise |
madcowswe | 0:feb4117d16d8 | 436 | * \todo type promotion |
madcowswe | 0:feb4117d16d8 | 437 | */ |
madcowswe | 0:feb4117d16d8 | 438 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
madcowswe | 0:feb4117d16d8 | 439 | template<class E, class T, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 440 | inline \ |
madcowswe | 0:feb4117d16d8 | 441 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 442 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 443 | Fcnl_##NAME<typename E::value_type, std::complex<T> >, \ |
madcowswe | 0:feb4117d16d8 | 444 | XprMatrix<E, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 445 | XprLiteral< std::complex<T> > \ |
madcowswe | 0:feb4117d16d8 | 446 | >, \ |
madcowswe | 0:feb4117d16d8 | 447 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 448 | > \ |
madcowswe | 0:feb4117d16d8 | 449 | NAME (const XprMatrix<E, Rows, Cols>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 450 | const std::complex<T>& rhs) { \ |
madcowswe | 0:feb4117d16d8 | 451 | typedef XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 452 | Fcnl_##NAME<typename E::value_type, std::complex<T> >, \ |
madcowswe | 0:feb4117d16d8 | 453 | XprMatrix<E, Rows, Cols>, \ |
madcowswe | 0:feb4117d16d8 | 454 | XprLiteral< std::complex<T> > \ |
madcowswe | 0:feb4117d16d8 | 455 | > expr_type; \ |
madcowswe | 0:feb4117d16d8 | 456 | return XprMatrix<expr_type, Rows, Cols>( \ |
madcowswe | 0:feb4117d16d8 | 457 | expr_type(lhs, XprLiteral< std::complex<T> >(rhs))); \ |
madcowswe | 0:feb4117d16d8 | 458 | } \ |
madcowswe | 0:feb4117d16d8 | 459 | \ |
madcowswe | 0:feb4117d16d8 | 460 | template<class T, class E, std::size_t Rows, std::size_t Cols> \ |
madcowswe | 0:feb4117d16d8 | 461 | inline \ |
madcowswe | 0:feb4117d16d8 | 462 | XprMatrix< \ |
madcowswe | 0:feb4117d16d8 | 463 | XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 464 | Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 465 | XprLiteral< std::complex<T> >, \ |
madcowswe | 0:feb4117d16d8 | 466 | XprMatrix<E, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 467 | >, \ |
madcowswe | 0:feb4117d16d8 | 468 | Rows, Cols \ |
madcowswe | 0:feb4117d16d8 | 469 | > \ |
madcowswe | 0:feb4117d16d8 | 470 | NAME (const std::complex<T>& lhs, \ |
madcowswe | 0:feb4117d16d8 | 471 | const XprMatrix<E, Rows, Cols>& rhs) { \ |
madcowswe | 0:feb4117d16d8 | 472 | typedef XprBinOp< \ |
madcowswe | 0:feb4117d16d8 | 473 | Fcnl_##NAME< std::complex<T>, typename E::value_type>, \ |
madcowswe | 0:feb4117d16d8 | 474 | XprLiteral< std::complex<T> >, \ |
madcowswe | 0:feb4117d16d8 | 475 | XprMatrix<E, Rows, Cols> \ |
madcowswe | 0:feb4117d16d8 | 476 | > expr_type; \ |
madcowswe | 0:feb4117d16d8 | 477 | return XprMatrix<expr_type, Rows, Cols>( \ |
madcowswe | 0:feb4117d16d8 | 478 | expr_type(XprLiteral< std::complex<T> >(lhs), rhs)); \ |
madcowswe | 0:feb4117d16d8 | 479 | } |
madcowswe | 0:feb4117d16d8 | 480 | |
madcowswe | 0:feb4117d16d8 | 481 | TVMET_IMPLEMENT_MACRO(add) |
madcowswe | 0:feb4117d16d8 | 482 | TVMET_IMPLEMENT_MACRO(sub) |
madcowswe | 0:feb4117d16d8 | 483 | TVMET_IMPLEMENT_MACRO(mul) |
madcowswe | 0:feb4117d16d8 | 484 | TVMET_IMPLEMENT_MACRO(div) |
madcowswe | 0:feb4117d16d8 | 485 | |
madcowswe | 0:feb4117d16d8 | 486 | #undef TVMET_IMPLEMENT_MACRO |
madcowswe | 0:feb4117d16d8 | 487 | |
madcowswe | 0:feb4117d16d8 | 488 | #endif // defined(TVMET_HAVE_COMPLEX) |
madcowswe | 0:feb4117d16d8 | 489 | |
madcowswe | 0:feb4117d16d8 | 490 | |
madcowswe | 0:feb4117d16d8 | 491 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 492 | * matrix prod( ... ) functions |
madcowswe | 0:feb4117d16d8 | 493 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 494 | |
madcowswe | 0:feb4117d16d8 | 495 | |
madcowswe | 0:feb4117d16d8 | 496 | /** |
madcowswe | 0:feb4117d16d8 | 497 | * \fn prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) |
madcowswe | 0:feb4117d16d8 | 498 | * \brief Evaluate the product of two XprMatrix. |
madcowswe | 0:feb4117d16d8 | 499 | * Perform on given Matrix M1 and M2: |
madcowswe | 0:feb4117d16d8 | 500 | * \f[ |
madcowswe | 0:feb4117d16d8 | 501 | * M_1\,M_2 |
madcowswe | 0:feb4117d16d8 | 502 | * \f] |
madcowswe | 0:feb4117d16d8 | 503 | * \note The numer of Rows2 has to be equal to Cols1. |
madcowswe | 0:feb4117d16d8 | 504 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 505 | */ |
madcowswe | 0:feb4117d16d8 | 506 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 507 | class E2, std::size_t Cols2> |
madcowswe | 0:feb4117d16d8 | 508 | inline |
madcowswe | 0:feb4117d16d8 | 509 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 510 | XprMMProduct< |
madcowswe | 0:feb4117d16d8 | 511 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 512 | XprMatrix<E2, Cols1, Cols2>, Cols2 |
madcowswe | 0:feb4117d16d8 | 513 | >, |
madcowswe | 0:feb4117d16d8 | 514 | Rows1, Cols2 // return Dim |
madcowswe | 0:feb4117d16d8 | 515 | > |
madcowswe | 0:feb4117d16d8 | 516 | prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) { |
madcowswe | 0:feb4117d16d8 | 517 | typedef XprMMProduct< |
madcowswe | 0:feb4117d16d8 | 518 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, |
madcowswe | 0:feb4117d16d8 | 519 | XprMatrix<E2, Cols1, Cols2>, Cols2 |
madcowswe | 0:feb4117d16d8 | 520 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 521 | return XprMatrix<expr_type, Rows1, Cols2>(expr_type(lhs, rhs)); |
madcowswe | 0:feb4117d16d8 | 522 | } |
madcowswe | 0:feb4117d16d8 | 523 | |
madcowswe | 0:feb4117d16d8 | 524 | |
madcowswe | 0:feb4117d16d8 | 525 | /** |
madcowswe | 0:feb4117d16d8 | 526 | * \fn trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) |
madcowswe | 0:feb4117d16d8 | 527 | * \brief Function for the trans(matrix-matrix-product) |
madcowswe | 0:feb4117d16d8 | 528 | * Perform on given Matrix M1 and M2: |
madcowswe | 0:feb4117d16d8 | 529 | * \f[ |
madcowswe | 0:feb4117d16d8 | 530 | * (M_1\,M_2)^T |
madcowswe | 0:feb4117d16d8 | 531 | * \f] |
madcowswe | 0:feb4117d16d8 | 532 | * \note The numer of Rows2 has to be equal to Cols1. |
madcowswe | 0:feb4117d16d8 | 533 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 534 | */ |
madcowswe | 0:feb4117d16d8 | 535 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 536 | class E2, std::size_t Cols2> |
madcowswe | 0:feb4117d16d8 | 537 | inline |
madcowswe | 0:feb4117d16d8 | 538 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 539 | XprMMProductTransposed< |
madcowswe | 0:feb4117d16d8 | 540 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 541 | XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
madcowswe | 0:feb4117d16d8 | 542 | >, |
madcowswe | 0:feb4117d16d8 | 543 | Cols2, Rows1 // return Dim |
madcowswe | 0:feb4117d16d8 | 544 | > |
madcowswe | 0:feb4117d16d8 | 545 | trans_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) { |
madcowswe | 0:feb4117d16d8 | 546 | typedef XprMMProductTransposed< |
madcowswe | 0:feb4117d16d8 | 547 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, |
madcowswe | 0:feb4117d16d8 | 548 | XprMatrix<E2, Cols1, Cols2>, Cols2 |
madcowswe | 0:feb4117d16d8 | 549 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 550 | return XprMatrix<expr_type, Cols2, Rows1>(expr_type(lhs, rhs)); |
madcowswe | 0:feb4117d16d8 | 551 | } |
madcowswe | 0:feb4117d16d8 | 552 | |
madcowswe | 0:feb4117d16d8 | 553 | |
madcowswe | 0:feb4117d16d8 | 554 | /** |
madcowswe | 0:feb4117d16d8 | 555 | * \fn MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows1, Cols2>& rhs) |
madcowswe | 0:feb4117d16d8 | 556 | * \brief Function for the trans(matrix)-matrix-product. |
madcowswe | 0:feb4117d16d8 | 557 | * using formula |
madcowswe | 0:feb4117d16d8 | 558 | * \f[ |
madcowswe | 0:feb4117d16d8 | 559 | * M_1^{T}\,M_2 |
madcowswe | 0:feb4117d16d8 | 560 | * \f] |
madcowswe | 0:feb4117d16d8 | 561 | * \note The number of cols of matrix 2 have to be equal to number of rows of |
madcowswe | 0:feb4117d16d8 | 562 | * matrix 1, since matrix 1 is trans - the result is a (Cols1 x Cols2) |
madcowswe | 0:feb4117d16d8 | 563 | * matrix. |
madcowswe | 0:feb4117d16d8 | 564 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 565 | */ |
madcowswe | 0:feb4117d16d8 | 566 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 567 | class E2, std::size_t Cols2> // Rows2 = Rows1 |
madcowswe | 0:feb4117d16d8 | 568 | inline |
madcowswe | 0:feb4117d16d8 | 569 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 570 | XprMtMProduct< |
madcowswe | 0:feb4117d16d8 | 571 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 572 | XprMatrix<E2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2) |
madcowswe | 0:feb4117d16d8 | 573 | >, |
madcowswe | 0:feb4117d16d8 | 574 | Cols1, Cols2 // return Dim |
madcowswe | 0:feb4117d16d8 | 575 | > |
madcowswe | 0:feb4117d16d8 | 576 | MtM_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows1, Cols2>& rhs) { |
madcowswe | 0:feb4117d16d8 | 577 | typedef XprMtMProduct< |
madcowswe | 0:feb4117d16d8 | 578 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, |
madcowswe | 0:feb4117d16d8 | 579 | XprMatrix<E2, Rows1, Cols2>, Cols2 |
madcowswe | 0:feb4117d16d8 | 580 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 581 | return XprMatrix<expr_type, Cols1, Cols2>(expr_type(lhs, rhs)); |
madcowswe | 0:feb4117d16d8 | 582 | } |
madcowswe | 0:feb4117d16d8 | 583 | |
madcowswe | 0:feb4117d16d8 | 584 | |
madcowswe | 0:feb4117d16d8 | 585 | /** |
madcowswe | 0:feb4117d16d8 | 586 | * \fn MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows2, Cols1>& rhs) |
madcowswe | 0:feb4117d16d8 | 587 | * \brief Function for the matrix-trans(matrix)-product. |
madcowswe | 0:feb4117d16d8 | 588 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 589 | * \note The cols2 has to be equal to cols1. |
madcowswe | 0:feb4117d16d8 | 590 | */ |
madcowswe | 0:feb4117d16d8 | 591 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
madcowswe | 0:feb4117d16d8 | 592 | class E2, std::size_t Rows2> // Cols2 = Cols1 |
madcowswe | 0:feb4117d16d8 | 593 | inline |
madcowswe | 0:feb4117d16d8 | 594 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 595 | XprMMtProduct< |
madcowswe | 0:feb4117d16d8 | 596 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
madcowswe | 0:feb4117d16d8 | 597 | XprMatrix<E2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1) |
madcowswe | 0:feb4117d16d8 | 598 | >, |
madcowswe | 0:feb4117d16d8 | 599 | Rows1, Rows2 // return Dim |
madcowswe | 0:feb4117d16d8 | 600 | > |
madcowswe | 0:feb4117d16d8 | 601 | MMt_prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const XprMatrix<E2, Rows2, Cols1>& rhs) { |
madcowswe | 0:feb4117d16d8 | 602 | typedef XprMMtProduct< |
madcowswe | 0:feb4117d16d8 | 603 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, |
madcowswe | 0:feb4117d16d8 | 604 | XprMatrix<E2, Rows2, Cols1>, Cols1 |
madcowswe | 0:feb4117d16d8 | 605 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 606 | return XprMatrix<expr_type, Rows1, Rows2>(expr_type(lhs, rhs)); |
madcowswe | 0:feb4117d16d8 | 607 | } |
madcowswe | 0:feb4117d16d8 | 608 | |
madcowswe | 0:feb4117d16d8 | 609 | |
madcowswe | 0:feb4117d16d8 | 610 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 611 | * matrix-vector specific prod( ... ) functions |
madcowswe | 0:feb4117d16d8 | 612 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 613 | |
madcowswe | 0:feb4117d16d8 | 614 | |
madcowswe | 0:feb4117d16d8 | 615 | /** |
madcowswe | 0:feb4117d16d8 | 616 | * \fn prod(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) |
madcowswe | 0:feb4117d16d8 | 617 | * \brief Evaluate the product of XprMatrix and XprVector. |
madcowswe | 0:feb4117d16d8 | 618 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 619 | */ |
madcowswe | 0:feb4117d16d8 | 620 | template<class E1, std::size_t Rows, std::size_t Cols, |
madcowswe | 0:feb4117d16d8 | 621 | class E2> |
madcowswe | 0:feb4117d16d8 | 622 | inline |
madcowswe | 0:feb4117d16d8 | 623 | XprVector< |
madcowswe | 0:feb4117d16d8 | 624 | XprMVProduct< |
madcowswe | 0:feb4117d16d8 | 625 | XprMatrix<E1, Rows, Cols>, Rows, Cols, |
madcowswe | 0:feb4117d16d8 | 626 | XprVector<E2, Cols> |
madcowswe | 0:feb4117d16d8 | 627 | >, |
madcowswe | 0:feb4117d16d8 | 628 | Rows |
madcowswe | 0:feb4117d16d8 | 629 | > |
madcowswe | 0:feb4117d16d8 | 630 | prod(const XprMatrix<E1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) { |
madcowswe | 0:feb4117d16d8 | 631 | typedef XprMVProduct< |
madcowswe | 0:feb4117d16d8 | 632 | XprMatrix<E1, Rows, Cols>, Rows, Cols, |
madcowswe | 0:feb4117d16d8 | 633 | XprVector<E2, Cols> |
madcowswe | 0:feb4117d16d8 | 634 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 635 | return XprVector<expr_type, Rows>(expr_type(lhs, rhs)); |
madcowswe | 0:feb4117d16d8 | 636 | } |
madcowswe | 0:feb4117d16d8 | 637 | |
madcowswe | 0:feb4117d16d8 | 638 | |
madcowswe | 0:feb4117d16d8 | 639 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
madcowswe | 0:feb4117d16d8 | 640 | * matrix specific functions |
madcowswe | 0:feb4117d16d8 | 641 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
madcowswe | 0:feb4117d16d8 | 642 | |
madcowswe | 0:feb4117d16d8 | 643 | |
madcowswe | 0:feb4117d16d8 | 644 | /** |
madcowswe | 0:feb4117d16d8 | 645 | * \fn trans(const XprMatrix<E, Rows, Cols>& rhs) |
madcowswe | 0:feb4117d16d8 | 646 | * \brief Transpose an expression matrix. |
madcowswe | 0:feb4117d16d8 | 647 | * \ingroup _unary_function |
madcowswe | 0:feb4117d16d8 | 648 | */ |
madcowswe | 0:feb4117d16d8 | 649 | template<class E, std::size_t Rows, std::size_t Cols> |
madcowswe | 0:feb4117d16d8 | 650 | inline |
madcowswe | 0:feb4117d16d8 | 651 | XprMatrix< |
madcowswe | 0:feb4117d16d8 | 652 | XprMatrixTranspose< |
madcowswe | 0:feb4117d16d8 | 653 | XprMatrix<E, Rows, Cols> |
madcowswe | 0:feb4117d16d8 | 654 | >, |
madcowswe | 0:feb4117d16d8 | 655 | Cols, Rows |
madcowswe | 0:feb4117d16d8 | 656 | > |
madcowswe | 0:feb4117d16d8 | 657 | trans(const XprMatrix<E, Rows, Cols>& rhs) { |
madcowswe | 0:feb4117d16d8 | 658 | typedef XprMatrixTranspose< |
madcowswe | 0:feb4117d16d8 | 659 | XprMatrix<E, Rows, Cols> |
madcowswe | 0:feb4117d16d8 | 660 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 661 | return XprMatrix<expr_type, Cols, Rows>(expr_type(rhs)); |
madcowswe | 0:feb4117d16d8 | 662 | } |
madcowswe | 0:feb4117d16d8 | 663 | |
madcowswe | 0:feb4117d16d8 | 664 | |
madcowswe | 0:feb4117d16d8 | 665 | /* |
madcowswe | 0:feb4117d16d8 | 666 | * \fn trace(const XprMatrix<E, Sz, Sz>& m) |
madcowswe | 0:feb4117d16d8 | 667 | * \brief Compute the trace of a square matrix. |
madcowswe | 0:feb4117d16d8 | 668 | * \ingroup _unary_function |
madcowswe | 0:feb4117d16d8 | 669 | * |
madcowswe | 0:feb4117d16d8 | 670 | * Simply compute the trace of the given matrix expression as: |
madcowswe | 0:feb4117d16d8 | 671 | * \f[ |
madcowswe | 0:feb4117d16d8 | 672 | * \sum_{k = 0}^{Sz-1} m(k, k) |
madcowswe | 0:feb4117d16d8 | 673 | * \f] |
madcowswe | 0:feb4117d16d8 | 674 | */ |
madcowswe | 0:feb4117d16d8 | 675 | template<class E, std::size_t Sz> |
madcowswe | 0:feb4117d16d8 | 676 | inline |
madcowswe | 0:feb4117d16d8 | 677 | typename NumericTraits<typename E::value_type>::sum_type |
madcowswe | 0:feb4117d16d8 | 678 | trace(const XprMatrix<E, Sz, Sz>& m) { |
madcowswe | 0:feb4117d16d8 | 679 | return meta::Matrix<Sz, Sz, 0, 0>::trace(m); |
madcowswe | 0:feb4117d16d8 | 680 | } |
madcowswe | 0:feb4117d16d8 | 681 | |
madcowswe | 0:feb4117d16d8 | 682 | |
madcowswe | 0:feb4117d16d8 | 683 | /** |
madcowswe | 0:feb4117d16d8 | 684 | * \fn row(const XprMatrix<E, Rows, Cols>& m, std::size_t no) |
madcowswe | 0:feb4117d16d8 | 685 | * \brief Returns a row vector of the given matrix. |
madcowswe | 0:feb4117d16d8 | 686 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 687 | */ |
madcowswe | 0:feb4117d16d8 | 688 | template<class E, std::size_t Rows, std::size_t Cols> |
madcowswe | 0:feb4117d16d8 | 689 | inline |
madcowswe | 0:feb4117d16d8 | 690 | XprVector< |
madcowswe | 0:feb4117d16d8 | 691 | XprMatrixRow< |
madcowswe | 0:feb4117d16d8 | 692 | XprMatrix<E, Rows, Cols>, |
madcowswe | 0:feb4117d16d8 | 693 | Rows, Cols |
madcowswe | 0:feb4117d16d8 | 694 | >, |
madcowswe | 0:feb4117d16d8 | 695 | Cols |
madcowswe | 0:feb4117d16d8 | 696 | > |
madcowswe | 0:feb4117d16d8 | 697 | row(const XprMatrix<E, Rows, Cols>& m, std::size_t no) { |
madcowswe | 0:feb4117d16d8 | 698 | typedef XprMatrixRow< |
madcowswe | 0:feb4117d16d8 | 699 | XprMatrix<E, Rows, Cols>, |
madcowswe | 0:feb4117d16d8 | 700 | Rows, Cols |
madcowswe | 0:feb4117d16d8 | 701 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 702 | |
madcowswe | 0:feb4117d16d8 | 703 | return XprVector<expr_type, Cols>(expr_type(m, no)); |
madcowswe | 0:feb4117d16d8 | 704 | } |
madcowswe | 0:feb4117d16d8 | 705 | |
madcowswe | 0:feb4117d16d8 | 706 | |
madcowswe | 0:feb4117d16d8 | 707 | /** |
madcowswe | 0:feb4117d16d8 | 708 | * \fn col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) |
madcowswe | 0:feb4117d16d8 | 709 | * \brief Returns a column vector of the given matrix. |
madcowswe | 0:feb4117d16d8 | 710 | * \ingroup _binary_function |
madcowswe | 0:feb4117d16d8 | 711 | */ |
madcowswe | 0:feb4117d16d8 | 712 | template<class E, std::size_t Rows, std::size_t Cols> |
madcowswe | 0:feb4117d16d8 | 713 | inline |
madcowswe | 0:feb4117d16d8 | 714 | XprVector< |
madcowswe | 0:feb4117d16d8 | 715 | XprMatrixCol< |
madcowswe | 0:feb4117d16d8 | 716 | XprMatrix<E, Rows, Cols>, |
madcowswe | 0:feb4117d16d8 | 717 | Rows, Cols |
madcowswe | 0:feb4117d16d8 | 718 | >, |
madcowswe | 0:feb4117d16d8 | 719 | Rows |
madcowswe | 0:feb4117d16d8 | 720 | > |
madcowswe | 0:feb4117d16d8 | 721 | col(const XprMatrix<E, Rows, Cols>& m, std::size_t no) { |
madcowswe | 0:feb4117d16d8 | 722 | typedef XprMatrixCol< |
madcowswe | 0:feb4117d16d8 | 723 | XprMatrix<E, Rows, Cols>, |
madcowswe | 0:feb4117d16d8 | 724 | Rows, Cols |
madcowswe | 0:feb4117d16d8 | 725 | > expr_type; |
madcowswe | 0:feb4117d16d8 | 726 | |
madcowswe | 0:feb4117d16d8 | 727 | return XprVector<expr_type, Cols>(expr_type(m, no)); |
madcowswe | 0:feb4117d16d8 | 728 | } |
madcowswe | 0:feb4117d16d8 | 729 | |
madcowswe | 0:feb4117d16d8 | 730 | |
madcowswe | 0:feb4117d16d8 | 731 | /** |
madcowswe | 0:feb4117d16d8 | 732 | * \fn diag(const XprMatrix<E, Sz, Sz>& m) |
madcowswe | 0:feb4117d16d8 | 733 | * \brief Returns the diagonal vector of the given square matrix. |
madcowswe | 0:feb4117d16d8 | 734 | * \ingroup _unary_function |
madcowswe | 0:feb4117d16d8 | 735 | */ |
madcowswe | 0:feb4117d16d8 | 736 | template<class E, std::size_t Sz> |
madcowswe | 0:feb4117d16d8 | 737 | inline |
madcowswe | 0:feb4117d16d8 | 738 | XprVector< |
madcowswe | 0:feb4117d16d8 | 739 | XprMatrixDiag< |
madcowswe | 0:feb4117d16d8 | 740 | XprMatrix<E, Sz, Sz>, |
madcowswe | 0:feb4117d16d8 | 741 | Sz |
madcowswe | 0:feb4117d16d8 | 742 | >, |
madcowswe | 0:feb4117d16d8 | 743 | Sz |
madcowswe | 0:feb4117d16d8 | 744 | > |
madcowswe | 0:feb4117d16d8 | 745 | diag(const XprMatrix<E, Sz, Sz>& m) { |
madcowswe | 0:feb4117d16d8 | 746 | typedef XprMatrixDiag< |
madcowswe | 0:feb4117d16d8 | 747 | XprMatrix<E, Sz, Sz>, |
madcowswe | 0:feb4117d16d8 | 748 | Sz> expr_type; |
madcowswe | 0:feb4117d16d8 | 749 | |
madcowswe | 0:feb4117d16d8 | 750 | return XprVector<expr_type, Sz>(expr_type(m)); |
madcowswe | 0:feb4117d16d8 | 751 | } |
madcowswe | 0:feb4117d16d8 | 752 | |
madcowswe | 0:feb4117d16d8 | 753 | |
madcowswe | 0:feb4117d16d8 | 754 | } // namespace tvmet |
madcowswe | 0:feb4117d16d8 | 755 | |
madcowswe | 0:feb4117d16d8 | 756 | #endif // TVMET_XPR_MATRIX_FUNCTIONS_H |
madcowswe | 0:feb4117d16d8 | 757 | |
madcowswe | 0:feb4117d16d8 | 758 | // Local Variables: |
madcowswe | 0:feb4117d16d8 | 759 | // mode:C++ |
madcowswe | 0:feb4117d16d8 | 760 | // tab-width:8 |
madcowswe | 0:feb4117d16d8 | 761 | // End: |