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