Oskar Weigl
/
Eurobot2013
We are going to win! wohoo
tvmet/MatrixFunctions.h@1:6799c07fe510, 2012-11-07 (annotated)
- Committer:
- sv
- Date:
- Wed Nov 07 14:37:35 2012 +0000
- Revision:
- 1:6799c07fe510
Preliminary copy of 2012 code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sv | 1:6799c07fe510 | 1 | /* |
sv | 1:6799c07fe510 | 2 | * Tiny Vector Matrix Library |
sv | 1:6799c07fe510 | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
sv | 1:6799c07fe510 | 4 | * |
sv | 1:6799c07fe510 | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
sv | 1:6799c07fe510 | 6 | * |
sv | 1:6799c07fe510 | 7 | * This library is free software; you can redistribute it and/or |
sv | 1:6799c07fe510 | 8 | * modify it under the terms of the GNU lesser General Public |
sv | 1:6799c07fe510 | 9 | * License as published by the Free Software Foundation; either |
sv | 1:6799c07fe510 | 10 | * version 2.1 of the License, or (at your option) any later version. |
sv | 1:6799c07fe510 | 11 | * |
sv | 1:6799c07fe510 | 12 | * This library is distributed in the hope that it will be useful, |
sv | 1:6799c07fe510 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
sv | 1:6799c07fe510 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
sv | 1:6799c07fe510 | 15 | * lesser General Public License for more details. |
sv | 1:6799c07fe510 | 16 | * |
sv | 1:6799c07fe510 | 17 | * You should have received a copy of the GNU lesser General Public |
sv | 1:6799c07fe510 | 18 | * License along with this library; if not, write to the Free Software |
sv | 1:6799c07fe510 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
sv | 1:6799c07fe510 | 20 | * |
sv | 1:6799c07fe510 | 21 | * $Id: MatrixFunctions.h,v 1.65 2007-06-23 15:58:58 opetzold Exp $ |
sv | 1:6799c07fe510 | 22 | */ |
sv | 1:6799c07fe510 | 23 | |
sv | 1:6799c07fe510 | 24 | #ifndef TVMET_MATRIX_FUNCTIONS_H |
sv | 1:6799c07fe510 | 25 | #define TVMET_MATRIX_FUNCTIONS_H |
sv | 1:6799c07fe510 | 26 | |
sv | 1:6799c07fe510 | 27 | #include <tvmet/Extremum.h> |
sv | 1:6799c07fe510 | 28 | |
sv | 1:6799c07fe510 | 29 | namespace tvmet { |
sv | 1:6799c07fe510 | 30 | |
sv | 1:6799c07fe510 | 31 | /* forwards */ |
sv | 1:6799c07fe510 | 32 | template<class T, std::size_t Sz> class Vector; |
sv | 1:6799c07fe510 | 33 | template<class T, std::size_t Sz> class VectorConstReference; |
sv | 1:6799c07fe510 | 34 | |
sv | 1:6799c07fe510 | 35 | |
sv | 1:6799c07fe510 | 36 | /********************************************************* |
sv | 1:6799c07fe510 | 37 | * PART I: DECLARATION |
sv | 1:6799c07fe510 | 38 | *********************************************************/ |
sv | 1:6799c07fe510 | 39 | |
sv | 1:6799c07fe510 | 40 | |
sv | 1:6799c07fe510 | 41 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 42 | * Vector arithmetic functions add, sub, mul and div |
sv | 1:6799c07fe510 | 43 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 44 | |
sv | 1:6799c07fe510 | 45 | |
sv | 1:6799c07fe510 | 46 | /* |
sv | 1:6799c07fe510 | 47 | * function(Matrix<T1, Rows, Cols>, Matrix<T2, Rows, Cols>) |
sv | 1:6799c07fe510 | 48 | * function(XprMatrix<E, Rows, Cols>, Matrix<T, Rows, Cols>) |
sv | 1:6799c07fe510 | 49 | * function(Matrix<T, Rows, Cols>, XprMatrix<E, Rows, Cols>) |
sv | 1:6799c07fe510 | 50 | */ |
sv | 1:6799c07fe510 | 51 | #define TVMET_DECLARE_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 52 | template<class T1, class T2, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 53 | XprMatrix< \ |
sv | 1:6799c07fe510 | 54 | XprBinOp< \ |
sv | 1:6799c07fe510 | 55 | Fcnl_##NAME<T1, T2>, \ |
sv | 1:6799c07fe510 | 56 | MatrixConstReference<T1, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 57 | MatrixConstReference<T2, Rows, Cols> \ |
sv | 1:6799c07fe510 | 58 | >, \ |
sv | 1:6799c07fe510 | 59 | Rows, Cols \ |
sv | 1:6799c07fe510 | 60 | > \ |
sv | 1:6799c07fe510 | 61 | NAME (const Matrix<T1, Rows, Cols>& lhs, \ |
sv | 1:6799c07fe510 | 62 | const Matrix<T2, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; \ |
sv | 1:6799c07fe510 | 63 | \ |
sv | 1:6799c07fe510 | 64 | template<class E, class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 65 | XprMatrix< \ |
sv | 1:6799c07fe510 | 66 | XprBinOp< \ |
sv | 1:6799c07fe510 | 67 | Fcnl_##NAME<typename E::value_type, T>, \ |
sv | 1:6799c07fe510 | 68 | XprMatrix<E, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 69 | MatrixConstReference<T, Rows, Cols> \ |
sv | 1:6799c07fe510 | 70 | >, \ |
sv | 1:6799c07fe510 | 71 | Rows, Cols \ |
sv | 1:6799c07fe510 | 72 | > \ |
sv | 1:6799c07fe510 | 73 | NAME (const XprMatrix<E, Rows, Cols>& lhs, \ |
sv | 1:6799c07fe510 | 74 | const Matrix<T, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; \ |
sv | 1:6799c07fe510 | 75 | \ |
sv | 1:6799c07fe510 | 76 | template<class T, class E, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 77 | XprMatrix< \ |
sv | 1:6799c07fe510 | 78 | XprBinOp< \ |
sv | 1:6799c07fe510 | 79 | Fcnl_##NAME<typename E::value_type, T>, \ |
sv | 1:6799c07fe510 | 80 | MatrixConstReference<T, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 81 | XprMatrix<E, Rows, Cols> \ |
sv | 1:6799c07fe510 | 82 | >, \ |
sv | 1:6799c07fe510 | 83 | Rows, Cols \ |
sv | 1:6799c07fe510 | 84 | > \ |
sv | 1:6799c07fe510 | 85 | NAME (const Matrix<T, Rows, Cols>& lhs, \ |
sv | 1:6799c07fe510 | 86 | const XprMatrix<E, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 87 | |
sv | 1:6799c07fe510 | 88 | TVMET_DECLARE_MACRO(add) // per se element wise |
sv | 1:6799c07fe510 | 89 | TVMET_DECLARE_MACRO(sub) // per se element wise |
sv | 1:6799c07fe510 | 90 | namespace element_wise { |
sv | 1:6799c07fe510 | 91 | TVMET_DECLARE_MACRO(mul) // not defined for matrizes |
sv | 1:6799c07fe510 | 92 | TVMET_DECLARE_MACRO(div) // not defined for matrizes |
sv | 1:6799c07fe510 | 93 | } |
sv | 1:6799c07fe510 | 94 | |
sv | 1:6799c07fe510 | 95 | #undef TVMET_DECLARE_MACRO |
sv | 1:6799c07fe510 | 96 | |
sv | 1:6799c07fe510 | 97 | |
sv | 1:6799c07fe510 | 98 | /* |
sv | 1:6799c07fe510 | 99 | * function(Matrix<T, Rows, Cols>, POD) |
sv | 1:6799c07fe510 | 100 | * function(POD, Matrix<T, Rows, Cols>) |
sv | 1:6799c07fe510 | 101 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 102 | */ |
sv | 1:6799c07fe510 | 103 | #define TVMET_DECLARE_MACRO(NAME, POD) \ |
sv | 1:6799c07fe510 | 104 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 105 | XprMatrix< \ |
sv | 1:6799c07fe510 | 106 | XprBinOp< \ |
sv | 1:6799c07fe510 | 107 | Fcnl_##NAME<T, POD >, \ |
sv | 1:6799c07fe510 | 108 | MatrixConstReference<T, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 109 | XprLiteral<POD > \ |
sv | 1:6799c07fe510 | 110 | >, \ |
sv | 1:6799c07fe510 | 111 | Rows, Cols \ |
sv | 1:6799c07fe510 | 112 | > \ |
sv | 1:6799c07fe510 | 113 | NAME (const Matrix<T, Rows, Cols>& lhs, \ |
sv | 1:6799c07fe510 | 114 | POD rhs) TVMET_CXX_ALWAYS_INLINE; \ |
sv | 1:6799c07fe510 | 115 | \ |
sv | 1:6799c07fe510 | 116 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 117 | XprMatrix< \ |
sv | 1:6799c07fe510 | 118 | XprBinOp< \ |
sv | 1:6799c07fe510 | 119 | Fcnl_##NAME< POD, T>, \ |
sv | 1:6799c07fe510 | 120 | XprLiteral< POD >, \ |
sv | 1:6799c07fe510 | 121 | MatrixConstReference<T, Rows, Cols> \ |
sv | 1:6799c07fe510 | 122 | >, \ |
sv | 1:6799c07fe510 | 123 | Rows, Cols \ |
sv | 1:6799c07fe510 | 124 | > \ |
sv | 1:6799c07fe510 | 125 | NAME (POD lhs, \ |
sv | 1:6799c07fe510 | 126 | const Matrix<T, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 127 | |
sv | 1:6799c07fe510 | 128 | TVMET_DECLARE_MACRO(add, int) |
sv | 1:6799c07fe510 | 129 | TVMET_DECLARE_MACRO(sub, int) |
sv | 1:6799c07fe510 | 130 | TVMET_DECLARE_MACRO(mul, int) |
sv | 1:6799c07fe510 | 131 | TVMET_DECLARE_MACRO(div, int) |
sv | 1:6799c07fe510 | 132 | |
sv | 1:6799c07fe510 | 133 | #if defined(TVMET_HAVE_LONG_LONG) |
sv | 1:6799c07fe510 | 134 | TVMET_DECLARE_MACRO(add, long long int) |
sv | 1:6799c07fe510 | 135 | TVMET_DECLARE_MACRO(sub, long long int) |
sv | 1:6799c07fe510 | 136 | TVMET_DECLARE_MACRO(mul, long long int) |
sv | 1:6799c07fe510 | 137 | TVMET_DECLARE_MACRO(div, long long int) |
sv | 1:6799c07fe510 | 138 | #endif |
sv | 1:6799c07fe510 | 139 | |
sv | 1:6799c07fe510 | 140 | TVMET_DECLARE_MACRO(add, float) |
sv | 1:6799c07fe510 | 141 | TVMET_DECLARE_MACRO(sub, float) |
sv | 1:6799c07fe510 | 142 | TVMET_DECLARE_MACRO(mul, float) |
sv | 1:6799c07fe510 | 143 | TVMET_DECLARE_MACRO(div, float) |
sv | 1:6799c07fe510 | 144 | |
sv | 1:6799c07fe510 | 145 | TVMET_DECLARE_MACRO(add, double) |
sv | 1:6799c07fe510 | 146 | TVMET_DECLARE_MACRO(sub, double) |
sv | 1:6799c07fe510 | 147 | TVMET_DECLARE_MACRO(mul, double) |
sv | 1:6799c07fe510 | 148 | TVMET_DECLARE_MACRO(div, double) |
sv | 1:6799c07fe510 | 149 | |
sv | 1:6799c07fe510 | 150 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
sv | 1:6799c07fe510 | 151 | TVMET_DECLARE_MACRO(add, long double) |
sv | 1:6799c07fe510 | 152 | TVMET_DECLARE_MACRO(sub, long double) |
sv | 1:6799c07fe510 | 153 | TVMET_DECLARE_MACRO(mul, long double) |
sv | 1:6799c07fe510 | 154 | TVMET_DECLARE_MACRO(div, long double) |
sv | 1:6799c07fe510 | 155 | #endif |
sv | 1:6799c07fe510 | 156 | |
sv | 1:6799c07fe510 | 157 | #undef TVMET_DECLARE_MACRO |
sv | 1:6799c07fe510 | 158 | |
sv | 1:6799c07fe510 | 159 | |
sv | 1:6799c07fe510 | 160 | #if defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 161 | /* |
sv | 1:6799c07fe510 | 162 | * function(Matrix<T, Rows, Cols>, complex<T>) |
sv | 1:6799c07fe510 | 163 | * function(complex<T>, Matrix<T, Rows, Cols>) |
sv | 1:6799c07fe510 | 164 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 165 | * \todo type promotion |
sv | 1:6799c07fe510 | 166 | */ |
sv | 1:6799c07fe510 | 167 | #define TVMET_DECLARE_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 168 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 169 | XprMatrix< \ |
sv | 1:6799c07fe510 | 170 | XprBinOp< \ |
sv | 1:6799c07fe510 | 171 | Fcnl_##NAME< std::complex<T>, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 172 | MatrixConstReference< std::complex<T>, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 173 | XprLiteral<std::complex<T> > \ |
sv | 1:6799c07fe510 | 174 | >, \ |
sv | 1:6799c07fe510 | 175 | Rows, Cols \ |
sv | 1:6799c07fe510 | 176 | > \ |
sv | 1:6799c07fe510 | 177 | NAME (const Matrix< std::complex<T>, Rows, Cols>& lhs, \ |
sv | 1:6799c07fe510 | 178 | const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE; \ |
sv | 1:6799c07fe510 | 179 | \ |
sv | 1:6799c07fe510 | 180 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 181 | XprMatrix< \ |
sv | 1:6799c07fe510 | 182 | XprBinOp< \ |
sv | 1:6799c07fe510 | 183 | Fcnl_##NAME< std::complex<T>, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 184 | XprLiteral< std::complex<T> >, \ |
sv | 1:6799c07fe510 | 185 | MatrixConstReference< std::complex<T>, Rows, Cols> \ |
sv | 1:6799c07fe510 | 186 | >, \ |
sv | 1:6799c07fe510 | 187 | Rows, Cols \ |
sv | 1:6799c07fe510 | 188 | > \ |
sv | 1:6799c07fe510 | 189 | NAME (const std::complex<T>& lhs, \ |
sv | 1:6799c07fe510 | 190 | const Matrix< std::complex<T>, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 191 | |
sv | 1:6799c07fe510 | 192 | TVMET_DECLARE_MACRO(add) |
sv | 1:6799c07fe510 | 193 | TVMET_DECLARE_MACRO(sub) |
sv | 1:6799c07fe510 | 194 | TVMET_DECLARE_MACRO(mul) |
sv | 1:6799c07fe510 | 195 | TVMET_DECLARE_MACRO(div) |
sv | 1:6799c07fe510 | 196 | |
sv | 1:6799c07fe510 | 197 | #undef TVMET_DECLARE_MACRO |
sv | 1:6799c07fe510 | 198 | |
sv | 1:6799c07fe510 | 199 | #endif // defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 200 | |
sv | 1:6799c07fe510 | 201 | |
sv | 1:6799c07fe510 | 202 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 203 | * matrix specific prod( ... ) functions |
sv | 1:6799c07fe510 | 204 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 205 | |
sv | 1:6799c07fe510 | 206 | |
sv | 1:6799c07fe510 | 207 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 208 | class T2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 209 | XprMatrix< |
sv | 1:6799c07fe510 | 210 | XprMMProduct< |
sv | 1:6799c07fe510 | 211 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 212 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 213 | >, |
sv | 1:6799c07fe510 | 214 | Rows1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 215 | > |
sv | 1:6799c07fe510 | 216 | prod(const Matrix<T1, Rows1, Cols1>& lhs, |
sv | 1:6799c07fe510 | 217 | const Matrix<T2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 218 | |
sv | 1:6799c07fe510 | 219 | |
sv | 1:6799c07fe510 | 220 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 221 | class T2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 222 | XprMatrix< |
sv | 1:6799c07fe510 | 223 | XprMMProduct< |
sv | 1:6799c07fe510 | 224 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 225 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 226 | >, |
sv | 1:6799c07fe510 | 227 | Rows1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 228 | > |
sv | 1:6799c07fe510 | 229 | prod(const XprMatrix<E1, Rows1, Cols1>& lhs, |
sv | 1:6799c07fe510 | 230 | const Matrix<T2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 231 | |
sv | 1:6799c07fe510 | 232 | |
sv | 1:6799c07fe510 | 233 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 234 | class E2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 235 | XprMatrix< |
sv | 1:6799c07fe510 | 236 | XprMMProduct< |
sv | 1:6799c07fe510 | 237 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 238 | XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 239 | >, |
sv | 1:6799c07fe510 | 240 | Rows1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 241 | > |
sv | 1:6799c07fe510 | 242 | prod(const Matrix<T1, Rows1, Cols1>& lhs, |
sv | 1:6799c07fe510 | 243 | const XprMatrix<E2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 244 | |
sv | 1:6799c07fe510 | 245 | |
sv | 1:6799c07fe510 | 246 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 247 | class T2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 248 | XprMatrix< |
sv | 1:6799c07fe510 | 249 | XprMMProductTransposed< |
sv | 1:6799c07fe510 | 250 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 251 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 252 | >, |
sv | 1:6799c07fe510 | 253 | Cols2, Rows1 // return Dim |
sv | 1:6799c07fe510 | 254 | > |
sv | 1:6799c07fe510 | 255 | trans_prod(const Matrix<T1, Rows1, Cols1>& lhs, |
sv | 1:6799c07fe510 | 256 | const Matrix<T2, Cols1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 257 | |
sv | 1:6799c07fe510 | 258 | |
sv | 1:6799c07fe510 | 259 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 260 | class T2, std::size_t Cols2> // Rows2 = Rows1 |
sv | 1:6799c07fe510 | 261 | XprMatrix< |
sv | 1:6799c07fe510 | 262 | XprMtMProduct< |
sv | 1:6799c07fe510 | 263 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 264 | MatrixConstReference<T2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2) |
sv | 1:6799c07fe510 | 265 | >, |
sv | 1:6799c07fe510 | 266 | Cols1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 267 | > |
sv | 1:6799c07fe510 | 268 | MtM_prod(const Matrix<T1, Rows1, Cols1>& lhs, |
sv | 1:6799c07fe510 | 269 | const Matrix<T2, Rows1, Cols2>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 270 | |
sv | 1:6799c07fe510 | 271 | |
sv | 1:6799c07fe510 | 272 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 273 | class T2, std::size_t Rows2> |
sv | 1:6799c07fe510 | 274 | XprMatrix< |
sv | 1:6799c07fe510 | 275 | XprMMtProduct< |
sv | 1:6799c07fe510 | 276 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 277 | MatrixConstReference<T2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1) |
sv | 1:6799c07fe510 | 278 | >, |
sv | 1:6799c07fe510 | 279 | Rows1, Rows2 // return Dim |
sv | 1:6799c07fe510 | 280 | > |
sv | 1:6799c07fe510 | 281 | MMt_prod(const Matrix<T1, Rows1, Cols1>& lhs, |
sv | 1:6799c07fe510 | 282 | const Matrix<T2, Rows2, Cols1>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 283 | |
sv | 1:6799c07fe510 | 284 | |
sv | 1:6799c07fe510 | 285 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 286 | * matrix-vector specific prod( ... ) functions |
sv | 1:6799c07fe510 | 287 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 288 | |
sv | 1:6799c07fe510 | 289 | |
sv | 1:6799c07fe510 | 290 | template<class T1, class T2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 291 | XprVector< |
sv | 1:6799c07fe510 | 292 | XprMVProduct< |
sv | 1:6799c07fe510 | 293 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, // M(Rows, Cols) |
sv | 1:6799c07fe510 | 294 | VectorConstReference<T2, Cols> // V |
sv | 1:6799c07fe510 | 295 | >, |
sv | 1:6799c07fe510 | 296 | Rows |
sv | 1:6799c07fe510 | 297 | > |
sv | 1:6799c07fe510 | 298 | prod(const Matrix<T1, Rows, Cols>& lhs, |
sv | 1:6799c07fe510 | 299 | const Vector<T2, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 300 | |
sv | 1:6799c07fe510 | 301 | |
sv | 1:6799c07fe510 | 302 | template<class T1, class E2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 303 | XprVector< |
sv | 1:6799c07fe510 | 304 | XprMVProduct< |
sv | 1:6799c07fe510 | 305 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, |
sv | 1:6799c07fe510 | 306 | XprVector<E2, Cols> |
sv | 1:6799c07fe510 | 307 | >, |
sv | 1:6799c07fe510 | 308 | Rows |
sv | 1:6799c07fe510 | 309 | > |
sv | 1:6799c07fe510 | 310 | prod(const Matrix<T1, Rows, Cols>& lhs, |
sv | 1:6799c07fe510 | 311 | const XprVector<E2, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 312 | |
sv | 1:6799c07fe510 | 313 | |
sv | 1:6799c07fe510 | 314 | template<class E1, class T2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 315 | XprVector< |
sv | 1:6799c07fe510 | 316 | XprMVProduct< |
sv | 1:6799c07fe510 | 317 | XprMatrix<E1, Rows, Cols>, Rows, Cols, // M(Rows, Cols) |
sv | 1:6799c07fe510 | 318 | VectorConstReference<T2, Cols> // V |
sv | 1:6799c07fe510 | 319 | >, |
sv | 1:6799c07fe510 | 320 | Rows |
sv | 1:6799c07fe510 | 321 | > |
sv | 1:6799c07fe510 | 322 | prod(const XprMatrix<E1, Rows, Cols>& lhs, |
sv | 1:6799c07fe510 | 323 | const Vector<T2, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 324 | |
sv | 1:6799c07fe510 | 325 | |
sv | 1:6799c07fe510 | 326 | template<class T1, class T2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 327 | XprVector< |
sv | 1:6799c07fe510 | 328 | XprMtVProduct< |
sv | 1:6799c07fe510 | 329 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, // M(Rows, Cols) |
sv | 1:6799c07fe510 | 330 | VectorConstReference<T2, Rows> // V |
sv | 1:6799c07fe510 | 331 | >, |
sv | 1:6799c07fe510 | 332 | Cols |
sv | 1:6799c07fe510 | 333 | > |
sv | 1:6799c07fe510 | 334 | Mtx_prod(const Matrix<T1, Rows, Cols>& lhs, |
sv | 1:6799c07fe510 | 335 | const Vector<T2, Rows>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 336 | |
sv | 1:6799c07fe510 | 337 | |
sv | 1:6799c07fe510 | 338 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 339 | * matrix specific functions |
sv | 1:6799c07fe510 | 340 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 341 | |
sv | 1:6799c07fe510 | 342 | |
sv | 1:6799c07fe510 | 343 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 344 | XprMatrix< |
sv | 1:6799c07fe510 | 345 | XprMatrixTranspose< |
sv | 1:6799c07fe510 | 346 | MatrixConstReference<T, Rows, Cols> |
sv | 1:6799c07fe510 | 347 | >, |
sv | 1:6799c07fe510 | 348 | Cols, Rows |
sv | 1:6799c07fe510 | 349 | > |
sv | 1:6799c07fe510 | 350 | trans(const Matrix<T, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 351 | |
sv | 1:6799c07fe510 | 352 | |
sv | 1:6799c07fe510 | 353 | template<class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 354 | typename NumericTraits<T>::sum_type |
sv | 1:6799c07fe510 | 355 | trace(const Matrix<T, Sz, Sz>& m) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 356 | |
sv | 1:6799c07fe510 | 357 | |
sv | 1:6799c07fe510 | 358 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 359 | XprVector< |
sv | 1:6799c07fe510 | 360 | XprMatrixRow< |
sv | 1:6799c07fe510 | 361 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 362 | Rows, Cols |
sv | 1:6799c07fe510 | 363 | >, |
sv | 1:6799c07fe510 | 364 | Cols |
sv | 1:6799c07fe510 | 365 | > |
sv | 1:6799c07fe510 | 366 | row(const Matrix<T, Rows, Cols>& m, |
sv | 1:6799c07fe510 | 367 | std::size_t no) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 368 | |
sv | 1:6799c07fe510 | 369 | |
sv | 1:6799c07fe510 | 370 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 371 | XprVector< |
sv | 1:6799c07fe510 | 372 | XprMatrixCol< |
sv | 1:6799c07fe510 | 373 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 374 | Rows, Cols |
sv | 1:6799c07fe510 | 375 | >, |
sv | 1:6799c07fe510 | 376 | Rows |
sv | 1:6799c07fe510 | 377 | > |
sv | 1:6799c07fe510 | 378 | col(const Matrix<T, Rows, Cols>& m, |
sv | 1:6799c07fe510 | 379 | std::size_t no) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 380 | |
sv | 1:6799c07fe510 | 381 | |
sv | 1:6799c07fe510 | 382 | template<class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 383 | XprVector< |
sv | 1:6799c07fe510 | 384 | XprMatrixDiag< |
sv | 1:6799c07fe510 | 385 | MatrixConstReference<T, Sz, Sz>, |
sv | 1:6799c07fe510 | 386 | Sz |
sv | 1:6799c07fe510 | 387 | >, |
sv | 1:6799c07fe510 | 388 | Sz |
sv | 1:6799c07fe510 | 389 | > |
sv | 1:6799c07fe510 | 390 | diag(const Matrix<T, Sz, Sz>& m) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 391 | |
sv | 1:6799c07fe510 | 392 | |
sv | 1:6799c07fe510 | 393 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 394 | * min/max unary functions |
sv | 1:6799c07fe510 | 395 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 396 | |
sv | 1:6799c07fe510 | 397 | |
sv | 1:6799c07fe510 | 398 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 399 | Extremum<typename E::value_type, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 400 | maximum(const XprMatrix<E, Rows, Cols>& e); // NOT TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 401 | |
sv | 1:6799c07fe510 | 402 | |
sv | 1:6799c07fe510 | 403 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 404 | Extremum<T, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 405 | maximum(const Matrix<T, Rows, Cols>& m) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 406 | |
sv | 1:6799c07fe510 | 407 | |
sv | 1:6799c07fe510 | 408 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 409 | Extremum<typename E::value_type, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 410 | minimum(const XprMatrix<E, Rows, Cols>& e); // NOT TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 411 | |
sv | 1:6799c07fe510 | 412 | |
sv | 1:6799c07fe510 | 413 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 414 | Extremum<T, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 415 | minimum(const Matrix<T, Rows, Cols>& m) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 416 | |
sv | 1:6799c07fe510 | 417 | |
sv | 1:6799c07fe510 | 418 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 419 | typename E::value_type |
sv | 1:6799c07fe510 | 420 | max(const XprMatrix<E, Rows, Cols>& e); // NOT TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 421 | |
sv | 1:6799c07fe510 | 422 | |
sv | 1:6799c07fe510 | 423 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 424 | T max(const Matrix<T, Rows, Cols>& m) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 425 | |
sv | 1:6799c07fe510 | 426 | |
sv | 1:6799c07fe510 | 427 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 428 | typename E::value_type |
sv | 1:6799c07fe510 | 429 | min(const XprMatrix<E, Rows, Cols>& e); // NOT TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 430 | |
sv | 1:6799c07fe510 | 431 | |
sv | 1:6799c07fe510 | 432 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 433 | T min(const Matrix<T, Rows, Cols>& m) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 434 | |
sv | 1:6799c07fe510 | 435 | |
sv | 1:6799c07fe510 | 436 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 437 | * other unary functions |
sv | 1:6799c07fe510 | 438 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 439 | |
sv | 1:6799c07fe510 | 440 | |
sv | 1:6799c07fe510 | 441 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 442 | XprMatrix< |
sv | 1:6799c07fe510 | 443 | XprIdentity<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 444 | Rows, Cols |
sv | 1:6799c07fe510 | 445 | > |
sv | 1:6799c07fe510 | 446 | identity() TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 447 | |
sv | 1:6799c07fe510 | 448 | |
sv | 1:6799c07fe510 | 449 | template<class M> |
sv | 1:6799c07fe510 | 450 | XprMatrix< |
sv | 1:6799c07fe510 | 451 | XprIdentity< |
sv | 1:6799c07fe510 | 452 | typename M::value_type, |
sv | 1:6799c07fe510 | 453 | M::Rows, M::Cols>, |
sv | 1:6799c07fe510 | 454 | M::Rows, M::Cols |
sv | 1:6799c07fe510 | 455 | > |
sv | 1:6799c07fe510 | 456 | identity() TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 457 | |
sv | 1:6799c07fe510 | 458 | |
sv | 1:6799c07fe510 | 459 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 460 | XprMatrix< |
sv | 1:6799c07fe510 | 461 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 462 | Rows, Cols |
sv | 1:6799c07fe510 | 463 | > |
sv | 1:6799c07fe510 | 464 | cmatrix_ref(const T* mem) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 465 | |
sv | 1:6799c07fe510 | 466 | |
sv | 1:6799c07fe510 | 467 | /********************************************************* |
sv | 1:6799c07fe510 | 468 | * PART II: IMPLEMENTATION |
sv | 1:6799c07fe510 | 469 | *********************************************************/ |
sv | 1:6799c07fe510 | 470 | |
sv | 1:6799c07fe510 | 471 | |
sv | 1:6799c07fe510 | 472 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 473 | * Vector arithmetic functions add, sub, mul and div |
sv | 1:6799c07fe510 | 474 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 475 | |
sv | 1:6799c07fe510 | 476 | |
sv | 1:6799c07fe510 | 477 | /* |
sv | 1:6799c07fe510 | 478 | * function(Matrix<T1, Rows, Cols>, Matrix<T2, Rows, Cols>) |
sv | 1:6799c07fe510 | 479 | * function(XprMatrix<E, Rows, Cols>, Matrix<T, Rows, Cols>) |
sv | 1:6799c07fe510 | 480 | * function(Matrix<T, Rows, Cols>, XprMatrix<E, Rows, Cols>) |
sv | 1:6799c07fe510 | 481 | */ |
sv | 1:6799c07fe510 | 482 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 483 | template<class T1, class T2, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 484 | inline \ |
sv | 1:6799c07fe510 | 485 | XprMatrix< \ |
sv | 1:6799c07fe510 | 486 | XprBinOp< \ |
sv | 1:6799c07fe510 | 487 | Fcnl_##NAME<T1, T2>, \ |
sv | 1:6799c07fe510 | 488 | MatrixConstReference<T1, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 489 | MatrixConstReference<T2, Rows, Cols> \ |
sv | 1:6799c07fe510 | 490 | >, \ |
sv | 1:6799c07fe510 | 491 | Rows, Cols \ |
sv | 1:6799c07fe510 | 492 | > \ |
sv | 1:6799c07fe510 | 493 | NAME (const Matrix<T1, Rows, Cols>& lhs, const Matrix<T2, Rows, Cols>& rhs) { \ |
sv | 1:6799c07fe510 | 494 | typedef XprBinOp < \ |
sv | 1:6799c07fe510 | 495 | Fcnl_##NAME<T1, T2>, \ |
sv | 1:6799c07fe510 | 496 | MatrixConstReference<T1, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 497 | MatrixConstReference<T2, Rows, Cols> \ |
sv | 1:6799c07fe510 | 498 | > expr_type; \ |
sv | 1:6799c07fe510 | 499 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 500 | expr_type(lhs.const_ref(), rhs.const_ref())); \ |
sv | 1:6799c07fe510 | 501 | } \ |
sv | 1:6799c07fe510 | 502 | \ |
sv | 1:6799c07fe510 | 503 | template<class E, class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 504 | inline \ |
sv | 1:6799c07fe510 | 505 | XprMatrix< \ |
sv | 1:6799c07fe510 | 506 | XprBinOp< \ |
sv | 1:6799c07fe510 | 507 | Fcnl_##NAME<typename E::value_type, T>, \ |
sv | 1:6799c07fe510 | 508 | XprMatrix<E, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 509 | MatrixConstReference<T, Rows, Cols> \ |
sv | 1:6799c07fe510 | 510 | >, \ |
sv | 1:6799c07fe510 | 511 | Rows, Cols \ |
sv | 1:6799c07fe510 | 512 | > \ |
sv | 1:6799c07fe510 | 513 | NAME (const XprMatrix<E, Rows, Cols>& lhs, const Matrix<T, Rows, Cols>& rhs) { \ |
sv | 1:6799c07fe510 | 514 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 515 | Fcnl_##NAME<typename E::value_type, T>, \ |
sv | 1:6799c07fe510 | 516 | XprMatrix<E, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 517 | MatrixConstReference<T, Rows, Cols> \ |
sv | 1:6799c07fe510 | 518 | > expr_type; \ |
sv | 1:6799c07fe510 | 519 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 520 | expr_type(lhs, rhs.const_ref())); \ |
sv | 1:6799c07fe510 | 521 | } \ |
sv | 1:6799c07fe510 | 522 | \ |
sv | 1:6799c07fe510 | 523 | template<class T, class E, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 524 | inline \ |
sv | 1:6799c07fe510 | 525 | XprMatrix< \ |
sv | 1:6799c07fe510 | 526 | XprBinOp< \ |
sv | 1:6799c07fe510 | 527 | Fcnl_##NAME<typename E::value_type, T>, \ |
sv | 1:6799c07fe510 | 528 | MatrixConstReference<T, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 529 | XprMatrix<E, Rows, Cols> \ |
sv | 1:6799c07fe510 | 530 | >, \ |
sv | 1:6799c07fe510 | 531 | Rows, Cols \ |
sv | 1:6799c07fe510 | 532 | > \ |
sv | 1:6799c07fe510 | 533 | NAME (const Matrix<T, Rows, Cols>& lhs, const XprMatrix<E, Rows, Cols>& rhs) { \ |
sv | 1:6799c07fe510 | 534 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 535 | Fcnl_##NAME<T, typename E::value_type>, \ |
sv | 1:6799c07fe510 | 536 | MatrixConstReference<T, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 537 | XprMatrix<E, Rows, Cols> \ |
sv | 1:6799c07fe510 | 538 | > expr_type; \ |
sv | 1:6799c07fe510 | 539 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 540 | expr_type(lhs.const_ref(), rhs)); \ |
sv | 1:6799c07fe510 | 541 | } |
sv | 1:6799c07fe510 | 542 | |
sv | 1:6799c07fe510 | 543 | TVMET_IMPLEMENT_MACRO(add) // per se element wise |
sv | 1:6799c07fe510 | 544 | TVMET_IMPLEMENT_MACRO(sub) // per se element wise |
sv | 1:6799c07fe510 | 545 | namespace element_wise { |
sv | 1:6799c07fe510 | 546 | TVMET_IMPLEMENT_MACRO(mul) // not defined for matrizes |
sv | 1:6799c07fe510 | 547 | TVMET_IMPLEMENT_MACRO(div) // not defined for matrizes |
sv | 1:6799c07fe510 | 548 | } |
sv | 1:6799c07fe510 | 549 | |
sv | 1:6799c07fe510 | 550 | #undef TVMET_IMPLEMENT_MACRO |
sv | 1:6799c07fe510 | 551 | |
sv | 1:6799c07fe510 | 552 | |
sv | 1:6799c07fe510 | 553 | /* |
sv | 1:6799c07fe510 | 554 | * function(Matrix<T, Rows, Cols>, POD) |
sv | 1:6799c07fe510 | 555 | * function(POD, Matrix<T, Rows, Cols>) |
sv | 1:6799c07fe510 | 556 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 557 | */ |
sv | 1:6799c07fe510 | 558 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
sv | 1:6799c07fe510 | 559 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 560 | inline \ |
sv | 1:6799c07fe510 | 561 | XprMatrix< \ |
sv | 1:6799c07fe510 | 562 | XprBinOp< \ |
sv | 1:6799c07fe510 | 563 | Fcnl_##NAME<T, POD >, \ |
sv | 1:6799c07fe510 | 564 | MatrixConstReference<T, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 565 | XprLiteral<POD > \ |
sv | 1:6799c07fe510 | 566 | >, \ |
sv | 1:6799c07fe510 | 567 | Rows, Cols \ |
sv | 1:6799c07fe510 | 568 | > \ |
sv | 1:6799c07fe510 | 569 | NAME (const Matrix<T, Rows, Cols>& lhs, POD rhs) { \ |
sv | 1:6799c07fe510 | 570 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 571 | Fcnl_##NAME<T, POD >, \ |
sv | 1:6799c07fe510 | 572 | MatrixConstReference<T, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 573 | XprLiteral< POD > \ |
sv | 1:6799c07fe510 | 574 | > expr_type; \ |
sv | 1:6799c07fe510 | 575 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 576 | expr_type(lhs.const_ref(), XprLiteral< POD >(rhs))); \ |
sv | 1:6799c07fe510 | 577 | } \ |
sv | 1:6799c07fe510 | 578 | \ |
sv | 1:6799c07fe510 | 579 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 580 | inline \ |
sv | 1:6799c07fe510 | 581 | XprMatrix< \ |
sv | 1:6799c07fe510 | 582 | XprBinOp< \ |
sv | 1:6799c07fe510 | 583 | Fcnl_##NAME< POD, T>, \ |
sv | 1:6799c07fe510 | 584 | XprLiteral< POD >, \ |
sv | 1:6799c07fe510 | 585 | MatrixConstReference<T, Rows, Cols> \ |
sv | 1:6799c07fe510 | 586 | >, \ |
sv | 1:6799c07fe510 | 587 | Rows, Cols \ |
sv | 1:6799c07fe510 | 588 | > \ |
sv | 1:6799c07fe510 | 589 | NAME (POD lhs, const Matrix<T, Rows, Cols>& rhs) { \ |
sv | 1:6799c07fe510 | 590 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 591 | Fcnl_##NAME< POD, T>, \ |
sv | 1:6799c07fe510 | 592 | XprLiteral< POD >, \ |
sv | 1:6799c07fe510 | 593 | MatrixConstReference<T, Rows, Cols> \ |
sv | 1:6799c07fe510 | 594 | > expr_type; \ |
sv | 1:6799c07fe510 | 595 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 596 | expr_type(XprLiteral< POD >(lhs), rhs.const_ref())); \ |
sv | 1:6799c07fe510 | 597 | } |
sv | 1:6799c07fe510 | 598 | |
sv | 1:6799c07fe510 | 599 | TVMET_IMPLEMENT_MACRO(add, int) |
sv | 1:6799c07fe510 | 600 | TVMET_IMPLEMENT_MACRO(sub, int) |
sv | 1:6799c07fe510 | 601 | TVMET_IMPLEMENT_MACRO(mul, int) |
sv | 1:6799c07fe510 | 602 | TVMET_IMPLEMENT_MACRO(div, int) |
sv | 1:6799c07fe510 | 603 | |
sv | 1:6799c07fe510 | 604 | #if defined(TVMET_HAVE_LONG_LONG) |
sv | 1:6799c07fe510 | 605 | TVMET_IMPLEMENT_MACRO(add, long long int) |
sv | 1:6799c07fe510 | 606 | TVMET_IMPLEMENT_MACRO(sub, long long int) |
sv | 1:6799c07fe510 | 607 | TVMET_IMPLEMENT_MACRO(mul, long long int) |
sv | 1:6799c07fe510 | 608 | TVMET_IMPLEMENT_MACRO(div, long long int) |
sv | 1:6799c07fe510 | 609 | #endif |
sv | 1:6799c07fe510 | 610 | |
sv | 1:6799c07fe510 | 611 | TVMET_IMPLEMENT_MACRO(add, float) |
sv | 1:6799c07fe510 | 612 | TVMET_IMPLEMENT_MACRO(sub, float) |
sv | 1:6799c07fe510 | 613 | TVMET_IMPLEMENT_MACRO(mul, float) |
sv | 1:6799c07fe510 | 614 | TVMET_IMPLEMENT_MACRO(div, float) |
sv | 1:6799c07fe510 | 615 | |
sv | 1:6799c07fe510 | 616 | TVMET_IMPLEMENT_MACRO(add, double) |
sv | 1:6799c07fe510 | 617 | TVMET_IMPLEMENT_MACRO(sub, double) |
sv | 1:6799c07fe510 | 618 | TVMET_IMPLEMENT_MACRO(mul, double) |
sv | 1:6799c07fe510 | 619 | TVMET_IMPLEMENT_MACRO(div, double) |
sv | 1:6799c07fe510 | 620 | |
sv | 1:6799c07fe510 | 621 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
sv | 1:6799c07fe510 | 622 | TVMET_IMPLEMENT_MACRO(add, long double) |
sv | 1:6799c07fe510 | 623 | TVMET_IMPLEMENT_MACRO(sub, long double) |
sv | 1:6799c07fe510 | 624 | TVMET_IMPLEMENT_MACRO(mul, long double) |
sv | 1:6799c07fe510 | 625 | TVMET_IMPLEMENT_MACRO(div, long double) |
sv | 1:6799c07fe510 | 626 | #endif |
sv | 1:6799c07fe510 | 627 | |
sv | 1:6799c07fe510 | 628 | #undef TVMET_IMPLEMENT_MACRO |
sv | 1:6799c07fe510 | 629 | |
sv | 1:6799c07fe510 | 630 | |
sv | 1:6799c07fe510 | 631 | #if defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 632 | /* |
sv | 1:6799c07fe510 | 633 | * function(Matrix<T, Rows, Cols>, complex<T>) |
sv | 1:6799c07fe510 | 634 | * function(complex<T>, Matrix<T, Rows, Cols>) |
sv | 1:6799c07fe510 | 635 | * Note: - operations +,-,*,/ are per se element wise |
sv | 1:6799c07fe510 | 636 | * \todo type promotion |
sv | 1:6799c07fe510 | 637 | */ |
sv | 1:6799c07fe510 | 638 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
sv | 1:6799c07fe510 | 639 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 640 | inline \ |
sv | 1:6799c07fe510 | 641 | XprMatrix< \ |
sv | 1:6799c07fe510 | 642 | XprBinOp< \ |
sv | 1:6799c07fe510 | 643 | Fcnl_##NAME< std::complex<T>, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 644 | MatrixConstReference< std::complex<T>, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 645 | XprLiteral<std::complex<T> > \ |
sv | 1:6799c07fe510 | 646 | >, \ |
sv | 1:6799c07fe510 | 647 | Rows, Cols \ |
sv | 1:6799c07fe510 | 648 | > \ |
sv | 1:6799c07fe510 | 649 | NAME (const Matrix< std::complex<T>, Rows, Cols>& lhs, \ |
sv | 1:6799c07fe510 | 650 | const std::complex<T>& rhs) { \ |
sv | 1:6799c07fe510 | 651 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 652 | Fcnl_##NAME< std::complex<T>, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 653 | MatrixConstReference< std::complex<T>, Rows, Cols>, \ |
sv | 1:6799c07fe510 | 654 | XprLiteral< std::complex<T> > \ |
sv | 1:6799c07fe510 | 655 | > expr_type; \ |
sv | 1:6799c07fe510 | 656 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 657 | expr_type(lhs.const_ref(), XprLiteral< std::complex<T> >(rhs))); \ |
sv | 1:6799c07fe510 | 658 | } \ |
sv | 1:6799c07fe510 | 659 | \ |
sv | 1:6799c07fe510 | 660 | template<class T, std::size_t Rows, std::size_t Cols> \ |
sv | 1:6799c07fe510 | 661 | inline \ |
sv | 1:6799c07fe510 | 662 | XprMatrix< \ |
sv | 1:6799c07fe510 | 663 | XprBinOp< \ |
sv | 1:6799c07fe510 | 664 | Fcnl_##NAME< std::complex<T>, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 665 | XprLiteral< std::complex<T> >, \ |
sv | 1:6799c07fe510 | 666 | MatrixConstReference< std::complex<T>, Rows, Cols> \ |
sv | 1:6799c07fe510 | 667 | >, \ |
sv | 1:6799c07fe510 | 668 | Rows, Cols \ |
sv | 1:6799c07fe510 | 669 | > \ |
sv | 1:6799c07fe510 | 670 | NAME (const std::complex<T>& lhs, \ |
sv | 1:6799c07fe510 | 671 | const Matrix< std::complex<T>, Rows, Cols>& rhs) { \ |
sv | 1:6799c07fe510 | 672 | typedef XprBinOp< \ |
sv | 1:6799c07fe510 | 673 | Fcnl_##NAME< std::complex<T>, std::complex<T> >, \ |
sv | 1:6799c07fe510 | 674 | XprLiteral< std::complex<T> >, \ |
sv | 1:6799c07fe510 | 675 | MatrixConstReference<std::complex<T>, Rows, Cols> \ |
sv | 1:6799c07fe510 | 676 | > expr_type; \ |
sv | 1:6799c07fe510 | 677 | return XprMatrix<expr_type, Rows, Cols>( \ |
sv | 1:6799c07fe510 | 678 | expr_type(XprLiteral< std::complex<T> >(lhs), rhs.const_ref())); \ |
sv | 1:6799c07fe510 | 679 | } |
sv | 1:6799c07fe510 | 680 | |
sv | 1:6799c07fe510 | 681 | TVMET_IMPLEMENT_MACRO(add) |
sv | 1:6799c07fe510 | 682 | TVMET_IMPLEMENT_MACRO(sub) |
sv | 1:6799c07fe510 | 683 | TVMET_IMPLEMENT_MACRO(mul) |
sv | 1:6799c07fe510 | 684 | TVMET_IMPLEMENT_MACRO(div) |
sv | 1:6799c07fe510 | 685 | |
sv | 1:6799c07fe510 | 686 | #undef TVMET_IMPLEMENT_MACRO |
sv | 1:6799c07fe510 | 687 | |
sv | 1:6799c07fe510 | 688 | #endif // defined(TVMET_HAVE_COMPLEX) |
sv | 1:6799c07fe510 | 689 | |
sv | 1:6799c07fe510 | 690 | |
sv | 1:6799c07fe510 | 691 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 692 | * matrix specific prod( ... ) functions |
sv | 1:6799c07fe510 | 693 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 694 | |
sv | 1:6799c07fe510 | 695 | |
sv | 1:6799c07fe510 | 696 | /** |
sv | 1:6799c07fe510 | 697 | * \fn prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Cols1, Cols2>& rhs) |
sv | 1:6799c07fe510 | 698 | * \brief Function for the matrix-matrix-product. |
sv | 1:6799c07fe510 | 699 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 700 | * \note The rows2 has to be equal to cols1. |
sv | 1:6799c07fe510 | 701 | */ |
sv | 1:6799c07fe510 | 702 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 703 | class T2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 704 | inline |
sv | 1:6799c07fe510 | 705 | XprMatrix< |
sv | 1:6799c07fe510 | 706 | XprMMProduct< |
sv | 1:6799c07fe510 | 707 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 708 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 709 | >, |
sv | 1:6799c07fe510 | 710 | Rows1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 711 | > |
sv | 1:6799c07fe510 | 712 | prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Cols1, Cols2>& rhs) { |
sv | 1:6799c07fe510 | 713 | typedef XprMMProduct< |
sv | 1:6799c07fe510 | 714 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, |
sv | 1:6799c07fe510 | 715 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 |
sv | 1:6799c07fe510 | 716 | > expr_type; |
sv | 1:6799c07fe510 | 717 | return XprMatrix<expr_type, Rows1, Cols2>( |
sv | 1:6799c07fe510 | 718 | expr_type(lhs.const_ref(), rhs.const_ref())); |
sv | 1:6799c07fe510 | 719 | } |
sv | 1:6799c07fe510 | 720 | |
sv | 1:6799c07fe510 | 721 | |
sv | 1:6799c07fe510 | 722 | /** |
sv | 1:6799c07fe510 | 723 | * \fn prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const Matrix<T2, Cols1, Cols2>& rhs) |
sv | 1:6799c07fe510 | 724 | * \brief Evaluate the product of XprMatrix and Matrix. |
sv | 1:6799c07fe510 | 725 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 726 | */ |
sv | 1:6799c07fe510 | 727 | template<class E1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 728 | class T2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 729 | inline |
sv | 1:6799c07fe510 | 730 | XprMatrix< |
sv | 1:6799c07fe510 | 731 | XprMMProduct< |
sv | 1:6799c07fe510 | 732 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 733 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 734 | >, |
sv | 1:6799c07fe510 | 735 | Rows1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 736 | > |
sv | 1:6799c07fe510 | 737 | prod(const XprMatrix<E1, Rows1, Cols1>& lhs, const Matrix<T2, Cols1, Cols2>& rhs) { |
sv | 1:6799c07fe510 | 738 | typedef XprMMProduct< |
sv | 1:6799c07fe510 | 739 | XprMatrix<E1, Rows1, Cols1>, Rows1, Cols1, |
sv | 1:6799c07fe510 | 740 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 |
sv | 1:6799c07fe510 | 741 | > expr_type; |
sv | 1:6799c07fe510 | 742 | return XprMatrix<expr_type, Rows1, Cols2>( |
sv | 1:6799c07fe510 | 743 | expr_type(lhs, rhs.const_ref())); |
sv | 1:6799c07fe510 | 744 | } |
sv | 1:6799c07fe510 | 745 | |
sv | 1:6799c07fe510 | 746 | |
sv | 1:6799c07fe510 | 747 | /** |
sv | 1:6799c07fe510 | 748 | * \fn prod(const Matrix<T1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) |
sv | 1:6799c07fe510 | 749 | * \brief Evaluate the product of Matrix and XprMatrix. |
sv | 1:6799c07fe510 | 750 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 751 | */ |
sv | 1:6799c07fe510 | 752 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 753 | class E2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 754 | inline |
sv | 1:6799c07fe510 | 755 | XprMatrix< |
sv | 1:6799c07fe510 | 756 | XprMMProduct< |
sv | 1:6799c07fe510 | 757 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 758 | XprMatrix<E2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 759 | >, |
sv | 1:6799c07fe510 | 760 | Rows1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 761 | > |
sv | 1:6799c07fe510 | 762 | prod(const Matrix<T1, Rows1, Cols1>& lhs, const XprMatrix<E2, Cols1, Cols2>& rhs) { |
sv | 1:6799c07fe510 | 763 | typedef XprMMProduct< |
sv | 1:6799c07fe510 | 764 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, |
sv | 1:6799c07fe510 | 765 | XprMatrix<E2, Cols1, Cols2>, Cols2 |
sv | 1:6799c07fe510 | 766 | > expr_type; |
sv | 1:6799c07fe510 | 767 | return XprMatrix<expr_type, Rows1, Cols2>( |
sv | 1:6799c07fe510 | 768 | expr_type(lhs.const_ref(), rhs)); |
sv | 1:6799c07fe510 | 769 | } |
sv | 1:6799c07fe510 | 770 | |
sv | 1:6799c07fe510 | 771 | |
sv | 1:6799c07fe510 | 772 | /** |
sv | 1:6799c07fe510 | 773 | * \fn trans_prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Cols1, Cols2>& rhs) |
sv | 1:6799c07fe510 | 774 | * \brief Function for the trans(matrix-matrix-product) |
sv | 1:6799c07fe510 | 775 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 776 | * Perform on given Matrix M1 and M2: |
sv | 1:6799c07fe510 | 777 | * \f[ |
sv | 1:6799c07fe510 | 778 | * (M_1\,M_2)^T |
sv | 1:6799c07fe510 | 779 | * \f] |
sv | 1:6799c07fe510 | 780 | */ |
sv | 1:6799c07fe510 | 781 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 782 | class T2, std::size_t Cols2> |
sv | 1:6799c07fe510 | 783 | inline |
sv | 1:6799c07fe510 | 784 | XprMatrix< |
sv | 1:6799c07fe510 | 785 | XprMMProductTransposed< |
sv | 1:6799c07fe510 | 786 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 787 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 // M2(Cols1, Cols2) |
sv | 1:6799c07fe510 | 788 | >, |
sv | 1:6799c07fe510 | 789 | Cols2, Rows1 // return Dim |
sv | 1:6799c07fe510 | 790 | > |
sv | 1:6799c07fe510 | 791 | trans_prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Cols1, Cols2>& rhs) { |
sv | 1:6799c07fe510 | 792 | typedef XprMMProductTransposed< |
sv | 1:6799c07fe510 | 793 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, |
sv | 1:6799c07fe510 | 794 | MatrixConstReference<T2, Cols1, Cols2>, Cols2 |
sv | 1:6799c07fe510 | 795 | > expr_type; |
sv | 1:6799c07fe510 | 796 | return XprMatrix<expr_type, Cols2, Rows1>( |
sv | 1:6799c07fe510 | 797 | expr_type(lhs.const_ref(), rhs.const_ref())); |
sv | 1:6799c07fe510 | 798 | } |
sv | 1:6799c07fe510 | 799 | |
sv | 1:6799c07fe510 | 800 | |
sv | 1:6799c07fe510 | 801 | /** |
sv | 1:6799c07fe510 | 802 | * \fn MtM_prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Rows1, Cols2>& rhs) |
sv | 1:6799c07fe510 | 803 | * \brief Function for the trans(matrix)-matrix-product. |
sv | 1:6799c07fe510 | 804 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 805 | * using formula |
sv | 1:6799c07fe510 | 806 | * \f[ |
sv | 1:6799c07fe510 | 807 | * M_1^{T}\,M_2 |
sv | 1:6799c07fe510 | 808 | * \f] |
sv | 1:6799c07fe510 | 809 | * \note The number of cols of matrix 2 have to be equal to number of rows of |
sv | 1:6799c07fe510 | 810 | * matrix 1, since matrix 1 is trans - the result is a (Cols1 x Cols2) |
sv | 1:6799c07fe510 | 811 | * matrix. |
sv | 1:6799c07fe510 | 812 | */ |
sv | 1:6799c07fe510 | 813 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 814 | class T2, std::size_t Cols2> // Rows2 = Rows1 |
sv | 1:6799c07fe510 | 815 | inline |
sv | 1:6799c07fe510 | 816 | XprMatrix< |
sv | 1:6799c07fe510 | 817 | XprMtMProduct< |
sv | 1:6799c07fe510 | 818 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 819 | MatrixConstReference<T2, Rows1, Cols2>, Cols2 // M2(Rows1, Cols2) |
sv | 1:6799c07fe510 | 820 | >, |
sv | 1:6799c07fe510 | 821 | Cols1, Cols2 // return Dim |
sv | 1:6799c07fe510 | 822 | > |
sv | 1:6799c07fe510 | 823 | MtM_prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Rows1, Cols2>& rhs) { |
sv | 1:6799c07fe510 | 824 | typedef XprMtMProduct< |
sv | 1:6799c07fe510 | 825 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, |
sv | 1:6799c07fe510 | 826 | MatrixConstReference<T2, Rows1, Cols2>, Cols2 |
sv | 1:6799c07fe510 | 827 | > expr_type; |
sv | 1:6799c07fe510 | 828 | return XprMatrix<expr_type, Cols1, Cols2>( |
sv | 1:6799c07fe510 | 829 | expr_type(lhs.const_ref(), rhs.const_ref())); |
sv | 1:6799c07fe510 | 830 | } |
sv | 1:6799c07fe510 | 831 | |
sv | 1:6799c07fe510 | 832 | |
sv | 1:6799c07fe510 | 833 | /** |
sv | 1:6799c07fe510 | 834 | * \fn MMt_prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Rows2, Cols1>& rhs) |
sv | 1:6799c07fe510 | 835 | * \brief Function for the matrix-trans(matrix)-product. |
sv | 1:6799c07fe510 | 836 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 837 | * \note The Cols2 has to be equal to Cols1. |
sv | 1:6799c07fe510 | 838 | */ |
sv | 1:6799c07fe510 | 839 | template<class T1, std::size_t Rows1, std::size_t Cols1, |
sv | 1:6799c07fe510 | 840 | class T2, std::size_t Rows2> |
sv | 1:6799c07fe510 | 841 | inline |
sv | 1:6799c07fe510 | 842 | XprMatrix< |
sv | 1:6799c07fe510 | 843 | XprMMtProduct< |
sv | 1:6799c07fe510 | 844 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, // M1(Rows1, Cols1) |
sv | 1:6799c07fe510 | 845 | MatrixConstReference<T2, Rows2, Cols1>, Cols1 // M2(Rows2, Cols1) |
sv | 1:6799c07fe510 | 846 | >, |
sv | 1:6799c07fe510 | 847 | Rows1, Rows2 // return Dim |
sv | 1:6799c07fe510 | 848 | > |
sv | 1:6799c07fe510 | 849 | MMt_prod(const Matrix<T1, Rows1, Cols1>& lhs, const Matrix<T2, Rows2, Cols1>& rhs) { |
sv | 1:6799c07fe510 | 850 | typedef XprMMtProduct< |
sv | 1:6799c07fe510 | 851 | MatrixConstReference<T1, Rows1, Cols1>, Rows1, Cols1, |
sv | 1:6799c07fe510 | 852 | MatrixConstReference<T2, Rows2, Cols1>, Cols1 |
sv | 1:6799c07fe510 | 853 | > expr_type; |
sv | 1:6799c07fe510 | 854 | return XprMatrix<expr_type, Rows1, Rows2>( |
sv | 1:6799c07fe510 | 855 | expr_type(lhs.const_ref(), rhs.const_ref())); |
sv | 1:6799c07fe510 | 856 | } |
sv | 1:6799c07fe510 | 857 | |
sv | 1:6799c07fe510 | 858 | |
sv | 1:6799c07fe510 | 859 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 860 | * matrix-vector specific prod( ... ) functions |
sv | 1:6799c07fe510 | 861 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 862 | |
sv | 1:6799c07fe510 | 863 | |
sv | 1:6799c07fe510 | 864 | /** |
sv | 1:6799c07fe510 | 865 | * \fn prod(const Matrix<T1, Rows, Cols>& lhs, const Vector<T2, Cols>& rhs) |
sv | 1:6799c07fe510 | 866 | * \brief Function for the matrix-vector-product |
sv | 1:6799c07fe510 | 867 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 868 | */ |
sv | 1:6799c07fe510 | 869 | template<class T1, class T2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 870 | inline |
sv | 1:6799c07fe510 | 871 | XprVector< |
sv | 1:6799c07fe510 | 872 | XprMVProduct< |
sv | 1:6799c07fe510 | 873 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, // M(Rows, Cols) |
sv | 1:6799c07fe510 | 874 | VectorConstReference<T2, Cols> // V |
sv | 1:6799c07fe510 | 875 | >, |
sv | 1:6799c07fe510 | 876 | Rows |
sv | 1:6799c07fe510 | 877 | > |
sv | 1:6799c07fe510 | 878 | prod(const Matrix<T1, Rows, Cols>& lhs, const Vector<T2, Cols>& rhs) { |
sv | 1:6799c07fe510 | 879 | typedef XprMVProduct< |
sv | 1:6799c07fe510 | 880 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, |
sv | 1:6799c07fe510 | 881 | VectorConstReference<T2, Cols> |
sv | 1:6799c07fe510 | 882 | > expr_type; |
sv | 1:6799c07fe510 | 883 | return XprVector<expr_type, Rows>( |
sv | 1:6799c07fe510 | 884 | expr_type(lhs.const_ref(), rhs.const_ref())); |
sv | 1:6799c07fe510 | 885 | } |
sv | 1:6799c07fe510 | 886 | |
sv | 1:6799c07fe510 | 887 | |
sv | 1:6799c07fe510 | 888 | /** |
sv | 1:6799c07fe510 | 889 | * \fn prod(const Matrix<T1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) |
sv | 1:6799c07fe510 | 890 | * \brief Function for the matrix-vector-product |
sv | 1:6799c07fe510 | 891 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 892 | */ |
sv | 1:6799c07fe510 | 893 | template<class T1, class E2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 894 | inline |
sv | 1:6799c07fe510 | 895 | XprVector< |
sv | 1:6799c07fe510 | 896 | XprMVProduct< |
sv | 1:6799c07fe510 | 897 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, |
sv | 1:6799c07fe510 | 898 | XprVector<E2, Cols> |
sv | 1:6799c07fe510 | 899 | >, |
sv | 1:6799c07fe510 | 900 | Rows |
sv | 1:6799c07fe510 | 901 | > |
sv | 1:6799c07fe510 | 902 | prod(const Matrix<T1, Rows, Cols>& lhs, const XprVector<E2, Cols>& rhs) { |
sv | 1:6799c07fe510 | 903 | typedef XprMVProduct< |
sv | 1:6799c07fe510 | 904 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, |
sv | 1:6799c07fe510 | 905 | XprVector<E2, Cols> |
sv | 1:6799c07fe510 | 906 | > expr_type; |
sv | 1:6799c07fe510 | 907 | return XprVector<expr_type, Rows>( |
sv | 1:6799c07fe510 | 908 | expr_type(lhs.const_ref(), rhs)); |
sv | 1:6799c07fe510 | 909 | } |
sv | 1:6799c07fe510 | 910 | |
sv | 1:6799c07fe510 | 911 | |
sv | 1:6799c07fe510 | 912 | /* |
sv | 1:6799c07fe510 | 913 | * \fn prod(const XprMatrix<E, Rows, Cols>& lhs, const Vector<T, Cols>& rhs) |
sv | 1:6799c07fe510 | 914 | * \brief Compute the product of an XprMatrix with a Vector. |
sv | 1:6799c07fe510 | 915 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 916 | */ |
sv | 1:6799c07fe510 | 917 | template<class E1, class T2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 918 | inline |
sv | 1:6799c07fe510 | 919 | XprVector< |
sv | 1:6799c07fe510 | 920 | XprMVProduct< |
sv | 1:6799c07fe510 | 921 | XprMatrix<E1, Rows, Cols>, Rows, Cols, // M(Rows, Cols) |
sv | 1:6799c07fe510 | 922 | VectorConstReference<T2, Cols> // V |
sv | 1:6799c07fe510 | 923 | >, |
sv | 1:6799c07fe510 | 924 | Rows |
sv | 1:6799c07fe510 | 925 | > |
sv | 1:6799c07fe510 | 926 | prod(const XprMatrix<E1, Rows, Cols>& lhs, const Vector<T2, Cols>& rhs) { |
sv | 1:6799c07fe510 | 927 | typedef XprMVProduct< |
sv | 1:6799c07fe510 | 928 | XprMatrix<E1, Rows, Cols>, Rows, Cols, |
sv | 1:6799c07fe510 | 929 | VectorConstReference<T2, Cols> |
sv | 1:6799c07fe510 | 930 | > expr_type; |
sv | 1:6799c07fe510 | 931 | return XprVector<expr_type, Rows>( |
sv | 1:6799c07fe510 | 932 | expr_type(lhs, rhs.const_ref())); |
sv | 1:6799c07fe510 | 933 | } |
sv | 1:6799c07fe510 | 934 | |
sv | 1:6799c07fe510 | 935 | |
sv | 1:6799c07fe510 | 936 | /** |
sv | 1:6799c07fe510 | 937 | * \fn Mtx_prod(const Matrix<T1, Rows, Cols>& matrix, const Vector<T2, Rows>& vector) |
sv | 1:6799c07fe510 | 938 | * \brief Function for the trans(matrix)-vector-product |
sv | 1:6799c07fe510 | 939 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 940 | * Perform on given Matrix M and vector x: |
sv | 1:6799c07fe510 | 941 | * \f[ |
sv | 1:6799c07fe510 | 942 | * M^T\, x |
sv | 1:6799c07fe510 | 943 | * \f] |
sv | 1:6799c07fe510 | 944 | */ |
sv | 1:6799c07fe510 | 945 | template<class T1, class T2, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 946 | inline |
sv | 1:6799c07fe510 | 947 | XprVector< |
sv | 1:6799c07fe510 | 948 | XprMtVProduct< |
sv | 1:6799c07fe510 | 949 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, // M(Rows, Cols) |
sv | 1:6799c07fe510 | 950 | VectorConstReference<T2, Rows> // V |
sv | 1:6799c07fe510 | 951 | >, |
sv | 1:6799c07fe510 | 952 | Cols |
sv | 1:6799c07fe510 | 953 | > |
sv | 1:6799c07fe510 | 954 | Mtx_prod(const Matrix<T1, Rows, Cols>& lhs, const Vector<T2, Rows>& rhs) { |
sv | 1:6799c07fe510 | 955 | typedef XprMtVProduct< |
sv | 1:6799c07fe510 | 956 | MatrixConstReference<T1, Rows, Cols>, Rows, Cols, |
sv | 1:6799c07fe510 | 957 | VectorConstReference<T2, Rows> |
sv | 1:6799c07fe510 | 958 | > expr_type; |
sv | 1:6799c07fe510 | 959 | return XprVector<expr_type, Cols>( |
sv | 1:6799c07fe510 | 960 | expr_type(lhs.const_ref(), rhs.const_ref())); |
sv | 1:6799c07fe510 | 961 | } |
sv | 1:6799c07fe510 | 962 | |
sv | 1:6799c07fe510 | 963 | |
sv | 1:6799c07fe510 | 964 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 965 | * matrix specific functions |
sv | 1:6799c07fe510 | 966 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 967 | |
sv | 1:6799c07fe510 | 968 | |
sv | 1:6799c07fe510 | 969 | /** |
sv | 1:6799c07fe510 | 970 | * \fn trans(const Matrix<T, Rows, Cols>& rhs) |
sv | 1:6799c07fe510 | 971 | * \brief Transpose the matrix |
sv | 1:6799c07fe510 | 972 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 973 | */ |
sv | 1:6799c07fe510 | 974 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 975 | inline |
sv | 1:6799c07fe510 | 976 | XprMatrix< |
sv | 1:6799c07fe510 | 977 | XprMatrixTranspose< |
sv | 1:6799c07fe510 | 978 | MatrixConstReference<T, Rows, Cols> |
sv | 1:6799c07fe510 | 979 | >, |
sv | 1:6799c07fe510 | 980 | Cols, Rows |
sv | 1:6799c07fe510 | 981 | > |
sv | 1:6799c07fe510 | 982 | trans(const Matrix<T, Rows, Cols>& rhs) { |
sv | 1:6799c07fe510 | 983 | typedef XprMatrixTranspose< |
sv | 1:6799c07fe510 | 984 | MatrixConstReference<T, Rows, Cols> |
sv | 1:6799c07fe510 | 985 | > expr_type; |
sv | 1:6799c07fe510 | 986 | return XprMatrix<expr_type, Cols, Rows>( |
sv | 1:6799c07fe510 | 987 | expr_type(rhs.const_ref())); |
sv | 1:6799c07fe510 | 988 | } |
sv | 1:6799c07fe510 | 989 | |
sv | 1:6799c07fe510 | 990 | |
sv | 1:6799c07fe510 | 991 | /* |
sv | 1:6799c07fe510 | 992 | * \fn trace(const Matrix<T, Sz, Sz>& m) |
sv | 1:6799c07fe510 | 993 | * \brief Compute the trace of a square matrix. |
sv | 1:6799c07fe510 | 994 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 995 | * |
sv | 1:6799c07fe510 | 996 | * Simply compute the trace of the given matrix as: |
sv | 1:6799c07fe510 | 997 | * \f[ |
sv | 1:6799c07fe510 | 998 | * \sum_{k = 0}^{Sz-1} m(k, k) |
sv | 1:6799c07fe510 | 999 | * \f] |
sv | 1:6799c07fe510 | 1000 | */ |
sv | 1:6799c07fe510 | 1001 | template<class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 1002 | inline |
sv | 1:6799c07fe510 | 1003 | typename NumericTraits<T>::sum_type |
sv | 1:6799c07fe510 | 1004 | trace(const Matrix<T, Sz, Sz>& m) { |
sv | 1:6799c07fe510 | 1005 | return meta::Matrix<Sz, Sz, 0, 0>::trace(m); |
sv | 1:6799c07fe510 | 1006 | } |
sv | 1:6799c07fe510 | 1007 | |
sv | 1:6799c07fe510 | 1008 | |
sv | 1:6799c07fe510 | 1009 | /** |
sv | 1:6799c07fe510 | 1010 | * \fn row(const Matrix<T, Rows, Cols>& m, std::size_t no) |
sv | 1:6799c07fe510 | 1011 | * \brief Returns a row vector of the given matrix. |
sv | 1:6799c07fe510 | 1012 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 1013 | */ |
sv | 1:6799c07fe510 | 1014 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1015 | inline |
sv | 1:6799c07fe510 | 1016 | XprVector< |
sv | 1:6799c07fe510 | 1017 | XprMatrixRow< |
sv | 1:6799c07fe510 | 1018 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 1019 | Rows, Cols |
sv | 1:6799c07fe510 | 1020 | >, |
sv | 1:6799c07fe510 | 1021 | Cols |
sv | 1:6799c07fe510 | 1022 | > |
sv | 1:6799c07fe510 | 1023 | row(const Matrix<T, Rows, Cols>& m, std::size_t no) { |
sv | 1:6799c07fe510 | 1024 | typedef XprMatrixRow< |
sv | 1:6799c07fe510 | 1025 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 1026 | Rows, Cols |
sv | 1:6799c07fe510 | 1027 | > expr_type; |
sv | 1:6799c07fe510 | 1028 | return XprVector<expr_type, Cols>(expr_type(m.const_ref(), no)); |
sv | 1:6799c07fe510 | 1029 | } |
sv | 1:6799c07fe510 | 1030 | |
sv | 1:6799c07fe510 | 1031 | |
sv | 1:6799c07fe510 | 1032 | /** |
sv | 1:6799c07fe510 | 1033 | * \fn col(const Matrix<T, Rows, Cols>& m, std::size_t no) |
sv | 1:6799c07fe510 | 1034 | * \brief Returns a column vector of the given matrix. |
sv | 1:6799c07fe510 | 1035 | * \ingroup _binary_function |
sv | 1:6799c07fe510 | 1036 | */ |
sv | 1:6799c07fe510 | 1037 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1038 | inline |
sv | 1:6799c07fe510 | 1039 | XprVector< |
sv | 1:6799c07fe510 | 1040 | XprMatrixCol< |
sv | 1:6799c07fe510 | 1041 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 1042 | Rows, Cols |
sv | 1:6799c07fe510 | 1043 | >, |
sv | 1:6799c07fe510 | 1044 | Rows |
sv | 1:6799c07fe510 | 1045 | > |
sv | 1:6799c07fe510 | 1046 | col(const Matrix<T, Rows, Cols>& m, std::size_t no) { |
sv | 1:6799c07fe510 | 1047 | typedef XprMatrixCol< |
sv | 1:6799c07fe510 | 1048 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 1049 | Rows, Cols |
sv | 1:6799c07fe510 | 1050 | > expr_type; |
sv | 1:6799c07fe510 | 1051 | return XprVector<expr_type, Rows>(expr_type(m.const_ref(), no)); |
sv | 1:6799c07fe510 | 1052 | } |
sv | 1:6799c07fe510 | 1053 | |
sv | 1:6799c07fe510 | 1054 | |
sv | 1:6799c07fe510 | 1055 | /** |
sv | 1:6799c07fe510 | 1056 | * \fn diag(const Matrix<T, Sz, Sz>& m) |
sv | 1:6799c07fe510 | 1057 | * \brief Returns the diagonal vector of the given square matrix. |
sv | 1:6799c07fe510 | 1058 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1059 | */ |
sv | 1:6799c07fe510 | 1060 | template<class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 1061 | inline |
sv | 1:6799c07fe510 | 1062 | XprVector< |
sv | 1:6799c07fe510 | 1063 | XprMatrixDiag< |
sv | 1:6799c07fe510 | 1064 | MatrixConstReference<T, Sz, Sz>, |
sv | 1:6799c07fe510 | 1065 | Sz |
sv | 1:6799c07fe510 | 1066 | >, |
sv | 1:6799c07fe510 | 1067 | Sz |
sv | 1:6799c07fe510 | 1068 | > |
sv | 1:6799c07fe510 | 1069 | diag(const Matrix<T, Sz, Sz>& m) { |
sv | 1:6799c07fe510 | 1070 | typedef XprMatrixDiag< |
sv | 1:6799c07fe510 | 1071 | MatrixConstReference<T, Sz, Sz>, |
sv | 1:6799c07fe510 | 1072 | Sz |
sv | 1:6799c07fe510 | 1073 | > expr_type; |
sv | 1:6799c07fe510 | 1074 | return XprVector<expr_type, Sz>(expr_type(m.const_ref())); |
sv | 1:6799c07fe510 | 1075 | } |
sv | 1:6799c07fe510 | 1076 | |
sv | 1:6799c07fe510 | 1077 | |
sv | 1:6799c07fe510 | 1078 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 1079 | * min/max unary functions |
sv | 1:6799c07fe510 | 1080 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 1081 | |
sv | 1:6799c07fe510 | 1082 | |
sv | 1:6799c07fe510 | 1083 | /** |
sv | 1:6799c07fe510 | 1084 | * \fn maximum(const XprMatrix<E, Rows, Cols>& e) |
sv | 1:6799c07fe510 | 1085 | * \brief Find the maximum of a matrix expression |
sv | 1:6799c07fe510 | 1086 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1087 | */ |
sv | 1:6799c07fe510 | 1088 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1089 | inline |
sv | 1:6799c07fe510 | 1090 | Extremum<typename E::value_type, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 1091 | maximum(const XprMatrix<E, Rows, Cols>& e) { |
sv | 1:6799c07fe510 | 1092 | typedef typename E::value_type value_type; |
sv | 1:6799c07fe510 | 1093 | |
sv | 1:6799c07fe510 | 1094 | value_type temp(e(0, 0)); |
sv | 1:6799c07fe510 | 1095 | std::size_t row_no(0), col_no(0); |
sv | 1:6799c07fe510 | 1096 | |
sv | 1:6799c07fe510 | 1097 | for(std::size_t i = 0; i != Rows; ++i) { |
sv | 1:6799c07fe510 | 1098 | for(std::size_t j = 0; j != Cols; ++j) { |
sv | 1:6799c07fe510 | 1099 | if(e(i, j) > temp) { |
sv | 1:6799c07fe510 | 1100 | temp = e(i, j); |
sv | 1:6799c07fe510 | 1101 | row_no = i; |
sv | 1:6799c07fe510 | 1102 | col_no = j; |
sv | 1:6799c07fe510 | 1103 | } |
sv | 1:6799c07fe510 | 1104 | } |
sv | 1:6799c07fe510 | 1105 | } |
sv | 1:6799c07fe510 | 1106 | |
sv | 1:6799c07fe510 | 1107 | return Extremum<value_type, std::size_t, matrix_tag>(temp, row_no, col_no); |
sv | 1:6799c07fe510 | 1108 | } |
sv | 1:6799c07fe510 | 1109 | |
sv | 1:6799c07fe510 | 1110 | |
sv | 1:6799c07fe510 | 1111 | /** |
sv | 1:6799c07fe510 | 1112 | * \fn maximum(const Matrix<T, Rows, Cols>& m) |
sv | 1:6799c07fe510 | 1113 | * \brief Find the maximum of a matrix |
sv | 1:6799c07fe510 | 1114 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1115 | */ |
sv | 1:6799c07fe510 | 1116 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1117 | inline |
sv | 1:6799c07fe510 | 1118 | Extremum<T, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 1119 | maximum(const Matrix<T, Rows, Cols>& m) { return maximum(m.as_expr()); } |
sv | 1:6799c07fe510 | 1120 | |
sv | 1:6799c07fe510 | 1121 | |
sv | 1:6799c07fe510 | 1122 | /** |
sv | 1:6799c07fe510 | 1123 | * \fn minimum(const XprMatrix<E, Rows, Cols>& e) |
sv | 1:6799c07fe510 | 1124 | * \brief Find the minimum of a matrix expression |
sv | 1:6799c07fe510 | 1125 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1126 | */ |
sv | 1:6799c07fe510 | 1127 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1128 | inline |
sv | 1:6799c07fe510 | 1129 | Extremum<typename E::value_type, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 1130 | minimum(const XprMatrix<E, Rows, Cols>& e) { |
sv | 1:6799c07fe510 | 1131 | typedef typename E::value_type value_type; |
sv | 1:6799c07fe510 | 1132 | |
sv | 1:6799c07fe510 | 1133 | value_type temp(e(0, 0)); |
sv | 1:6799c07fe510 | 1134 | std::size_t row_no(0), col_no(0); |
sv | 1:6799c07fe510 | 1135 | |
sv | 1:6799c07fe510 | 1136 | for(std::size_t i = 0; i != Rows; ++i) { |
sv | 1:6799c07fe510 | 1137 | for(std::size_t j = 0; j != Cols; ++j) { |
sv | 1:6799c07fe510 | 1138 | if(e(i, j) < temp) { |
sv | 1:6799c07fe510 | 1139 | temp = e(i, j); |
sv | 1:6799c07fe510 | 1140 | row_no = i; |
sv | 1:6799c07fe510 | 1141 | col_no = j; |
sv | 1:6799c07fe510 | 1142 | } |
sv | 1:6799c07fe510 | 1143 | } |
sv | 1:6799c07fe510 | 1144 | } |
sv | 1:6799c07fe510 | 1145 | |
sv | 1:6799c07fe510 | 1146 | return Extremum<value_type, std::size_t, matrix_tag>(temp, row_no, col_no); |
sv | 1:6799c07fe510 | 1147 | } |
sv | 1:6799c07fe510 | 1148 | |
sv | 1:6799c07fe510 | 1149 | |
sv | 1:6799c07fe510 | 1150 | /** |
sv | 1:6799c07fe510 | 1151 | * \fn minimum(const Matrix<T, Rows, Cols>& m) |
sv | 1:6799c07fe510 | 1152 | * \brief Find the minimum of a matrix |
sv | 1:6799c07fe510 | 1153 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1154 | */ |
sv | 1:6799c07fe510 | 1155 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1156 | inline |
sv | 1:6799c07fe510 | 1157 | Extremum<T, std::size_t, matrix_tag> |
sv | 1:6799c07fe510 | 1158 | minimum(const Matrix<T, Rows, Cols>& m) { return minimum(m.as_expr()); } |
sv | 1:6799c07fe510 | 1159 | |
sv | 1:6799c07fe510 | 1160 | |
sv | 1:6799c07fe510 | 1161 | /** |
sv | 1:6799c07fe510 | 1162 | * \fn max(const XprMatrix<E, Rows, Cols>& e) |
sv | 1:6799c07fe510 | 1163 | * \brief Find the maximum of a matrix expression |
sv | 1:6799c07fe510 | 1164 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1165 | */ |
sv | 1:6799c07fe510 | 1166 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1167 | inline |
sv | 1:6799c07fe510 | 1168 | typename E::value_type |
sv | 1:6799c07fe510 | 1169 | max(const XprMatrix<E, Rows, Cols>& e) { |
sv | 1:6799c07fe510 | 1170 | typedef typename E::value_type value_type; |
sv | 1:6799c07fe510 | 1171 | |
sv | 1:6799c07fe510 | 1172 | value_type temp(e(0, 0)); |
sv | 1:6799c07fe510 | 1173 | |
sv | 1:6799c07fe510 | 1174 | for(std::size_t i = 0; i != Rows; ++i) |
sv | 1:6799c07fe510 | 1175 | for(std::size_t j = 0; j != Cols; ++j) |
sv | 1:6799c07fe510 | 1176 | if(e(i, j) > temp) |
sv | 1:6799c07fe510 | 1177 | temp = e(i, j); |
sv | 1:6799c07fe510 | 1178 | |
sv | 1:6799c07fe510 | 1179 | return temp; |
sv | 1:6799c07fe510 | 1180 | } |
sv | 1:6799c07fe510 | 1181 | |
sv | 1:6799c07fe510 | 1182 | |
sv | 1:6799c07fe510 | 1183 | /** |
sv | 1:6799c07fe510 | 1184 | * \fn max(const Matrix<T, Rows, Cols>& m) |
sv | 1:6799c07fe510 | 1185 | * \brief Find the maximum of a matrix |
sv | 1:6799c07fe510 | 1186 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1187 | */ |
sv | 1:6799c07fe510 | 1188 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1189 | inline |
sv | 1:6799c07fe510 | 1190 | T max(const Matrix<T, Rows, Cols>& m) { |
sv | 1:6799c07fe510 | 1191 | typedef T value_type; |
sv | 1:6799c07fe510 | 1192 | typedef typename Matrix< |
sv | 1:6799c07fe510 | 1193 | T, Rows, Cols |
sv | 1:6799c07fe510 | 1194 | >::const_iterator const_iterator; |
sv | 1:6799c07fe510 | 1195 | |
sv | 1:6799c07fe510 | 1196 | const_iterator iter(m.begin()); |
sv | 1:6799c07fe510 | 1197 | const_iterator last(m.end()); |
sv | 1:6799c07fe510 | 1198 | value_type temp(*iter); |
sv | 1:6799c07fe510 | 1199 | |
sv | 1:6799c07fe510 | 1200 | for( ; iter != last; ++iter) |
sv | 1:6799c07fe510 | 1201 | if(*iter > temp) |
sv | 1:6799c07fe510 | 1202 | temp = *iter; |
sv | 1:6799c07fe510 | 1203 | |
sv | 1:6799c07fe510 | 1204 | return temp; |
sv | 1:6799c07fe510 | 1205 | } |
sv | 1:6799c07fe510 | 1206 | |
sv | 1:6799c07fe510 | 1207 | |
sv | 1:6799c07fe510 | 1208 | /** |
sv | 1:6799c07fe510 | 1209 | * \fn min(const XprMatrix<E, Rows, Cols>& e) |
sv | 1:6799c07fe510 | 1210 | * \brief Find the minimum of a matrix expression |
sv | 1:6799c07fe510 | 1211 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1212 | */ |
sv | 1:6799c07fe510 | 1213 | template<class E, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1214 | inline |
sv | 1:6799c07fe510 | 1215 | typename E::value_type |
sv | 1:6799c07fe510 | 1216 | min(const XprMatrix<E, Rows, Cols>& e) { |
sv | 1:6799c07fe510 | 1217 | typedef typename E::value_type value_type; |
sv | 1:6799c07fe510 | 1218 | |
sv | 1:6799c07fe510 | 1219 | value_type temp(e(0, 0)); |
sv | 1:6799c07fe510 | 1220 | |
sv | 1:6799c07fe510 | 1221 | for(std::size_t i = 0; i != Rows; ++i) |
sv | 1:6799c07fe510 | 1222 | for(std::size_t j = 0; j != Cols; ++j) |
sv | 1:6799c07fe510 | 1223 | if(e(i, j) < temp) |
sv | 1:6799c07fe510 | 1224 | temp = e(i, j); |
sv | 1:6799c07fe510 | 1225 | |
sv | 1:6799c07fe510 | 1226 | return temp; |
sv | 1:6799c07fe510 | 1227 | } |
sv | 1:6799c07fe510 | 1228 | |
sv | 1:6799c07fe510 | 1229 | |
sv | 1:6799c07fe510 | 1230 | /** |
sv | 1:6799c07fe510 | 1231 | * \fn min(const Matrix<T, Rows, Cols>& m) |
sv | 1:6799c07fe510 | 1232 | * \brief Find the minimum of a matrix |
sv | 1:6799c07fe510 | 1233 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1234 | */ |
sv | 1:6799c07fe510 | 1235 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1236 | inline |
sv | 1:6799c07fe510 | 1237 | T min(const Matrix<T, Rows, Cols>& m) { |
sv | 1:6799c07fe510 | 1238 | typedef T value_type; |
sv | 1:6799c07fe510 | 1239 | typedef typename Matrix< |
sv | 1:6799c07fe510 | 1240 | T, Rows, Cols |
sv | 1:6799c07fe510 | 1241 | >::const_iterator const_iterator; |
sv | 1:6799c07fe510 | 1242 | |
sv | 1:6799c07fe510 | 1243 | const_iterator iter(m.begin()); |
sv | 1:6799c07fe510 | 1244 | const_iterator last(m.end()); |
sv | 1:6799c07fe510 | 1245 | value_type temp(*iter); |
sv | 1:6799c07fe510 | 1246 | |
sv | 1:6799c07fe510 | 1247 | for( ; iter != last; ++iter) |
sv | 1:6799c07fe510 | 1248 | if(*iter < temp) |
sv | 1:6799c07fe510 | 1249 | temp = *iter; |
sv | 1:6799c07fe510 | 1250 | |
sv | 1:6799c07fe510 | 1251 | return temp; |
sv | 1:6799c07fe510 | 1252 | } |
sv | 1:6799c07fe510 | 1253 | |
sv | 1:6799c07fe510 | 1254 | |
sv | 1:6799c07fe510 | 1255 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
sv | 1:6799c07fe510 | 1256 | * other unary functions |
sv | 1:6799c07fe510 | 1257 | *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
sv | 1:6799c07fe510 | 1258 | |
sv | 1:6799c07fe510 | 1259 | |
sv | 1:6799c07fe510 | 1260 | /** |
sv | 1:6799c07fe510 | 1261 | * \fn XprMatrix<XprIdentity<typename M::value_type, M::Rows, M::Cols>, M::Rows, M::Cols>identity() |
sv | 1:6799c07fe510 | 1262 | * \brief Fill a matrix to an identity matrix. |
sv | 1:6799c07fe510 | 1263 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1264 | * |
sv | 1:6799c07fe510 | 1265 | * \note The matrix doesn't need to be square. Only the elements |
sv | 1:6799c07fe510 | 1266 | * where the current number of rows are equal to columns |
sv | 1:6799c07fe510 | 1267 | * will be set to 1, else to 0. |
sv | 1:6799c07fe510 | 1268 | * |
sv | 1:6799c07fe510 | 1269 | * \par Usage: |
sv | 1:6799c07fe510 | 1270 | * \code |
sv | 1:6799c07fe510 | 1271 | * typedef Matrix<double,3,3> matrix_type; |
sv | 1:6799c07fe510 | 1272 | * ... |
sv | 1:6799c07fe510 | 1273 | * matrix_type E( identity<double, 3, 3>() ); |
sv | 1:6799c07fe510 | 1274 | * \endcode |
sv | 1:6799c07fe510 | 1275 | * |
sv | 1:6799c07fe510 | 1276 | * Note, we have to specify the type, number of rows and columns |
sv | 1:6799c07fe510 | 1277 | * since ADL can't work here. |
sv | 1:6799c07fe510 | 1278 | * |
sv | 1:6799c07fe510 | 1279 | * |
sv | 1:6799c07fe510 | 1280 | * |
sv | 1:6799c07fe510 | 1281 | * \since release 1.6.0 |
sv | 1:6799c07fe510 | 1282 | */ |
sv | 1:6799c07fe510 | 1283 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1284 | inline |
sv | 1:6799c07fe510 | 1285 | XprMatrix< |
sv | 1:6799c07fe510 | 1286 | XprIdentity<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 1287 | Rows, Cols |
sv | 1:6799c07fe510 | 1288 | > |
sv | 1:6799c07fe510 | 1289 | identity() { |
sv | 1:6799c07fe510 | 1290 | typedef XprIdentity<T, Rows, Cols> expr_type; |
sv | 1:6799c07fe510 | 1291 | |
sv | 1:6799c07fe510 | 1292 | return XprMatrix<expr_type, Rows, Cols>(expr_type()); |
sv | 1:6799c07fe510 | 1293 | } |
sv | 1:6799c07fe510 | 1294 | |
sv | 1:6799c07fe510 | 1295 | /** |
sv | 1:6799c07fe510 | 1296 | * \fn XprMatrix<XprIdentity<typename M::value_type, M::Rows, M::Cols>, M::Rows, M::Cols>identity() |
sv | 1:6799c07fe510 | 1297 | * \brief Fill a matrix to an identity matrix (convenience wrapper |
sv | 1:6799c07fe510 | 1298 | * for matrix typedefs). |
sv | 1:6799c07fe510 | 1299 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1300 | * |
sv | 1:6799c07fe510 | 1301 | * \note The matrix doesn't need to be square. Only the elements |
sv | 1:6799c07fe510 | 1302 | * where the current number of rows are equal to columns |
sv | 1:6799c07fe510 | 1303 | * will be set to 1, else to 0. |
sv | 1:6799c07fe510 | 1304 | * |
sv | 1:6799c07fe510 | 1305 | * \par Usage: |
sv | 1:6799c07fe510 | 1306 | * \code |
sv | 1:6799c07fe510 | 1307 | * typedef Matrix<double,3,3> matrix_type; |
sv | 1:6799c07fe510 | 1308 | * ... |
sv | 1:6799c07fe510 | 1309 | * matrix_type E( identity<matrix_type>() ); |
sv | 1:6799c07fe510 | 1310 | * \endcode |
sv | 1:6799c07fe510 | 1311 | * |
sv | 1:6799c07fe510 | 1312 | * Note, we have to specify the matrix type, since ADL can't work here. |
sv | 1:6799c07fe510 | 1313 | * |
sv | 1:6799c07fe510 | 1314 | * \since release 1.6.0 |
sv | 1:6799c07fe510 | 1315 | */ |
sv | 1:6799c07fe510 | 1316 | template<class M> |
sv | 1:6799c07fe510 | 1317 | inline |
sv | 1:6799c07fe510 | 1318 | XprMatrix< |
sv | 1:6799c07fe510 | 1319 | XprIdentity< |
sv | 1:6799c07fe510 | 1320 | typename M::value_type, |
sv | 1:6799c07fe510 | 1321 | M::Rows, M::Cols>, |
sv | 1:6799c07fe510 | 1322 | M::Rows, M::Cols |
sv | 1:6799c07fe510 | 1323 | > |
sv | 1:6799c07fe510 | 1324 | identity() { |
sv | 1:6799c07fe510 | 1325 | return identity<typename M::value_type, M::Rows, M::Cols>(); |
sv | 1:6799c07fe510 | 1326 | } |
sv | 1:6799c07fe510 | 1327 | |
sv | 1:6799c07fe510 | 1328 | |
sv | 1:6799c07fe510 | 1329 | /** |
sv | 1:6799c07fe510 | 1330 | * \fn cmatrix_ref(const T* mem) |
sv | 1:6799c07fe510 | 1331 | * \brief Creates an expression wrapper for a C like matrices. |
sv | 1:6799c07fe510 | 1332 | * \ingroup _unary_function |
sv | 1:6799c07fe510 | 1333 | * |
sv | 1:6799c07fe510 | 1334 | * This is like creating a matrix of external data, as described |
sv | 1:6799c07fe510 | 1335 | * at \ref construct. With this function you wrap an expression |
sv | 1:6799c07fe510 | 1336 | * around a C style matrix and you can operate directly with it |
sv | 1:6799c07fe510 | 1337 | * as usual. |
sv | 1:6799c07fe510 | 1338 | * |
sv | 1:6799c07fe510 | 1339 | * \par Example: |
sv | 1:6799c07fe510 | 1340 | * \code |
sv | 1:6799c07fe510 | 1341 | * static float lhs[3][3] = { |
sv | 1:6799c07fe510 | 1342 | * {-1, 0, 1}, { 1, 0, 1}, {-1, 0, -1} |
sv | 1:6799c07fe510 | 1343 | * }; |
sv | 1:6799c07fe510 | 1344 | * static float rhs[3][3] = { |
sv | 1:6799c07fe510 | 1345 | * { 0, 1, 1}, { 0, 1, -1}, { 0, -1, 1} |
sv | 1:6799c07fe510 | 1346 | * }; |
sv | 1:6799c07fe510 | 1347 | * ... |
sv | 1:6799c07fe510 | 1348 | * |
sv | 1:6799c07fe510 | 1349 | * typedef Matrix<float, 3, 3> matrix_type; |
sv | 1:6799c07fe510 | 1350 | * |
sv | 1:6799c07fe510 | 1351 | * matrix_type M( cmatrix_ref<float, 3, 3>(&lhs[0][0]) |
sv | 1:6799c07fe510 | 1352 | * * cmatrix_ref<float, 3, 3>(&rhs[0][0]) ); |
sv | 1:6799c07fe510 | 1353 | * \endcode |
sv | 1:6799c07fe510 | 1354 | * |
sv | 1:6799c07fe510 | 1355 | * \since release 1.6.0 |
sv | 1:6799c07fe510 | 1356 | */ |
sv | 1:6799c07fe510 | 1357 | template<class T, std::size_t Rows, std::size_t Cols> |
sv | 1:6799c07fe510 | 1358 | inline |
sv | 1:6799c07fe510 | 1359 | XprMatrix< |
sv | 1:6799c07fe510 | 1360 | MatrixConstReference<T, Rows, Cols>, |
sv | 1:6799c07fe510 | 1361 | Rows, Cols |
sv | 1:6799c07fe510 | 1362 | > |
sv | 1:6799c07fe510 | 1363 | cmatrix_ref(const T* mem) { |
sv | 1:6799c07fe510 | 1364 | typedef MatrixConstReference<T, Rows, Cols> expr_type; |
sv | 1:6799c07fe510 | 1365 | |
sv | 1:6799c07fe510 | 1366 | return XprMatrix<expr_type, Rows, Cols>(expr_type(mem)); |
sv | 1:6799c07fe510 | 1367 | } |
sv | 1:6799c07fe510 | 1368 | |
sv | 1:6799c07fe510 | 1369 | |
sv | 1:6799c07fe510 | 1370 | } // namespace tvmet |
sv | 1:6799c07fe510 | 1371 | |
sv | 1:6799c07fe510 | 1372 | #endif // TVMET_MATRIX_FUNCTIONS_H |
sv | 1:6799c07fe510 | 1373 | |
sv | 1:6799c07fe510 | 1374 | // Local Variables: |
sv | 1:6799c07fe510 | 1375 | // mode:C++ |
sv | 1:6799c07fe510 | 1376 | // tab-width:8 |
sv | 1:6799c07fe510 | 1377 | // End: |