Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
tvmet/UnaryFunctionals.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: UnaryFunctionals.h,v 1.24 2007-06-23 15:58:58 opetzold Exp $ |
narshu | 25:143b19c1fb05 | 22 | */ |
narshu | 25:143b19c1fb05 | 23 | |
narshu | 25:143b19c1fb05 | 24 | #ifndef TVMET_UNARY_FUNCTIONAL_H |
narshu | 25:143b19c1fb05 | 25 | #define TVMET_UNARY_FUNCTIONAL_H |
narshu | 25:143b19c1fb05 | 26 | |
narshu | 25:143b19c1fb05 | 27 | namespace tvmet { |
narshu | 25:143b19c1fb05 | 28 | |
narshu | 25:143b19c1fb05 | 29 | /** \class Fcnl_compl UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 30 | /** \class Fcnl_neg UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 31 | /** \class Fcnl_not UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 32 | #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ |
narshu | 25:143b19c1fb05 | 33 | template <class T> \ |
narshu | 25:143b19c1fb05 | 34 | struct Fcnl_##NAME : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 35 | typedef T value_type; \ |
narshu | 25:143b19c1fb05 | 36 | \ |
narshu | 25:143b19c1fb05 | 37 | static inline \ |
narshu | 25:143b19c1fb05 | 38 | value_type apply_on(value_type rhs) { \ |
narshu | 25:143b19c1fb05 | 39 | return OP rhs; \ |
narshu | 25:143b19c1fb05 | 40 | } \ |
narshu | 25:143b19c1fb05 | 41 | \ |
narshu | 25:143b19c1fb05 | 42 | static \ |
narshu | 25:143b19c1fb05 | 43 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 44 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 45 | << typeid(T).name() << ">," \ |
narshu | 25:143b19c1fb05 | 46 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 47 | } \ |
narshu | 25:143b19c1fb05 | 48 | }; |
narshu | 25:143b19c1fb05 | 49 | |
narshu | 25:143b19c1fb05 | 50 | TVMET_IMPLEMENT_MACRO(compl, ~) |
narshu | 25:143b19c1fb05 | 51 | TVMET_IMPLEMENT_MACRO(neg, -) |
narshu | 25:143b19c1fb05 | 52 | TVMET_IMPLEMENT_MACRO(not, !) |
narshu | 25:143b19c1fb05 | 53 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 54 | |
narshu | 25:143b19c1fb05 | 55 | |
narshu | 25:143b19c1fb05 | 56 | /** \class Fcnl_abs UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 57 | /** \class Fcnl_ceil UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 58 | /** \class Fcnl_floor UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 59 | /** \class Fcnl_sin UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 60 | /** \class Fcnl_cos UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 61 | /** \class Fcnl_tan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 62 | /** \class Fcnl_sinh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 63 | /** \class Fcnl_cosh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 64 | /** \class Fcnl_tanh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 65 | /** \class Fcnl_asin UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 66 | /** \class Fcnl_acos UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 67 | /** \class Fcnl_atan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 68 | /** \class Fcnl_exp UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 69 | /** \class Fcnl_log UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 70 | /** \class Fcnl_log10 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 71 | /** \class Fcnl_sqrt UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 72 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 73 | template <class T> \ |
narshu | 25:143b19c1fb05 | 74 | struct Fcnl_##NAME : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 75 | typedef T value_type; \ |
narshu | 25:143b19c1fb05 | 76 | \ |
narshu | 25:143b19c1fb05 | 77 | static inline \ |
narshu | 25:143b19c1fb05 | 78 | value_type apply_on(value_type rhs) { \ |
narshu | 25:143b19c1fb05 | 79 | return TVMET_STD_SCOPE(NAME)(rhs); \ |
narshu | 25:143b19c1fb05 | 80 | } \ |
narshu | 25:143b19c1fb05 | 81 | \ |
narshu | 25:143b19c1fb05 | 82 | static \ |
narshu | 25:143b19c1fb05 | 83 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 84 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 85 | << typeid(value_type).name() << ">," \ |
narshu | 25:143b19c1fb05 | 86 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 87 | } \ |
narshu | 25:143b19c1fb05 | 88 | }; |
narshu | 25:143b19c1fb05 | 89 | |
narshu | 25:143b19c1fb05 | 90 | TVMET_IMPLEMENT_MACRO(abs) // specialized later, see below |
narshu | 25:143b19c1fb05 | 91 | TVMET_IMPLEMENT_MACRO(ceil) |
narshu | 25:143b19c1fb05 | 92 | TVMET_IMPLEMENT_MACRO(floor) |
narshu | 25:143b19c1fb05 | 93 | TVMET_IMPLEMENT_MACRO(sin) |
narshu | 25:143b19c1fb05 | 94 | TVMET_IMPLEMENT_MACRO(cos) |
narshu | 25:143b19c1fb05 | 95 | TVMET_IMPLEMENT_MACRO(tan) |
narshu | 25:143b19c1fb05 | 96 | TVMET_IMPLEMENT_MACRO(sinh) |
narshu | 25:143b19c1fb05 | 97 | TVMET_IMPLEMENT_MACRO(cosh) |
narshu | 25:143b19c1fb05 | 98 | TVMET_IMPLEMENT_MACRO(tanh) |
narshu | 25:143b19c1fb05 | 99 | TVMET_IMPLEMENT_MACRO(asin) |
narshu | 25:143b19c1fb05 | 100 | TVMET_IMPLEMENT_MACRO(acos) |
narshu | 25:143b19c1fb05 | 101 | TVMET_IMPLEMENT_MACRO(atan) |
narshu | 25:143b19c1fb05 | 102 | TVMET_IMPLEMENT_MACRO(exp) |
narshu | 25:143b19c1fb05 | 103 | TVMET_IMPLEMENT_MACRO(log) |
narshu | 25:143b19c1fb05 | 104 | TVMET_IMPLEMENT_MACRO(log10) |
narshu | 25:143b19c1fb05 | 105 | TVMET_IMPLEMENT_MACRO(sqrt) |
narshu | 25:143b19c1fb05 | 106 | |
narshu | 25:143b19c1fb05 | 107 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 108 | |
narshu | 25:143b19c1fb05 | 109 | |
narshu | 25:143b19c1fb05 | 110 | /** \class Fcnl_cbrt UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 111 | /** \class Fcnl_rint UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 112 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 113 | template <class T> \ |
narshu | 25:143b19c1fb05 | 114 | struct Fcnl_##NAME : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 115 | typedef T value_type; \ |
narshu | 25:143b19c1fb05 | 116 | \ |
narshu | 25:143b19c1fb05 | 117 | static inline \ |
narshu | 25:143b19c1fb05 | 118 | value_type apply_on(value_type rhs) { \ |
narshu | 25:143b19c1fb05 | 119 | return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ |
narshu | 25:143b19c1fb05 | 120 | } \ |
narshu | 25:143b19c1fb05 | 121 | \ |
narshu | 25:143b19c1fb05 | 122 | static \ |
narshu | 25:143b19c1fb05 | 123 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 124 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 125 | << typeid(value_type).name() << ">," \ |
narshu | 25:143b19c1fb05 | 126 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 127 | } \ |
narshu | 25:143b19c1fb05 | 128 | }; |
narshu | 25:143b19c1fb05 | 129 | |
narshu | 25:143b19c1fb05 | 130 | TVMET_IMPLEMENT_MACRO(cbrt) |
narshu | 25:143b19c1fb05 | 131 | TVMET_IMPLEMENT_MACRO(rint) |
narshu | 25:143b19c1fb05 | 132 | |
narshu | 25:143b19c1fb05 | 133 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 134 | |
narshu | 25:143b19c1fb05 | 135 | |
narshu | 25:143b19c1fb05 | 136 | #if defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 137 | |
narshu | 25:143b19c1fb05 | 138 | /** \class Fcnl_asinh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 139 | /** \class Fcnl_acosh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 140 | /** \class Fcnl_atanh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 141 | /** \class Fcnl_expm1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 142 | /** \class Fcnl_log1p UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 143 | /** \class Fcnl_erf UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 144 | /** \class Fcnl_erfc UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 145 | /** \class Fcnl_j0 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 146 | /** \class Fcnl_j1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 147 | /** \class Fcnl_y0 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 148 | /** \class Fcnl_y1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 149 | /** \class Fcnl_lgamma UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 150 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 151 | template <class T> \ |
narshu | 25:143b19c1fb05 | 152 | struct Fcnl_##NAME : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 153 | typedef T value_type; \ |
narshu | 25:143b19c1fb05 | 154 | \ |
narshu | 25:143b19c1fb05 | 155 | static inline \ |
narshu | 25:143b19c1fb05 | 156 | value_type apply_on(value_type rhs) { \ |
narshu | 25:143b19c1fb05 | 157 | return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ |
narshu | 25:143b19c1fb05 | 158 | } \ |
narshu | 25:143b19c1fb05 | 159 | \ |
narshu | 25:143b19c1fb05 | 160 | static \ |
narshu | 25:143b19c1fb05 | 161 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 162 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 163 | << typeid(value_type).name() << ">," \ |
narshu | 25:143b19c1fb05 | 164 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 165 | } \ |
narshu | 25:143b19c1fb05 | 166 | }; |
narshu | 25:143b19c1fb05 | 167 | |
narshu | 25:143b19c1fb05 | 168 | TVMET_IMPLEMENT_MACRO(asinh) |
narshu | 25:143b19c1fb05 | 169 | TVMET_IMPLEMENT_MACRO(acosh) |
narshu | 25:143b19c1fb05 | 170 | TVMET_IMPLEMENT_MACRO(atanh) |
narshu | 25:143b19c1fb05 | 171 | TVMET_IMPLEMENT_MACRO(expm1) |
narshu | 25:143b19c1fb05 | 172 | TVMET_IMPLEMENT_MACRO(log1p) |
narshu | 25:143b19c1fb05 | 173 | TVMET_IMPLEMENT_MACRO(erf) |
narshu | 25:143b19c1fb05 | 174 | TVMET_IMPLEMENT_MACRO(erfc) |
narshu | 25:143b19c1fb05 | 175 | TVMET_IMPLEMENT_MACRO(j0) |
narshu | 25:143b19c1fb05 | 176 | TVMET_IMPLEMENT_MACRO(j1) |
narshu | 25:143b19c1fb05 | 177 | TVMET_IMPLEMENT_MACRO(y0) |
narshu | 25:143b19c1fb05 | 178 | TVMET_IMPLEMENT_MACRO(y1) |
narshu | 25:143b19c1fb05 | 179 | TVMET_IMPLEMENT_MACRO(lgamma) |
narshu | 25:143b19c1fb05 | 180 | |
narshu | 25:143b19c1fb05 | 181 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 182 | |
narshu | 25:143b19c1fb05 | 183 | #endif // defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 184 | |
narshu | 25:143b19c1fb05 | 185 | |
narshu | 25:143b19c1fb05 | 186 | /** \class Fcnl_abs<long int> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 187 | /** \class Fcnl_abs<long long int> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 188 | /** \class Fcnl_abs<float> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 189 | /** \class Fcnl_abs<double> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 190 | /** \class Fcnl_abs<long double> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 191 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
narshu | 25:143b19c1fb05 | 192 | template <class T> struct Fcnl_##NAME; \ |
narshu | 25:143b19c1fb05 | 193 | template <> \ |
narshu | 25:143b19c1fb05 | 194 | struct Fcnl_##NAME< POD > : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 195 | typedef POD value_type; \ |
narshu | 25:143b19c1fb05 | 196 | \ |
narshu | 25:143b19c1fb05 | 197 | static inline \ |
narshu | 25:143b19c1fb05 | 198 | value_type apply_on(value_type rhs) { \ |
narshu | 25:143b19c1fb05 | 199 | return TVMET_STD_SCOPE(NAME)(rhs); \ |
narshu | 25:143b19c1fb05 | 200 | } \ |
narshu | 25:143b19c1fb05 | 201 | \ |
narshu | 25:143b19c1fb05 | 202 | static \ |
narshu | 25:143b19c1fb05 | 203 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 204 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 205 | << typeid(value_type).name() << ">," \ |
narshu | 25:143b19c1fb05 | 206 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 207 | } \ |
narshu | 25:143b19c1fb05 | 208 | }; |
narshu | 25:143b19c1fb05 | 209 | |
narshu | 25:143b19c1fb05 | 210 | TVMET_IMPLEMENT_MACRO(labs, long int) |
narshu | 25:143b19c1fb05 | 211 | |
narshu | 25:143b19c1fb05 | 212 | #if defined(TVMET_HAVE_LONG_LONG) |
narshu | 25:143b19c1fb05 | 213 | TVMET_IMPLEMENT_MACRO(labs, long long int) |
narshu | 25:143b19c1fb05 | 214 | #endif |
narshu | 25:143b19c1fb05 | 215 | |
narshu | 25:143b19c1fb05 | 216 | TVMET_IMPLEMENT_MACRO(fabs, float) |
narshu | 25:143b19c1fb05 | 217 | TVMET_IMPLEMENT_MACRO(fabs, double) |
narshu | 25:143b19c1fb05 | 218 | |
narshu | 25:143b19c1fb05 | 219 | #if defined(TVMET_HAVE_LONG_DOUBLE) |
narshu | 25:143b19c1fb05 | 220 | TVMET_IMPLEMENT_MACRO(fabs, long double) |
narshu | 25:143b19c1fb05 | 221 | #endif |
narshu | 25:143b19c1fb05 | 222 | |
narshu | 25:143b19c1fb05 | 223 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 224 | |
narshu | 25:143b19c1fb05 | 225 | |
narshu | 25:143b19c1fb05 | 226 | /* |
narshu | 25:143b19c1fb05 | 227 | * complex support |
narshu | 25:143b19c1fb05 | 228 | */ |
narshu | 25:143b19c1fb05 | 229 | |
narshu | 25:143b19c1fb05 | 230 | #if defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 231 | /** |
narshu | 25:143b19c1fb05 | 232 | * \class Fcnl_abs< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" |
narshu | 25:143b19c1fb05 | 233 | */ |
narshu | 25:143b19c1fb05 | 234 | template <class T> |
narshu | 25:143b19c1fb05 | 235 | struct Fcnl_abs< std::complex<T> > : public UnaryFunctional { |
narshu | 25:143b19c1fb05 | 236 | typedef T value_type; |
narshu | 25:143b19c1fb05 | 237 | |
narshu | 25:143b19c1fb05 | 238 | static inline |
narshu | 25:143b19c1fb05 | 239 | value_type apply_on(const std::complex<T>& rhs) { |
narshu | 25:143b19c1fb05 | 240 | return std::abs(rhs); |
narshu | 25:143b19c1fb05 | 241 | } |
narshu | 25:143b19c1fb05 | 242 | |
narshu | 25:143b19c1fb05 | 243 | static |
narshu | 25:143b19c1fb05 | 244 | void print_xpr(std::ostream& os, std::size_t l=0) { |
narshu | 25:143b19c1fb05 | 245 | os << IndentLevel(l) << "Fcnl_abs<T=" |
narshu | 25:143b19c1fb05 | 246 | << typeid(std::complex<T>).name() << ">," |
narshu | 25:143b19c1fb05 | 247 | << std::endl; |
narshu | 25:143b19c1fb05 | 248 | } |
narshu | 25:143b19c1fb05 | 249 | }; |
narshu | 25:143b19c1fb05 | 250 | |
narshu | 25:143b19c1fb05 | 251 | |
narshu | 25:143b19c1fb05 | 252 | /** |
narshu | 25:143b19c1fb05 | 253 | * \class Fcnl_conj< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" |
narshu | 25:143b19c1fb05 | 254 | * \brief %Functional for conj. |
narshu | 25:143b19c1fb05 | 255 | */ |
narshu | 25:143b19c1fb05 | 256 | template <class T> struct Fcnl_conj : public UnaryFunctional { }; |
narshu | 25:143b19c1fb05 | 257 | |
narshu | 25:143b19c1fb05 | 258 | |
narshu | 25:143b19c1fb05 | 259 | /** \class Fcnl_conj< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 260 | template <class T> |
narshu | 25:143b19c1fb05 | 261 | struct Fcnl_conj< std::complex<T> > : public UnaryFunctional { |
narshu | 25:143b19c1fb05 | 262 | typedef std::complex<T> value_type; |
narshu | 25:143b19c1fb05 | 263 | |
narshu | 25:143b19c1fb05 | 264 | static inline |
narshu | 25:143b19c1fb05 | 265 | value_type apply_on(const std::complex<T>& rhs) { |
narshu | 25:143b19c1fb05 | 266 | return std::conj(rhs); |
narshu | 25:143b19c1fb05 | 267 | } |
narshu | 25:143b19c1fb05 | 268 | |
narshu | 25:143b19c1fb05 | 269 | static |
narshu | 25:143b19c1fb05 | 270 | void print_xpr(std::ostream& os, std::size_t l=0) { |
narshu | 25:143b19c1fb05 | 271 | os << IndentLevel(l) << "Fcnl_conj<T=" |
narshu | 25:143b19c1fb05 | 272 | << typeid(std::complex<T>).name() << ">," |
narshu | 25:143b19c1fb05 | 273 | << std::endl; |
narshu | 25:143b19c1fb05 | 274 | } |
narshu | 25:143b19c1fb05 | 275 | }; |
narshu | 25:143b19c1fb05 | 276 | |
narshu | 25:143b19c1fb05 | 277 | |
narshu | 25:143b19c1fb05 | 278 | /** \class Fcnl_real< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 279 | /** \class Fcnl_imag< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 280 | /** \class Fcnl_arg< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 281 | /** \class Fcnl_norm< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 282 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 283 | template <class T> struct Fcnl_##NAME; \ |
narshu | 25:143b19c1fb05 | 284 | template <class T> \ |
narshu | 25:143b19c1fb05 | 285 | struct Fcnl_##NAME< std::complex<T> > : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 286 | typedef T value_type; \ |
narshu | 25:143b19c1fb05 | 287 | \ |
narshu | 25:143b19c1fb05 | 288 | static inline \ |
narshu | 25:143b19c1fb05 | 289 | value_type apply_on(const std::complex<T>& rhs) { \ |
narshu | 25:143b19c1fb05 | 290 | return TVMET_STD_SCOPE(NAME)(rhs); \ |
narshu | 25:143b19c1fb05 | 291 | } \ |
narshu | 25:143b19c1fb05 | 292 | \ |
narshu | 25:143b19c1fb05 | 293 | static \ |
narshu | 25:143b19c1fb05 | 294 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 295 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 296 | << typeid(std::complex<T>).name() << ">," \ |
narshu | 25:143b19c1fb05 | 297 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 298 | } \ |
narshu | 25:143b19c1fb05 | 299 | }; |
narshu | 25:143b19c1fb05 | 300 | |
narshu | 25:143b19c1fb05 | 301 | TVMET_IMPLEMENT_MACRO(real) |
narshu | 25:143b19c1fb05 | 302 | TVMET_IMPLEMENT_MACRO(imag) |
narshu | 25:143b19c1fb05 | 303 | TVMET_IMPLEMENT_MACRO(arg) |
narshu | 25:143b19c1fb05 | 304 | TVMET_IMPLEMENT_MACRO(norm) |
narshu | 25:143b19c1fb05 | 305 | |
narshu | 25:143b19c1fb05 | 306 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 307 | |
narshu | 25:143b19c1fb05 | 308 | #endif // defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 309 | |
narshu | 25:143b19c1fb05 | 310 | |
narshu | 25:143b19c1fb05 | 311 | #if defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 312 | |
narshu | 25:143b19c1fb05 | 313 | /** \class Fcnl_isnan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 314 | /** \class Fcnl_isinf UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 315 | /** \class Fcnl_finite UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 316 | #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ |
narshu | 25:143b19c1fb05 | 317 | template <class T> \ |
narshu | 25:143b19c1fb05 | 318 | struct Fcnl_##NAME : public UnaryFunctional { \ |
narshu | 25:143b19c1fb05 | 319 | typedef T value_type; \ |
narshu | 25:143b19c1fb05 | 320 | \ |
narshu | 25:143b19c1fb05 | 321 | static inline \ |
narshu | 25:143b19c1fb05 | 322 | POD apply_on(T rhs) { \ |
narshu | 25:143b19c1fb05 | 323 | return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ |
narshu | 25:143b19c1fb05 | 324 | } \ |
narshu | 25:143b19c1fb05 | 325 | \ |
narshu | 25:143b19c1fb05 | 326 | static \ |
narshu | 25:143b19c1fb05 | 327 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 328 | os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ |
narshu | 25:143b19c1fb05 | 329 | << typeid(POD).name() << ">," \ |
narshu | 25:143b19c1fb05 | 330 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 331 | } \ |
narshu | 25:143b19c1fb05 | 332 | }; |
narshu | 25:143b19c1fb05 | 333 | |
narshu | 25:143b19c1fb05 | 334 | TVMET_IMPLEMENT_MACRO(isnan, int) |
narshu | 25:143b19c1fb05 | 335 | TVMET_IMPLEMENT_MACRO(isinf, int) |
narshu | 25:143b19c1fb05 | 336 | TVMET_IMPLEMENT_MACRO(finite, int) |
narshu | 25:143b19c1fb05 | 337 | |
narshu | 25:143b19c1fb05 | 338 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 339 | |
narshu | 25:143b19c1fb05 | 340 | #endif // defined(TVMET_HAVE_IEEE_MATH) |
narshu | 25:143b19c1fb05 | 341 | |
narshu | 25:143b19c1fb05 | 342 | } // namespace tvmet |
narshu | 25:143b19c1fb05 | 343 | |
narshu | 25:143b19c1fb05 | 344 | #endif // TVMET_UNARY_FUNCTIONAL_H |
narshu | 25:143b19c1fb05 | 345 | |
narshu | 25:143b19c1fb05 | 346 | // Local Variables: |
narshu | 25:143b19c1fb05 | 347 | // mode:C++ |
narshu | 25:143b19c1fb05 | 348 | // tab-width:8 |
narshu | 25:143b19c1fb05 | 349 | // End: |