2014 Eurobot fork

Dependencies:   mbed-rtos mbed QEI

Committer:
rsavitski
Date:
Tue Oct 15 12:19:32 2013 +0000
Revision:
92:4a1225fbb146
Parent:
15:9c5aaeda36dc
touch: ripped out 2013-specific bits. Need to address "2014" comments. Rewrite AI layer and other deleted parts.

Who changed what in which revision?

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