Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
tvmet/MatrixUnaryFunctions.h@26:0995f61cb7b8, 2012-10-17 (annotated)
- 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?
User | Revision | Line number | New 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: MatrixUnaryFunctions.h,v 1.13 2007-06-23 15:58:58 opetzold Exp $ |
narshu | 25:143b19c1fb05 | 22 | */ |
narshu | 25:143b19c1fb05 | 23 | |
narshu | 25:143b19c1fb05 | 24 | #ifndef TVMET_MATRIX_UNARY_FUNCTIONS_H |
narshu | 25:143b19c1fb05 | 25 | #define TVMET_MATRIX_UNARY_FUNCTIONS_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 | * unary_function(Matrix<T, Rows, Cols>) |
narshu | 25:143b19c1fb05 | 36 | */ |
narshu | 25:143b19c1fb05 | 37 | #define TVMET_DECLARE_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 38 | template<class T, std::size_t Rows, std::size_t Cols> \ |
narshu | 25:143b19c1fb05 | 39 | inline \ |
narshu | 25:143b19c1fb05 | 40 | XprMatrix< \ |
narshu | 25:143b19c1fb05 | 41 | XprUnOp< \ |
narshu | 25:143b19c1fb05 | 42 | Fcnl_##NAME<T>, \ |
narshu | 25:143b19c1fb05 | 43 | MatrixConstReference<T, Rows, Cols> \ |
narshu | 25:143b19c1fb05 | 44 | >, \ |
narshu | 25:143b19c1fb05 | 45 | Rows, Cols \ |
narshu | 25:143b19c1fb05 | 46 | > \ |
narshu | 25:143b19c1fb05 | 47 | NAME(const Matrix<T, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
narshu | 25:143b19c1fb05 | 48 | |
narshu | 25:143b19c1fb05 | 49 | TVMET_DECLARE_MACRO(abs) |
narshu | 25:143b19c1fb05 | 50 | TVMET_DECLARE_MACRO(cbrt) |
narshu | 25:143b19c1fb05 | 51 | TVMET_DECLARE_MACRO(ceil) |
narshu | 25:143b19c1fb05 | 52 | TVMET_DECLARE_MACRO(floor) |
narshu | 25:143b19c1fb05 | 53 | TVMET_DECLARE_MACRO(rint) |
narshu | 25:143b19c1fb05 | 54 | TVMET_DECLARE_MACRO(sin) |
narshu | 25:143b19c1fb05 | 55 | TVMET_DECLARE_MACRO(cos) |
narshu | 25:143b19c1fb05 | 56 | TVMET_DECLARE_MACRO(tan) |
narshu | 25:143b19c1fb05 | 57 | TVMET_DECLARE_MACRO(sinh) |
narshu | 25:143b19c1fb05 | 58 | TVMET_DECLARE_MACRO(cosh) |
narshu | 25:143b19c1fb05 | 59 | TVMET_DECLARE_MACRO(tanh) |
narshu | 25:143b19c1fb05 | 60 | TVMET_DECLARE_MACRO(asin) |
narshu | 25:143b19c1fb05 | 61 | TVMET_DECLARE_MACRO(acos) |
narshu | 25:143b19c1fb05 | 62 | TVMET_DECLARE_MACRO(atan) |
narshu | 25:143b19c1fb05 | 63 | TVMET_DECLARE_MACRO(exp) |
narshu | 25:143b19c1fb05 | 64 | TVMET_DECLARE_MACRO(log) |
narshu | 25:143b19c1fb05 | 65 | TVMET_DECLARE_MACRO(log10) |
narshu | 25:143b19c1fb05 | 66 | TVMET_DECLARE_MACRO(sqrt) |
narshu | 25:143b19c1fb05 | 67 | |
narshu | 25:143b19c1fb05 | 68 | #if defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 69 | TVMET_DECLARE_MACRO(asinh) |
narshu | 25:143b19c1fb05 | 70 | TVMET_DECLARE_MACRO(acosh) |
narshu | 25:143b19c1fb05 | 71 | TVMET_DECLARE_MACRO(atanh) |
narshu | 25:143b19c1fb05 | 72 | TVMET_DECLARE_MACRO(expm1) |
narshu | 25:143b19c1fb05 | 73 | TVMET_DECLARE_MACRO(log1p) |
narshu | 25:143b19c1fb05 | 74 | TVMET_DECLARE_MACRO(erf) |
narshu | 25:143b19c1fb05 | 75 | TVMET_DECLARE_MACRO(erfc) |
narshu | 25:143b19c1fb05 | 76 | TVMET_DECLARE_MACRO(j0) |
narshu | 25:143b19c1fb05 | 77 | TVMET_DECLARE_MACRO(j1) |
narshu | 25:143b19c1fb05 | 78 | TVMET_DECLARE_MACRO(y0) |
narshu | 25:143b19c1fb05 | 79 | TVMET_DECLARE_MACRO(y1) |
narshu | 25:143b19c1fb05 | 80 | TVMET_DECLARE_MACRO(lgamma) |
narshu | 25:143b19c1fb05 | 81 | /** \todo isnan etc. - default return is only an int! */ |
narshu | 25:143b19c1fb05 | 82 | |
narshu | 25:143b19c1fb05 | 83 | TVMET_DECLARE_MACRO(finite) |
narshu | 25:143b19c1fb05 | 84 | #endif // defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 85 | |
narshu | 25:143b19c1fb05 | 86 | #undef TVMET_DECLARE_MACRO |
narshu | 25:143b19c1fb05 | 87 | |
narshu | 25:143b19c1fb05 | 88 | |
narshu | 25:143b19c1fb05 | 89 | /* |
narshu | 25:143b19c1fb05 | 90 | * unary_function(Matrix<std::complex<T>, Rows, Cols>) |
narshu | 25:143b19c1fb05 | 91 | */ |
narshu | 25:143b19c1fb05 | 92 | #if defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 93 | #define TVMET_DECLARE_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 94 | template<class T, std::size_t Rows, std::size_t Cols> \ |
narshu | 25:143b19c1fb05 | 95 | inline \ |
narshu | 25:143b19c1fb05 | 96 | XprMatrix< \ |
narshu | 25:143b19c1fb05 | 97 | XprUnOp< \ |
narshu | 25:143b19c1fb05 | 98 | Fcnl_##NAME< std::complex<T> >, \ |
narshu | 25:143b19c1fb05 | 99 | MatrixConstReference<std::complex<T>, Rows, Cols> \ |
narshu | 25:143b19c1fb05 | 100 | >, \ |
narshu | 25:143b19c1fb05 | 101 | Rows, Cols \ |
narshu | 25:143b19c1fb05 | 102 | > \ |
narshu | 25:143b19c1fb05 | 103 | NAME(const Matrix<std::complex<T>, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE; |
narshu | 25:143b19c1fb05 | 104 | |
narshu | 25:143b19c1fb05 | 105 | TVMET_DECLARE_MACRO(real) |
narshu | 25:143b19c1fb05 | 106 | TVMET_DECLARE_MACRO(imag) |
narshu | 25:143b19c1fb05 | 107 | TVMET_DECLARE_MACRO(arg) |
narshu | 25:143b19c1fb05 | 108 | TVMET_DECLARE_MACRO(norm) |
narshu | 25:143b19c1fb05 | 109 | TVMET_DECLARE_MACRO(conj) |
narshu | 25:143b19c1fb05 | 110 | |
narshu | 25:143b19c1fb05 | 111 | #undef TVMET_DECLARE_MACRO |
narshu | 25:143b19c1fb05 | 112 | |
narshu | 25:143b19c1fb05 | 113 | #endif // defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 114 | |
narshu | 25:143b19c1fb05 | 115 | |
narshu | 25:143b19c1fb05 | 116 | /********************************************************* |
narshu | 25:143b19c1fb05 | 117 | * PART II: IMPLEMENTATION |
narshu | 25:143b19c1fb05 | 118 | *********************************************************/ |
narshu | 25:143b19c1fb05 | 119 | |
narshu | 25:143b19c1fb05 | 120 | |
narshu | 25:143b19c1fb05 | 121 | /* |
narshu | 25:143b19c1fb05 | 122 | * unary_function(Matrix<T, Rows, Cols>) |
narshu | 25:143b19c1fb05 | 123 | */ |
narshu | 25:143b19c1fb05 | 124 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 125 | template<class T, std::size_t Rows, std::size_t Cols> \ |
narshu | 25:143b19c1fb05 | 126 | inline \ |
narshu | 25:143b19c1fb05 | 127 | XprMatrix< \ |
narshu | 25:143b19c1fb05 | 128 | XprUnOp< \ |
narshu | 25:143b19c1fb05 | 129 | Fcnl_##NAME<T>, \ |
narshu | 25:143b19c1fb05 | 130 | MatrixConstReference<T, Rows, Cols> \ |
narshu | 25:143b19c1fb05 | 131 | >, \ |
narshu | 25:143b19c1fb05 | 132 | Rows, Cols \ |
narshu | 25:143b19c1fb05 | 133 | > \ |
narshu | 25:143b19c1fb05 | 134 | NAME(const Matrix<T, Rows, Cols>& rhs) { \ |
narshu | 25:143b19c1fb05 | 135 | typedef XprUnOp< \ |
narshu | 25:143b19c1fb05 | 136 | Fcnl_##NAME<T>, \ |
narshu | 25:143b19c1fb05 | 137 | MatrixConstReference<T, Rows, Cols> \ |
narshu | 25:143b19c1fb05 | 138 | > expr_type; \ |
narshu | 25:143b19c1fb05 | 139 | return XprMatrix<expr_type, Rows, Cols>(expr_type(rhs.const_ref())); \ |
narshu | 25:143b19c1fb05 | 140 | } |
narshu | 25:143b19c1fb05 | 141 | |
narshu | 25:143b19c1fb05 | 142 | TVMET_IMPLEMENT_MACRO(abs) |
narshu | 25:143b19c1fb05 | 143 | TVMET_IMPLEMENT_MACRO(cbrt) |
narshu | 25:143b19c1fb05 | 144 | TVMET_IMPLEMENT_MACRO(ceil) |
narshu | 25:143b19c1fb05 | 145 | TVMET_IMPLEMENT_MACRO(floor) |
narshu | 25:143b19c1fb05 | 146 | TVMET_IMPLEMENT_MACRO(rint) |
narshu | 25:143b19c1fb05 | 147 | TVMET_IMPLEMENT_MACRO(sin) |
narshu | 25:143b19c1fb05 | 148 | TVMET_IMPLEMENT_MACRO(cos) |
narshu | 25:143b19c1fb05 | 149 | TVMET_IMPLEMENT_MACRO(tan) |
narshu | 25:143b19c1fb05 | 150 | TVMET_IMPLEMENT_MACRO(sinh) |
narshu | 25:143b19c1fb05 | 151 | TVMET_IMPLEMENT_MACRO(cosh) |
narshu | 25:143b19c1fb05 | 152 | TVMET_IMPLEMENT_MACRO(tanh) |
narshu | 25:143b19c1fb05 | 153 | TVMET_IMPLEMENT_MACRO(asin) |
narshu | 25:143b19c1fb05 | 154 | TVMET_IMPLEMENT_MACRO(acos) |
narshu | 25:143b19c1fb05 | 155 | TVMET_IMPLEMENT_MACRO(atan) |
narshu | 25:143b19c1fb05 | 156 | TVMET_IMPLEMENT_MACRO(exp) |
narshu | 25:143b19c1fb05 | 157 | TVMET_IMPLEMENT_MACRO(log) |
narshu | 25:143b19c1fb05 | 158 | TVMET_IMPLEMENT_MACRO(log10) |
narshu | 25:143b19c1fb05 | 159 | TVMET_IMPLEMENT_MACRO(sqrt) |
narshu | 25:143b19c1fb05 | 160 | |
narshu | 25:143b19c1fb05 | 161 | #if defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 162 | TVMET_IMPLEMENT_MACRO(asinh) |
narshu | 25:143b19c1fb05 | 163 | TVMET_IMPLEMENT_MACRO(acosh) |
narshu | 25:143b19c1fb05 | 164 | TVMET_IMPLEMENT_MACRO(atanh) |
narshu | 25:143b19c1fb05 | 165 | TVMET_IMPLEMENT_MACRO(expm1) |
narshu | 25:143b19c1fb05 | 166 | TVMET_IMPLEMENT_MACRO(log1p) |
narshu | 25:143b19c1fb05 | 167 | TVMET_IMPLEMENT_MACRO(erf) |
narshu | 25:143b19c1fb05 | 168 | TVMET_IMPLEMENT_MACRO(erfc) |
narshu | 25:143b19c1fb05 | 169 | TVMET_IMPLEMENT_MACRO(j0) |
narshu | 25:143b19c1fb05 | 170 | TVMET_IMPLEMENT_MACRO(j1) |
narshu | 25:143b19c1fb05 | 171 | TVMET_IMPLEMENT_MACRO(y0) |
narshu | 25:143b19c1fb05 | 172 | TVMET_IMPLEMENT_MACRO(y1) |
narshu | 25:143b19c1fb05 | 173 | TVMET_IMPLEMENT_MACRO(lgamma) |
narshu | 25:143b19c1fb05 | 174 | /** \todo isnan etc. - default return is only an int! */ |
narshu | 25:143b19c1fb05 | 175 | |
narshu | 25:143b19c1fb05 | 176 | TVMET_IMPLEMENT_MACRO(finite) |
narshu | 25:143b19c1fb05 | 177 | #endif // defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 178 | |
narshu | 25:143b19c1fb05 | 179 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 180 | |
narshu | 25:143b19c1fb05 | 181 | |
narshu | 25:143b19c1fb05 | 182 | /* |
narshu | 25:143b19c1fb05 | 183 | * unary_function(Matrix<std::complex<T>, Rows, Cols>) |
narshu | 25:143b19c1fb05 | 184 | */ |
narshu | 25:143b19c1fb05 | 185 | #if defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 186 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 187 | template<class T, std::size_t Rows, std::size_t Cols> \ |
narshu | 25:143b19c1fb05 | 188 | inline \ |
narshu | 25:143b19c1fb05 | 189 | XprMatrix< \ |
narshu | 25:143b19c1fb05 | 190 | XprUnOp< \ |
narshu | 25:143b19c1fb05 | 191 | Fcnl_##NAME< std::complex<T> >, \ |
narshu | 25:143b19c1fb05 | 192 | MatrixConstReference<std::complex<T>, Rows, Cols> \ |
narshu | 25:143b19c1fb05 | 193 | >, \ |
narshu | 25:143b19c1fb05 | 194 | Rows, Cols \ |
narshu | 25:143b19c1fb05 | 195 | > \ |
narshu | 25:143b19c1fb05 | 196 | NAME(const Matrix<std::complex<T>, Rows, Cols>& rhs) { \ |
narshu | 25:143b19c1fb05 | 197 | typedef XprUnOp< \ |
narshu | 25:143b19c1fb05 | 198 | Fcnl_##NAME< std::complex<T> >, \ |
narshu | 25:143b19c1fb05 | 199 | MatrixConstReference<std::complex<T>, Rows, Cols> \ |
narshu | 25:143b19c1fb05 | 200 | > expr_type; \ |
narshu | 25:143b19c1fb05 | 201 | return XprMatrix<expr_type, Rows, Cols>(expr_type(rhs.const_ref())); \ |
narshu | 25:143b19c1fb05 | 202 | } |
narshu | 25:143b19c1fb05 | 203 | |
narshu | 25:143b19c1fb05 | 204 | TVMET_IMPLEMENT_MACRO(real) |
narshu | 25:143b19c1fb05 | 205 | TVMET_IMPLEMENT_MACRO(imag) |
narshu | 25:143b19c1fb05 | 206 | TVMET_IMPLEMENT_MACRO(arg) |
narshu | 25:143b19c1fb05 | 207 | TVMET_IMPLEMENT_MACRO(norm) |
narshu | 25:143b19c1fb05 | 208 | TVMET_IMPLEMENT_MACRO(conj) |
narshu | 25:143b19c1fb05 | 209 | |
narshu | 25:143b19c1fb05 | 210 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 211 | |
narshu | 25:143b19c1fb05 | 212 | #endif // defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 213 | |
narshu | 25:143b19c1fb05 | 214 | |
narshu | 25:143b19c1fb05 | 215 | } // namespace tvmet |
narshu | 25:143b19c1fb05 | 216 | |
narshu | 25:143b19c1fb05 | 217 | #endif // TVMET_MATRIX_UNARY_FUNCTIONS_H |
narshu | 25:143b19c1fb05 | 218 | |
narshu | 25:143b19c1fb05 | 219 | // Local Variables: |
narshu | 25:143b19c1fb05 | 220 | // mode:C++ |
narshu | 25:143b19c1fb05 | 221 | // tab-width:8 |
narshu | 25:143b19c1fb05 | 222 | // End: |