ICRS Eurobot 2013

Dependencies:   mbed mbed-rtos Servo QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MatrixBinaryFunctions.h Source File

MatrixBinaryFunctions.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: MatrixBinaryFunctions.h,v 1.12 2007-06-23 15:59:00 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_XPR_MATRIX_BINARY_FUNCTIONS_H
00025 #define TVMET_XPR_MATRIX_BINARY_FUNCTIONS_H
00026 
00027 namespace tvmet {
00028 
00029 
00030 /*********************************************************
00031  * PART I: DECLARATION
00032  *********************************************************/
00033 
00034 /*
00035  * binary_function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>)
00036  */
00037 #define TVMET_DECLARE_MACRO(NAME)                    \
00038 template<class E1, std::size_t Rows, std::size_t Cols, class E2>    \
00039 XprMatrix<                                \
00040   XprBinOp<                                \
00041     Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,    \
00042     XprMatrix<E1, Rows, Cols>,                        \
00043     XprMatrix<E2, Rows, Cols>                        \
00044   >,                                    \
00045   Rows, Cols                                \
00046 >                                    \
00047 NAME(const XprMatrix<E1, Rows, Cols>& lhs,                 \
00048      const XprMatrix<E2, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
00049 
00050 TVMET_DECLARE_MACRO(atan2)
00051 TVMET_DECLARE_MACRO(drem)
00052 TVMET_DECLARE_MACRO(fmod)
00053 TVMET_DECLARE_MACRO(hypot)
00054 TVMET_DECLARE_MACRO(jn)
00055 TVMET_DECLARE_MACRO(yn)
00056 TVMET_DECLARE_MACRO(pow)
00057 #if defined(TVMET_HAVE_COMPLEX)
00058   //TVMET_DECLARE_MACRO(polar)
00059 #endif
00060 
00061 #undef TVMET_DECLARE_MACRO
00062 
00063 
00064 /*
00065  * binary_function(XprMatrix<E, Rows, Cols>, POD)
00066  */
00067 #define TVMET_DECLARE_MACRO(NAME, TP)            \
00068 template<class E, std::size_t Rows, std::size_t Cols>    \
00069 XprMatrix<                        \
00070   XprBinOp<                        \
00071     Fcnl_##NAME<typename E::value_type, TP >,        \
00072     XprMatrix<E, Rows, Cols>,                \
00073     XprLiteral< TP >                    \
00074   >,                            \
00075   Rows, Cols                        \
00076 >                            \
00077 NAME(const XprMatrix<E, Rows, Cols>& lhs,         \
00078      TP rhs) TVMET_CXX_ALWAYS_INLINE;
00079 
00080 TVMET_DECLARE_MACRO(atan2, int)
00081 TVMET_DECLARE_MACRO(drem, int)
00082 TVMET_DECLARE_MACRO(fmod, int)
00083 TVMET_DECLARE_MACRO(hypot, int)
00084 TVMET_DECLARE_MACRO(jn, int)
00085 TVMET_DECLARE_MACRO(yn, int)
00086 TVMET_DECLARE_MACRO(pow, int)
00087 
00088 #if defined(TVMET_HAVE_LONG_LONG)
00089 TVMET_DECLARE_MACRO(atan2, long long int)
00090 TVMET_DECLARE_MACRO(drem, long long int)
00091 TVMET_DECLARE_MACRO(fmod, long long int)
00092 TVMET_DECLARE_MACRO(hypot, long long int)
00093 TVMET_DECLARE_MACRO(jn, long long int)
00094 TVMET_DECLARE_MACRO(yn,long long int)
00095 TVMET_DECLARE_MACRO(pow, long long int)
00096 #endif // defined(TVMET_HAVE_LONG_LONG)
00097 
00098 TVMET_DECLARE_MACRO(atan2, float)
00099 TVMET_DECLARE_MACRO(drem, float)
00100 TVMET_DECLARE_MACRO(fmod, float)
00101 TVMET_DECLARE_MACRO(hypot, float)
00102 TVMET_DECLARE_MACRO(jn, float)
00103 TVMET_DECLARE_MACRO(yn, float)
00104 TVMET_DECLARE_MACRO(pow, float)
00105 
00106 TVMET_DECLARE_MACRO(atan2, double)
00107 TVMET_DECLARE_MACRO(drem, double)
00108 TVMET_DECLARE_MACRO(fmod, double)
00109 TVMET_DECLARE_MACRO(hypot,double)
00110 TVMET_DECLARE_MACRO(jn, double)
00111 TVMET_DECLARE_MACRO(yn, double)
00112 TVMET_DECLARE_MACRO(pow, double)
00113 
00114 #if defined(TVMET_HAVE_LONG_DOUBLE)
00115 TVMET_DECLARE_MACRO(atan2, long double)
00116 TVMET_DECLARE_MACRO(drem, long double)
00117 TVMET_DECLARE_MACRO(fmod, long double)
00118 TVMET_DECLARE_MACRO(hypot, long double)
00119 TVMET_DECLARE_MACRO(jn, long double)
00120 TVMET_DECLARE_MACRO(yn, long double)
00121 TVMET_DECLARE_MACRO(pow, long double)
00122 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
00123 
00124 #undef TVMET_DECLARE_MACRO
00125 
00126 
00127 #if defined(TVMET_HAVE_COMPLEX)
00128 /*
00129  * binary_function(XprMatrix<E, Rows, Cols>, std::complex<>)
00130  */
00131 #define TVMET_DECLARE_MACRO(NAME)                \
00132 template<class E, std::size_t Rows, std::size_t Cols, class T>    \
00133 XprMatrix<                            \
00134   XprBinOp<                            \
00135     Fcnl_##NAME<typename E::value_type, std::complex<T> >,    \
00136     XprMatrix<E, Rows, Cols>,                    \
00137     XprLiteral< std::complex<T> >                \
00138   >,                                \
00139   Rows, Cols                            \
00140 >                                \
00141 NAME(const XprMatrix<E, Rows, Cols>& lhs,             \
00142      const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE;
00143 
00144 TVMET_DECLARE_MACRO(pow)
00145 
00146 TVMET_DECLARE_MACRO(atan2)
00147 TVMET_DECLARE_MACRO(drem)
00148 TVMET_DECLARE_MACRO(fmod)
00149 TVMET_DECLARE_MACRO(hypot)
00150 TVMET_DECLARE_MACRO(jn)
00151 TVMET_DECLARE_MACRO(yn)
00152 
00153 #undef TVMET_DECLARE_MACRO
00154 
00155 #endif // defined(TVMET_HAVE_COMPLEX)
00156 
00157 
00158 /*********************************************************
00159  * PART II: IMPLEMENTATION
00160  *********************************************************/
00161 
00162 
00163 /*
00164  * binary_function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>)
00165  */
00166 #define TVMET_IMPLEMENT_MACRO(NAME)                            \
00167 template<class E1, std::size_t Rows, std::size_t Cols, class E2>            \
00168 inline                                            \
00169 XprMatrix<                                        \
00170   XprBinOp<                                        \
00171     Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,            \
00172     XprMatrix<E1, Rows, Cols>,                                \
00173     XprMatrix<E2, Rows, Cols>                                \
00174   >,                                            \
00175   Rows, Cols                                        \
00176 >                                            \
00177 NAME(const XprMatrix<E1, Rows, Cols>& lhs, const XprMatrix<E2, Rows, Cols>& rhs) {    \
00178   typedef XprBinOp<                                    \
00179     Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,            \
00180     XprMatrix<E1, Rows, Cols>,                                \
00181     XprMatrix<E2, Rows, Cols>                                \
00182   >                                expr_type;            \
00183   return XprMatrix<expr_type, Rows, Cols>(                        \
00184     expr_type(lhs, rhs));                                \
00185 }
00186 
00187 TVMET_IMPLEMENT_MACRO(atan2)
00188 TVMET_IMPLEMENT_MACRO(drem)
00189 TVMET_IMPLEMENT_MACRO(fmod)
00190 TVMET_IMPLEMENT_MACRO(hypot)
00191 TVMET_IMPLEMENT_MACRO(jn)
00192 TVMET_IMPLEMENT_MACRO(yn)
00193 TVMET_IMPLEMENT_MACRO(pow)
00194 #if defined(TVMET_HAVE_COMPLEX)
00195   //TVMET_IMPLEMENT_MACRO(polar)
00196 #endif
00197 
00198 #undef TVMET_IMPLEMENT_MACRO
00199 
00200 
00201 /*
00202  * binary_function(XprMatrix<E, Rows, Cols>, POD)
00203  */
00204 #define TVMET_IMPLEMENT_MACRO(NAME, TP)                    \
00205 template<class E, std::size_t Rows, std::size_t Cols>            \
00206 inline                                    \
00207 XprMatrix<                                \
00208   XprBinOp<                                \
00209     Fcnl_##NAME<typename E::value_type, TP >,                \
00210     XprMatrix<E, Rows, Cols>,                        \
00211     XprLiteral< TP >                            \
00212   >,                                    \
00213   Rows, Cols                                \
00214 >                                    \
00215 NAME(const XprMatrix<E, Rows, Cols>& lhs, TP rhs) {            \
00216   typedef XprBinOp<                            \
00217     Fcnl_##NAME<typename E::value_type, TP >,                \
00218     XprMatrix<E, Rows, Cols>,                        \
00219     XprLiteral< TP >                            \
00220   >                            expr_type;    \
00221   return XprMatrix<expr_type, Rows, Cols>(                \
00222     expr_type(lhs, XprLiteral< TP >(rhs)));                \
00223 }
00224 
00225 TVMET_IMPLEMENT_MACRO(atan2, int)
00226 TVMET_IMPLEMENT_MACRO(drem, int)
00227 TVMET_IMPLEMENT_MACRO(fmod, int)
00228 TVMET_IMPLEMENT_MACRO(hypot, int)
00229 TVMET_IMPLEMENT_MACRO(jn, int)
00230 TVMET_IMPLEMENT_MACRO(yn, int)
00231 TVMET_IMPLEMENT_MACRO(pow, int)
00232 
00233 #if defined(TVMET_HAVE_LONG_LONG)
00234 TVMET_IMPLEMENT_MACRO(atan2, long long int)
00235 TVMET_IMPLEMENT_MACRO(drem, long long int)
00236 TVMET_IMPLEMENT_MACRO(fmod, long long int)
00237 TVMET_IMPLEMENT_MACRO(hypot, long long int)
00238 TVMET_IMPLEMENT_MACRO(jn, long long int)
00239 TVMET_IMPLEMENT_MACRO(yn,long long int)
00240 TVMET_IMPLEMENT_MACRO(pow, long long int)
00241 #endif // defined(TVMET_HAVE_LONG_LONG)
00242 
00243 TVMET_IMPLEMENT_MACRO(atan2, float)
00244 TVMET_IMPLEMENT_MACRO(drem, float)
00245 TVMET_IMPLEMENT_MACRO(fmod, float)
00246 TVMET_IMPLEMENT_MACRO(hypot, float)
00247 TVMET_IMPLEMENT_MACRO(jn, float)
00248 TVMET_IMPLEMENT_MACRO(yn, float)
00249 TVMET_IMPLEMENT_MACRO(pow, float)
00250 
00251 TVMET_IMPLEMENT_MACRO(atan2, double)
00252 TVMET_IMPLEMENT_MACRO(drem, double)
00253 TVMET_IMPLEMENT_MACRO(fmod, double)
00254 TVMET_IMPLEMENT_MACRO(hypot,double)
00255 TVMET_IMPLEMENT_MACRO(jn, double)
00256 TVMET_IMPLEMENT_MACRO(yn, double)
00257 TVMET_IMPLEMENT_MACRO(pow, double)
00258 
00259 #if defined(TVMET_HAVE_LONG_DOUBLE)
00260 TVMET_IMPLEMENT_MACRO(atan2, long double)
00261 TVMET_IMPLEMENT_MACRO(drem, long double)
00262 TVMET_IMPLEMENT_MACRO(fmod, long double)
00263 TVMET_IMPLEMENT_MACRO(hypot, long double)
00264 TVMET_IMPLEMENT_MACRO(jn, long double)
00265 TVMET_IMPLEMENT_MACRO(yn, long double)
00266 TVMET_IMPLEMENT_MACRO(pow, long double)
00267 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
00268 
00269 #undef TVMET_IMPLEMENT_MACRO
00270 
00271 
00272 #if defined(TVMET_HAVE_COMPLEX)
00273 /*
00274  * binary_function(XprMatrix<E, Rows, Cols>, std::complex<>)
00275  */
00276 #define TVMET_IMPLEMENT_MACRO(NAME)                    \
00277 template<class E, std::size_t Rows, std::size_t Cols, class T>        \
00278 inline                                    \
00279 XprMatrix<                                \
00280   XprBinOp<                                \
00281     Fcnl_##NAME<typename E::value_type, std::complex<T> >,        \
00282     XprMatrix<E, Rows, Cols>,                        \
00283     XprLiteral< std::complex<T> >                    \
00284   >,                                    \
00285   Rows, Cols                                \
00286 >                                    \
00287 NAME(const XprMatrix<E, Rows, Cols>& lhs, const std::complex<T>& rhs) {    \
00288   typedef XprBinOp<                            \
00289     Fcnl_##NAME<typename E::value_type, std::complex<T> >,        \
00290     XprMatrix<E, Rows, Cols>,                        \
00291     XprLiteral< std::complex<T> >                    \
00292   >                            expr_type;    \
00293   return XprMatrix<expr_type, Rows, Cols>(                \
00294     expr_type(lhs, XprLiteral< std::complex<T> >(rhs)));        \
00295 }
00296 
00297 TVMET_IMPLEMENT_MACRO(pow)
00298 
00299 TVMET_IMPLEMENT_MACRO(atan2)
00300 TVMET_IMPLEMENT_MACRO(drem)
00301 TVMET_IMPLEMENT_MACRO(fmod)
00302 TVMET_IMPLEMENT_MACRO(hypot)
00303 TVMET_IMPLEMENT_MACRO(jn)
00304 TVMET_IMPLEMENT_MACRO(yn)
00305 
00306 #undef TVMET_IMPLEMENT_MACRO
00307 
00308 #endif // defined(TVMET_HAVE_COMPLEX)
00309 
00310 
00311 } // namespace tvmet
00312 
00313 #endif // TVMET_XPR_MATRIX_BINARY_FUNCTIONS_H
00314 
00315 // Local Variables:
00316 // mode:C++
00317 // tab-width:8
00318 // End: