Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:47 2012 +0000
Revision:
26:0995f61cb7b8
Parent:
25:143b19c1fb05
Eurobot 2012 Primary;

Who changed what in which revision?

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