This is the Tiny Vector Matrix Expression Templates library found at http://tvmet.sourceforge.net. It is the fastest and most compact matrix lib out there (for < 10x10 matricies). I have done some minor tweaks to make it compile for mbed. For examples and hints on how to use, see: http://tvmet.sourceforge.net/usage.html
Dependents: Eurobot_2012_Secondary
UnaryFunctionals.h
00001 /* 00002 * Tiny Vector Matrix Library 00003 * Dense Vector Matrix Libary of Tiny size using Expression Templates 00004 * 00005 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * $Id: UnaryFunctionals.h,v 1.24 2007-06-23 15:58:58 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_UNARY_FUNCTIONAL_H 00025 #define TVMET_UNARY_FUNCTIONAL_H 00026 00027 namespace tvmet { 00028 00029 /** \class Fcnl_compl UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00030 /** \class Fcnl_neg UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00031 /** \class Fcnl_not UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00032 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ 00033 template <class T> \ 00034 struct Fcnl_##NAME : public UnaryFunctional { \ 00035 typedef T value_type; \ 00036 \ 00037 static inline \ 00038 value_type apply_on(value_type rhs) { \ 00039 return OP rhs; \ 00040 } \ 00041 \ 00042 static \ 00043 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00044 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00045 << typeid(T).name() << ">," \ 00046 << std::endl; \ 00047 } \ 00048 }; 00049 00050 TVMET_IMPLEMENT_MACRO(compl, ~) 00051 TVMET_IMPLEMENT_MACRO(neg, -) 00052 TVMET_IMPLEMENT_MACRO(not, !) 00053 #undef TVMET_IMPLEMENT_MACRO 00054 00055 00056 /** \class Fcnl_abs UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00057 /** \class Fcnl_ceil UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00058 /** \class Fcnl_floor UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00059 /** \class Fcnl_sin UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00060 /** \class Fcnl_cos UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00061 /** \class Fcnl_tan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00062 /** \class Fcnl_sinh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00063 /** \class Fcnl_cosh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00064 /** \class Fcnl_tanh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00065 /** \class Fcnl_asin UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00066 /** \class Fcnl_acos UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00067 /** \class Fcnl_atan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00068 /** \class Fcnl_exp UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00069 /** \class Fcnl_log UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00070 /** \class Fcnl_log10 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00071 /** \class Fcnl_sqrt UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00072 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00073 template <class T> \ 00074 struct Fcnl_##NAME : public UnaryFunctional { \ 00075 typedef T value_type; \ 00076 \ 00077 static inline \ 00078 value_type apply_on(value_type rhs) { \ 00079 return TVMET_STD_SCOPE(NAME)(rhs); \ 00080 } \ 00081 \ 00082 static \ 00083 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00084 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00085 << typeid(value_type).name() << ">," \ 00086 << std::endl; \ 00087 } \ 00088 }; 00089 00090 TVMET_IMPLEMENT_MACRO(abs) // specialized later, see below 00091 TVMET_IMPLEMENT_MACRO(ceil) 00092 TVMET_IMPLEMENT_MACRO(floor) 00093 TVMET_IMPLEMENT_MACRO(sin) 00094 TVMET_IMPLEMENT_MACRO(cos) 00095 TVMET_IMPLEMENT_MACRO(tan) 00096 TVMET_IMPLEMENT_MACRO(sinh) 00097 TVMET_IMPLEMENT_MACRO(cosh) 00098 TVMET_IMPLEMENT_MACRO(tanh) 00099 TVMET_IMPLEMENT_MACRO(asin) 00100 TVMET_IMPLEMENT_MACRO(acos) 00101 TVMET_IMPLEMENT_MACRO(atan) 00102 TVMET_IMPLEMENT_MACRO(exp) 00103 TVMET_IMPLEMENT_MACRO(log) 00104 TVMET_IMPLEMENT_MACRO(log10) 00105 TVMET_IMPLEMENT_MACRO(sqrt) 00106 00107 #undef TVMET_IMPLEMENT_MACRO 00108 00109 00110 /** \class Fcnl_cbrt UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00111 /** \class Fcnl_rint UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00112 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00113 template <class T> \ 00114 struct Fcnl_##NAME : public UnaryFunctional { \ 00115 typedef T value_type; \ 00116 \ 00117 static inline \ 00118 value_type apply_on(value_type rhs) { \ 00119 return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ 00120 } \ 00121 \ 00122 static \ 00123 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00124 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00125 << typeid(value_type).name() << ">," \ 00126 << std::endl; \ 00127 } \ 00128 }; 00129 00130 TVMET_IMPLEMENT_MACRO(cbrt) 00131 TVMET_IMPLEMENT_MACRO(rint) 00132 00133 #undef TVMET_IMPLEMENT_MACRO 00134 00135 00136 #if defined(TVMET_HAVE_IEEE_MATH) 00137 00138 /** \class Fcnl_asinh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00139 /** \class Fcnl_acosh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00140 /** \class Fcnl_atanh UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00141 /** \class Fcnl_expm1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00142 /** \class Fcnl_log1p UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00143 /** \class Fcnl_erf UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00144 /** \class Fcnl_erfc UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00145 /** \class Fcnl_j0 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00146 /** \class Fcnl_j1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00147 /** \class Fcnl_y0 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00148 /** \class Fcnl_y1 UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00149 /** \class Fcnl_lgamma UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00150 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00151 template <class T> \ 00152 struct Fcnl_##NAME : public UnaryFunctional { \ 00153 typedef T value_type; \ 00154 \ 00155 static inline \ 00156 value_type apply_on(value_type rhs) { \ 00157 return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ 00158 } \ 00159 \ 00160 static \ 00161 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00162 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00163 << typeid(value_type).name() << ">," \ 00164 << std::endl; \ 00165 } \ 00166 }; 00167 00168 TVMET_IMPLEMENT_MACRO(asinh) 00169 TVMET_IMPLEMENT_MACRO(acosh) 00170 TVMET_IMPLEMENT_MACRO(atanh) 00171 TVMET_IMPLEMENT_MACRO(expm1) 00172 TVMET_IMPLEMENT_MACRO(log1p) 00173 TVMET_IMPLEMENT_MACRO(erf) 00174 TVMET_IMPLEMENT_MACRO(erfc) 00175 TVMET_IMPLEMENT_MACRO(j0) 00176 TVMET_IMPLEMENT_MACRO(j1) 00177 TVMET_IMPLEMENT_MACRO(y0) 00178 TVMET_IMPLEMENT_MACRO(y1) 00179 TVMET_IMPLEMENT_MACRO(lgamma) 00180 00181 #undef TVMET_IMPLEMENT_MACRO 00182 00183 #endif // defined(TVMET_HAVE_IEEE_MATH) 00184 00185 00186 /** \class Fcnl_abs<long int> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00187 /** \class Fcnl_abs<long long int> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00188 /** \class Fcnl_abs<float> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00189 /** \class Fcnl_abs<double> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00190 /** \class Fcnl_abs<long double> UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00191 #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ 00192 template <class T> struct Fcnl_##NAME; \ 00193 template <> \ 00194 struct Fcnl_##NAME< POD > : public UnaryFunctional { \ 00195 typedef POD value_type; \ 00196 \ 00197 static inline \ 00198 value_type apply_on(value_type rhs) { \ 00199 return TVMET_STD_SCOPE(NAME)(rhs); \ 00200 } \ 00201 \ 00202 static \ 00203 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00204 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00205 << typeid(value_type).name() << ">," \ 00206 << std::endl; \ 00207 } \ 00208 }; 00209 00210 TVMET_IMPLEMENT_MACRO(labs, long int) 00211 00212 #if defined(TVMET_HAVE_LONG_LONG) 00213 TVMET_IMPLEMENT_MACRO(labs, long long int) 00214 #endif 00215 00216 TVMET_IMPLEMENT_MACRO(fabs, float) 00217 TVMET_IMPLEMENT_MACRO(fabs, double) 00218 00219 #if defined(TVMET_HAVE_LONG_DOUBLE) 00220 TVMET_IMPLEMENT_MACRO(fabs, long double) 00221 #endif 00222 00223 #undef TVMET_IMPLEMENT_MACRO 00224 00225 00226 /* 00227 * complex support 00228 */ 00229 00230 #if defined(TVMET_HAVE_COMPLEX) 00231 /** 00232 * \class Fcnl_abs< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" 00233 */ 00234 template <class T> 00235 struct Fcnl_abs< std::complex<T> > : public UnaryFunctional { 00236 typedef T value_type; 00237 00238 static inline 00239 value_type apply_on(const std::complex<T>& rhs) { 00240 return std::abs(rhs); 00241 } 00242 00243 static 00244 void print_xpr(std::ostream& os, std::size_t l=0) { 00245 os << IndentLevel(l) << "Fcnl_abs<T=" 00246 << typeid(std::complex<T>).name() << ">," 00247 << std::endl; 00248 } 00249 }; 00250 00251 00252 /** 00253 * \class Fcnl_conj< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" 00254 * \brief %Functional for conj. 00255 */ 00256 template <class T> struct Fcnl_conj : public UnaryFunctional { }; 00257 00258 00259 /** \class Fcnl_conj< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00260 template <class T> 00261 struct Fcnl_conj< std::complex<T> > : public UnaryFunctional { 00262 typedef std::complex<T> value_type; 00263 00264 static inline 00265 value_type apply_on(const std::complex<T>& rhs) { 00266 return std::conj(rhs); 00267 } 00268 00269 static 00270 void print_xpr(std::ostream& os, std::size_t l=0) { 00271 os << IndentLevel(l) << "Fcnl_conj<T=" 00272 << typeid(std::complex<T>).name() << ">," 00273 << std::endl; 00274 } 00275 }; 00276 00277 00278 /** \class Fcnl_real< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00279 /** \class Fcnl_imag< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00280 /** \class Fcnl_arg< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00281 /** \class Fcnl_norm< std::complex<T> > UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00282 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00283 template <class T> struct Fcnl_##NAME; \ 00284 template <class T> \ 00285 struct Fcnl_##NAME< std::complex<T> > : public UnaryFunctional { \ 00286 typedef T value_type; \ 00287 \ 00288 static inline \ 00289 value_type apply_on(const std::complex<T>& rhs) { \ 00290 return TVMET_STD_SCOPE(NAME)(rhs); \ 00291 } \ 00292 \ 00293 static \ 00294 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00295 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00296 << typeid(std::complex<T>).name() << ">," \ 00297 << std::endl; \ 00298 } \ 00299 }; 00300 00301 TVMET_IMPLEMENT_MACRO(real) 00302 TVMET_IMPLEMENT_MACRO(imag) 00303 TVMET_IMPLEMENT_MACRO(arg) 00304 TVMET_IMPLEMENT_MACRO(norm) 00305 00306 #undef TVMET_IMPLEMENT_MACRO 00307 00308 #endif // defined(TVMET_HAVE_COMPLEX) 00309 00310 00311 #if defined(TVMET_HAVE_IEEE_MATH) 00312 00313 /** \class Fcnl_isnan UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00314 /** \class Fcnl_isinf UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00315 /** \class Fcnl_finite UnaryFunctionals.h "tvmet/UnaryFunctionals.h" */ 00316 #define TVMET_IMPLEMENT_MACRO(NAME, POD) \ 00317 template <class T> \ 00318 struct Fcnl_##NAME : public UnaryFunctional { \ 00319 typedef T value_type; \ 00320 \ 00321 static inline \ 00322 POD apply_on(T rhs) { \ 00323 return TVMET_GLOBAL_SCOPE(NAME)(rhs); \ 00324 } \ 00325 \ 00326 static \ 00327 void print_xpr(std::ostream& os, std::size_t l=0) { \ 00328 os << IndentLevel(l) << "Fcnl_" << #NAME << "<T=" \ 00329 << typeid(POD).name() << ">," \ 00330 << std::endl; \ 00331 } \ 00332 }; 00333 00334 TVMET_IMPLEMENT_MACRO(isnan, int) 00335 TVMET_IMPLEMENT_MACRO(isinf, int) 00336 TVMET_IMPLEMENT_MACRO(finite, int) 00337 00338 #undef TVMET_IMPLEMENT_MACRO 00339 00340 #endif // defined(TVMET_HAVE_IEEE_MATH) 00341 00342 } // namespace tvmet 00343 00344 #endif // TVMET_UNARY_FUNCTIONAL_H 00345 00346 // Local Variables: 00347 // mode:C++ 00348 // tab-width:8 00349 // End:
Generated on Tue Jul 12 2022 19:00:12 by 1.7.2