SourceForge Logo Tiny Vector Matrix library using Expression Templates Sourceforge Project Page

include/tvmet/xpr/MatrixBinaryFunctions.h
Go to the documentation of this file.
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.13 2008/02/08 19:13:26 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(fmod)
00052 TVMET_DECLARE_MACRO(pow)
00053 #if defined(TVMET_HAVE_DREM)
00054 TVMET_DECLARE_MACRO(drem)
00055 #endif
00056 #if defined(TVMET_HAVE_HYPOT)
00057 TVMET_DECLARE_MACRO(hypot)
00058 #endif
00059 #if defined(TVMET_HAVE_JN)
00060 TVMET_DECLARE_MACRO(jn)
00061 #endif
00062 #if defined(TVMET_HAVE_YN)
00063 TVMET_DECLARE_MACRO(yn)
00064 #endif
00065 
00066 #undef TVMET_DECLARE_MACRO
00067 
00068 
00069 /*
00070  * binary_function(XprMatrix<E, Rows, Cols>, POD)
00071  */
00072 #define TVMET_DECLARE_MACRO(NAME, TP)     \
00073 template<class E, std::size_t Rows, std::size_t Cols> \
00074 XprMatrix<            \
00075   XprBinOp<           \
00076     Fcnl_##NAME<typename E::value_type, TP >,   \
00077     XprMatrix<E, Rows, Cols>,       \
00078     XprLiteral< TP >          \
00079   >,              \
00080   Rows, Cols            \
00081 >             \
00082 NAME(const XprMatrix<E, Rows, Cols>& lhs,     \
00083      TP rhs) TVMET_CXX_ALWAYS_INLINE;
00084 
00085 TVMET_DECLARE_MACRO(atan2, int)
00086 TVMET_DECLARE_MACRO(fmod, int)
00087 TVMET_DECLARE_MACRO(pow, int)
00088 #if defined(TVMET_HAVE_DREM)
00089 TVMET_DECLARE_MACRO(drem, int)
00090 #endif
00091 #if defined(TVMET_HAVE_HYPOT)
00092 TVMET_DECLARE_MACRO(hypot, int)
00093 #endif
00094 #if defined(TVMET_HAVE_JN)
00095 TVMET_DECLARE_MACRO(jn, int)
00096 #endif
00097 #if defined(TVMET_HAVE_YN)
00098 TVMET_DECLARE_MACRO(yn, int)
00099 #endif
00100 
00101 
00102 #if defined(TVMET_HAVE_LONG_LONG)
00103 TVMET_DECLARE_MACRO(atan2, long long int)
00104 TVMET_DECLARE_MACRO(fmod, long long int)
00105 TVMET_DECLARE_MACRO(pow, long long int)
00106 #if defined(TVMET_HAVE_DREM)
00107 TVMET_DECLARE_MACRO(drem, long long int)
00108 #endif
00109 #if defined(TVMET_HAVE_HYPOT)
00110 TVMET_DECLARE_MACRO(hypot, long long int)
00111 #endif
00112 #if defined(TVMET_HAVE_JN)
00113 TVMET_DECLARE_MACRO(jn, long long int)
00114 #endif
00115 #if defined(TVMET_HAVE_YN)
00116 TVMET_DECLARE_MACRO(yn, long long int)
00117 #endif
00118 #endif // defined(TVMET_HAVE_LONG_LONG)
00119 
00120 
00121 TVMET_DECLARE_MACRO(atan2, float)
00122 TVMET_DECLARE_MACRO(fmod, float)
00123 TVMET_DECLARE_MACRO(pow, float)
00124 #if defined(TVMET_HAVE_DREM)
00125 TVMET_DECLARE_MACRO(drem, float)
00126 #endif
00127 #if defined(TVMET_HAVE_HYPOT)
00128 TVMET_DECLARE_MACRO(hypot, float)
00129 #endif
00130 #if defined(TVMET_HAVE_JN)
00131 TVMET_DECLARE_MACRO(jn, float)
00132 #endif
00133 #if defined(TVMET_HAVE_YN)
00134 TVMET_DECLARE_MACRO(yn, float)
00135 #endif
00136 
00137 
00138 TVMET_DECLARE_MACRO(atan2, double)
00139 TVMET_DECLARE_MACRO(fmod, double)
00140 TVMET_DECLARE_MACRO(pow, double)
00141 #if defined(TVMET_HAVE_DREM)
00142 TVMET_DECLARE_MACRO(drem, double)
00143 #endif
00144 #if defined(TVMET_HAVE_HYPOT)
00145 TVMET_DECLARE_MACRO(hypot, double)
00146 #endif
00147 #if defined(TVMET_HAVE_JN)
00148 TVMET_DECLARE_MACRO(jn, double)
00149 #endif
00150 #if defined(TVMET_HAVE_YN)
00151 TVMET_DECLARE_MACRO(yn, double)
00152 #endif
00153 
00154 
00155 #if defined(TVMET_HAVE_LONG_DOUBLE)
00156 TVMET_DECLARE_MACRO(atan2, long double)
00157 TVMET_DECLARE_MACRO(fmod, long double)
00158 TVMET_DECLARE_MACRO(pow, long double)
00159 #if defined(TVMET_HAVE_DREM)
00160 TVMET_DECLARE_MACRO(drem, long double)
00161 #endif
00162 #if defined(TVMET_HAVE_HYPOT)
00163 TVMET_DECLARE_MACRO(hypot, long double)
00164 #endif
00165 #if defined(TVMET_HAVE_JN)
00166 TVMET_DECLARE_MACRO(jn, long double)
00167 #endif
00168 #if defined(TVMET_HAVE_YN)
00169 TVMET_DECLARE_MACRO(yn, long double)
00170 #endif
00171 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
00172 
00173 #undef TVMET_DECLARE_MACRO
00174 
00175 
00176 #if defined(TVMET_HAVE_COMPLEX)
00177 /*
00178  * binary_function(XprMatrix<E, Rows, Cols>, std::complex<>)
00179  */
00180 #define TVMET_DECLARE_MACRO(NAME)       \
00181 template<class E, std::size_t Rows, std::size_t Cols, class T>  \
00182 XprMatrix<              \
00183   XprBinOp<             \
00184     Fcnl_##NAME<typename E::value_type, std::complex<T> >,  \
00185     XprMatrix<E, Rows, Cols>,         \
00186     XprLiteral< std::complex<T> >       \
00187   >,                \
00188   Rows, Cols              \
00189 >               \
00190 NAME(const XprMatrix<E, Rows, Cols>& lhs,       \
00191      const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE;
00192 
00193 
00194 TVMET_DECLARE_MACRO(atan2)
00195 TVMET_DECLARE_MACRO(fmod)
00196 TVMET_DECLARE_MACRO(pow)
00197 #if defined(TVMET_HAVE_DREM)
00198 TVMET_DECLARE_MACRO(drem)
00199 #endif
00200 #if defined(TVMET_HAVE_HYPOT)
00201 TVMET_DECLARE_MACRO(hypot)
00202 #endif
00203 #if defined(TVMET_HAVE_JN)
00204 TVMET_DECLARE_MACRO(jn)
00205 #endif
00206 #if defined(TVMET_HAVE_YN)
00207 TVMET_DECLARE_MACRO(yn)
00208 #endif
00209 
00210 #undef TVMET_DECLARE_MACRO
00211 
00212 #endif // defined(TVMET_HAVE_COMPLEX)
00213 
00214 
00215 /*********************************************************
00216  * PART II: IMPLEMENTATION
00217  *********************************************************/
00218 
00219 
00220 /*
00221  * binary_function(XprMatrix<E1, Rows, Cols>, XprMatrix<E2, Rows, Cols>)
00222  */
00223 #define TVMET_IMPLEMENT_MACRO(NAME)             \
00224 template<class E1, std::size_t Rows, std::size_t Cols, class E2>      \
00225 inline                      \
00226 XprMatrix<                    \
00227   XprBinOp<                   \
00228     Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,      \
00229     XprMatrix<E1, Rows, Cols>,                \
00230     XprMatrix<E2, Rows, Cols>               \
00231   >,                      \
00232   Rows, Cols                    \
00233 >                     \
00234 NAME(const XprMatrix<E1, Rows, Cols>& lhs, const XprMatrix<E2, Rows, Cols>& rhs) {  \
00235   typedef XprBinOp<                 \
00236     Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,      \
00237     XprMatrix<E1, Rows, Cols>,                \
00238     XprMatrix<E2, Rows, Cols>               \
00239   >                 expr_type;      \
00240   return XprMatrix<expr_type, Rows, Cols>(            \
00241     expr_type(lhs, rhs));               \
00242 }
00243 
00244 TVMET_IMPLEMENT_MACRO(atan2)
00245 TVMET_IMPLEMENT_MACRO(fmod)
00246 TVMET_IMPLEMENT_MACRO(pow)
00247 #if defined(TVMET_HAVE_DREM)
00248 TVMET_IMPLEMENT_MACRO(drem)
00249 #endif
00250 #if defined(TVMET_HAVE_HYPOT)
00251 TVMET_IMPLEMENT_MACRO(hypot)
00252 #endif
00253 #if defined(TVMET_HAVE_JN)
00254 TVMET_IMPLEMENT_MACRO(jn)
00255 #endif
00256 #if defined(TVMET_HAVE_YN)
00257 TVMET_IMPLEMENT_MACRO(yn)
00258 #endif
00259 
00260 #undef TVMET_IMPLEMENT_MACRO
00261 
00262 
00263 /*
00264  * binary_function(XprMatrix<E, Rows, Cols>, POD)
00265  */
00266 #define TVMET_IMPLEMENT_MACRO(NAME, TP)         \
00267 template<class E, std::size_t Rows, std::size_t Cols>     \
00268 inline                  \
00269 XprMatrix<                \
00270   XprBinOp<               \
00271     Fcnl_##NAME<typename E::value_type, TP >,       \
00272     XprMatrix<E, Rows, Cols>,           \
00273     XprLiteral< TP >              \
00274   >,                  \
00275   Rows, Cols                \
00276 >                 \
00277 NAME(const XprMatrix<E, Rows, Cols>& lhs, TP rhs) {     \
00278   typedef XprBinOp<             \
00279     Fcnl_##NAME<typename E::value_type, TP >,       \
00280     XprMatrix<E, Rows, Cols>,           \
00281     XprLiteral< TP >              \
00282   >             expr_type;  \
00283   return XprMatrix<expr_type, Rows, Cols>(        \
00284     expr_type(lhs, XprLiteral< TP >(rhs)));       \
00285 }
00286 
00287 TVMET_IMPLEMENT_MACRO(atan2, int)
00288 TVMET_IMPLEMENT_MACRO(fmod, int)
00289 TVMET_IMPLEMENT_MACRO(pow, int)
00290 #if defined(TVMET_HAVE_DREM)
00291 TVMET_IMPLEMENT_MACRO(drem, int)
00292 #endif
00293 #if defined(TVMET_HAVE_HYPOT)
00294 TVMET_IMPLEMENT_MACRO(hypot, int)
00295 #endif
00296 #if defined(TVMET_HAVE_JN)
00297 TVMET_IMPLEMENT_MACRO(jn, int)
00298 #endif
00299 #if defined(TVMET_HAVE_YN)
00300 TVMET_IMPLEMENT_MACRO(yn, int)
00301 #endif
00302 
00303 
00304 #if defined(TVMET_HAVE_LONG_LONG)
00305 TVMET_IMPLEMENT_MACRO(atan2, long long int)
00306 TVMET_IMPLEMENT_MACRO(fmod, long long int)
00307 TVMET_IMPLEMENT_MACRO(pow, long long int)
00308 #if defined(TVMET_HAVE_DREM)
00309 TVMET_IMPLEMENT_MACRO(drem, long long int)
00310 #endif
00311 #if defined(TVMET_HAVE_HYPOT)
00312 TVMET_IMPLEMENT_MACRO(hypot, long long int)
00313 #endif
00314 #if defined(TVMET_HAVE_JN)
00315 TVMET_IMPLEMENT_MACRO(jn, long long int)
00316 #endif
00317 #if defined(TVMET_HAVE_YN)
00318 TVMET_IMPLEMENT_MACRO(yn, long long int)
00319 #endif
00320 #endif // defined(TVMET_HAVE_LONG_LONG)
00321 
00322 
00323 TVMET_IMPLEMENT_MACRO(atan2, float)
00324 TVMET_IMPLEMENT_MACRO(fmod, float)
00325 TVMET_IMPLEMENT_MACRO(pow, float)
00326 #if defined(TVMET_HAVE_DREM)
00327 TVMET_IMPLEMENT_MACRO(drem, float)
00328 #endif
00329 #if defined(TVMET_HAVE_HYPOT)
00330 TVMET_IMPLEMENT_MACRO(hypot, float)
00331 #endif
00332 #if defined(TVMET_HAVE_JN)
00333 TVMET_IMPLEMENT_MACRO(jn, float)
00334 #endif
00335 #if defined(TVMET_HAVE_YN)
00336 TVMET_IMPLEMENT_MACRO(yn, float)
00337 #endif
00338 
00339 
00340 TVMET_IMPLEMENT_MACRO(atan2, double)
00341 TVMET_IMPLEMENT_MACRO(fmod, double)
00342 TVMET_IMPLEMENT_MACRO(pow, double)
00343 #if defined(TVMET_HAVE_DREM)
00344 TVMET_IMPLEMENT_MACRO(drem, double)
00345 #endif
00346 #if defined(TVMET_HAVE_HYPOT)
00347 TVMET_IMPLEMENT_MACRO(hypot, double)
00348 #endif
00349 #if defined(TVMET_HAVE_JN)
00350 TVMET_IMPLEMENT_MACRO(jn, double)
00351 #endif
00352 #if defined(TVMET_HAVE_YN)
00353 TVMET_IMPLEMENT_MACRO(yn, double)
00354 #endif
00355 
00356 
00357 #if defined(TVMET_HAVE_LONG_DOUBLE)
00358 TVMET_IMPLEMENT_MACRO(atan2, long double)
00359 TVMET_IMPLEMENT_MACRO(fmod, long double)
00360 TVMET_IMPLEMENT_MACRO(pow, long double)
00361 #if defined(TVMET_HAVE_DREM)
00362 TVMET_IMPLEMENT_MACRO(drem, long double)
00363 #endif
00364 #if defined(TVMET_HAVE_HYPOT)
00365 TVMET_IMPLEMENT_MACRO(hypot, long double)
00366 #endif
00367 #if defined(TVMET_HAVE_JN)
00368 TVMET_IMPLEMENT_MACRO(jn, long double)
00369 #endif
00370 #if defined(TVMET_HAVE_YN)
00371 TVMET_IMPLEMENT_MACRO(yn, long double)
00372 #endif
00373 #endif // defined(TVMET_HAVE_LONG_DOUBLE)
00374 
00375 #undef TVMET_IMPLEMENT_MACRO
00376 
00377 
00378 /*
00379  * complex support
00380  */
00381 
00382 #if defined(TVMET_HAVE_COMPLEX)
00383 /*
00384  * binary_function(XprMatrix<E, Rows, Cols>, std::complex<>)
00385  */
00386 #define TVMET_IMPLEMENT_MACRO(NAME)         \
00387 template<class E, std::size_t Rows, std::size_t Cols, class T>    \
00388 inline                  \
00389 XprMatrix<                \
00390   XprBinOp<               \
00391     Fcnl_##NAME<typename E::value_type, std::complex<T> >,    \
00392     XprMatrix<E, Rows, Cols>,           \
00393     XprLiteral< std::complex<T> >         \
00394   >,                  \
00395   Rows, Cols                \
00396 >                 \
00397 NAME(const XprMatrix<E, Rows, Cols>& lhs, const std::complex<T>& rhs) { \
00398   typedef XprBinOp<             \
00399     Fcnl_##NAME<typename E::value_type, std::complex<T> >,    \
00400     XprMatrix<E, Rows, Cols>,           \
00401     XprLiteral< std::complex<T> >         \
00402   >             expr_type;  \
00403   return XprMatrix<expr_type, Rows, Cols>(        \
00404     expr_type(lhs, XprLiteral< std::complex<T> >(rhs)));    \
00405 }
00406 
00407 TVMET_IMPLEMENT_MACRO(atan2)
00408 TVMET_IMPLEMENT_MACRO(pow)
00409 TVMET_IMPLEMENT_MACRO(fmod)
00410 #if defined(TVMET_HAVE_DREM)
00411 TVMET_IMPLEMENT_MACRO(drem)
00412 #endif
00413 #if defined(TVMET_HAVE_HYPOT)
00414 TVMET_IMPLEMENT_MACRO(hypot)
00415 #endif
00416 #if defined(TVMET_HAVE_JN)
00417 TVMET_IMPLEMENT_MACRO(jn)
00418 #endif
00419 #if defined(TVMET_HAVE_YN)
00420 TVMET_IMPLEMENT_MACRO(yn)
00421 #endif
00422 
00423 #undef TVMET_IMPLEMENT_MACRO
00424 
00425 #endif // defined(TVMET_HAVE_COMPLEX)
00426 
00427 
00428 } // namespace tvmet
00429 
00430 #endif // TVMET_XPR_MATRIX_BINARY_FUNCTIONS_H
00431 
00432 // Local Variables:
00433 // mode:C++
00434 // tab-width:8
00435 // End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines

Author: