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

include/tvmet/MatrixUnaryFunctions.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: MatrixUnaryFunctions.h,v 1.13 2007-06-23 15:58:58 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_MATRIX_UNARY_FUNCTIONS_H
00025 #define TVMET_MATRIX_UNARY_FUNCTIONS_H
00026 
00027 namespace tvmet {
00028 
00029 
00030 /*********************************************************
00031  * PART I: DECLARATION
00032  *********************************************************/
00033 
00034 /*
00035  * unary_function(Matrix<T, Rows, Cols>)
00036  */
00037 #define TVMET_DECLARE_MACRO(NAME)       \
00038 template<class T, std::size_t Rows, std::size_t Cols>   \
00039 inline                \
00040 XprMatrix<              \
00041   XprUnOp<              \
00042     Fcnl_##NAME<T>,           \
00043     MatrixConstReference<T, Rows, Cols>       \
00044   >,                \
00045   Rows, Cols              \
00046 >               \
00047 NAME(const Matrix<T, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
00048 
00049 TVMET_DECLARE_MACRO(abs)
00050 TVMET_DECLARE_MACRO(cbrt)
00051 TVMET_DECLARE_MACRO(ceil)
00052 TVMET_DECLARE_MACRO(floor)
00053 TVMET_DECLARE_MACRO(rint)
00054 TVMET_DECLARE_MACRO(sin)
00055 TVMET_DECLARE_MACRO(cos)
00056 TVMET_DECLARE_MACRO(tan)
00057 TVMET_DECLARE_MACRO(sinh)
00058 TVMET_DECLARE_MACRO(cosh)
00059 TVMET_DECLARE_MACRO(tanh)
00060 TVMET_DECLARE_MACRO(asin)
00061 TVMET_DECLARE_MACRO(acos)
00062 TVMET_DECLARE_MACRO(atan)
00063 TVMET_DECLARE_MACRO(exp)
00064 TVMET_DECLARE_MACRO(log)
00065 TVMET_DECLARE_MACRO(log10)
00066 TVMET_DECLARE_MACRO(sqrt)
00067 
00068 #if defined(TVMET_HAVE_IEEE_MATH)
00069 TVMET_DECLARE_MACRO(asinh)
00070 TVMET_DECLARE_MACRO(acosh)
00071 TVMET_DECLARE_MACRO(atanh)
00072 TVMET_DECLARE_MACRO(expm1)
00073 TVMET_DECLARE_MACRO(log1p)
00074 TVMET_DECLARE_MACRO(erf)
00075 TVMET_DECLARE_MACRO(erfc)
00076 TVMET_DECLARE_MACRO(j0)
00077 TVMET_DECLARE_MACRO(j1)
00078 TVMET_DECLARE_MACRO(y0)
00079 TVMET_DECLARE_MACRO(y1)
00080 TVMET_DECLARE_MACRO(lgamma)
00082 #if !defined(TVMET_NO_IEEE_MATH_ISNAN)
00083 TVMET_DECLARE_MACRO(isnan)
00084 #endif
00085 #if !defined(TVMET_NO_IEEE_MATH_ISINF)
00086 TVMET_DECLARE_MACRO(isinf)
00087 #endif
00088 TVMET_DECLARE_MACRO(finite)
00089 #endif // defined(TVMET_HAVE_IEEE_MATH)
00090 
00091 #undef TVMET_DECLARE_MACRO
00092 
00093 
00094 /*
00095  * unary_function(Matrix<std::complex<T>, Rows, Cols>)
00096  */
00097 #if defined(TVMET_HAVE_COMPLEX)
00098 #define TVMET_DECLARE_MACRO(NAME)           \
00099 template<class T, std::size_t Rows, std::size_t Cols>       \
00100 inline                    \
00101 XprMatrix<                  \
00102   XprUnOp<                  \
00103     Fcnl_##NAME< std::complex<T> >,           \
00104     MatrixConstReference<std::complex<T>, Rows, Cols>       \
00105   >,                    \
00106   Rows, Cols                  \
00107 >                   \
00108 NAME(const Matrix<std::complex<T>, Rows, Cols>& rhs) TVMET_CXX_ALWAYS_INLINE;
00109 
00110 TVMET_DECLARE_MACRO(real)
00111 TVMET_DECLARE_MACRO(imag)
00112 TVMET_DECLARE_MACRO(arg)
00113 TVMET_DECLARE_MACRO(norm)
00114 TVMET_DECLARE_MACRO(conj)
00115 
00116 #undef TVMET_DECLARE_MACRO
00117 
00118 #endif // defined(TVMET_HAVE_COMPLEX)
00119 
00120 
00121 /*********************************************************
00122  * PART II: IMPLEMENTATION
00123  *********************************************************/
00124 
00125 
00126 /*
00127  * unary_function(Matrix<T, Rows, Cols>)
00128  */
00129 #define TVMET_IMPLEMENT_MACRO(NAME)         \
00130 template<class T, std::size_t Rows, std::size_t Cols>     \
00131 inline                  \
00132 XprMatrix<                \
00133   XprUnOp<                \
00134     Fcnl_##NAME<T>,             \
00135     MatrixConstReference<T, Rows, Cols>         \
00136   >,                  \
00137   Rows, Cols                \
00138 >                 \
00139 NAME(const Matrix<T, Rows, Cols>& rhs) {        \
00140   typedef XprUnOp<              \
00141     Fcnl_##NAME<T>,             \
00142     MatrixConstReference<T, Rows, Cols>         \
00143   >               expr_type;  \
00144   return XprMatrix<expr_type, Rows, Cols>(expr_type(rhs.const_ref()));  \
00145 }
00146 
00147 TVMET_IMPLEMENT_MACRO(abs)
00148 TVMET_IMPLEMENT_MACRO(cbrt)
00149 TVMET_IMPLEMENT_MACRO(ceil)
00150 TVMET_IMPLEMENT_MACRO(floor)
00151 TVMET_IMPLEMENT_MACRO(rint)
00152 TVMET_IMPLEMENT_MACRO(sin)
00153 TVMET_IMPLEMENT_MACRO(cos)
00154 TVMET_IMPLEMENT_MACRO(tan)
00155 TVMET_IMPLEMENT_MACRO(sinh)
00156 TVMET_IMPLEMENT_MACRO(cosh)
00157 TVMET_IMPLEMENT_MACRO(tanh)
00158 TVMET_IMPLEMENT_MACRO(asin)
00159 TVMET_IMPLEMENT_MACRO(acos)
00160 TVMET_IMPLEMENT_MACRO(atan)
00161 TVMET_IMPLEMENT_MACRO(exp)
00162 TVMET_IMPLEMENT_MACRO(log)
00163 TVMET_IMPLEMENT_MACRO(log10)
00164 TVMET_IMPLEMENT_MACRO(sqrt)
00165 
00166 #if defined(TVMET_HAVE_IEEE_MATH)
00167 TVMET_IMPLEMENT_MACRO(asinh)
00168 TVMET_IMPLEMENT_MACRO(acosh)
00169 TVMET_IMPLEMENT_MACRO(atanh)
00170 TVMET_IMPLEMENT_MACRO(expm1)
00171 TVMET_IMPLEMENT_MACRO(log1p)
00172 TVMET_IMPLEMENT_MACRO(erf)
00173 TVMET_IMPLEMENT_MACRO(erfc)
00174 TVMET_IMPLEMENT_MACRO(j0)
00175 TVMET_IMPLEMENT_MACRO(j1)
00176 TVMET_IMPLEMENT_MACRO(y0)
00177 TVMET_IMPLEMENT_MACRO(y1)
00178 TVMET_IMPLEMENT_MACRO(lgamma)
00180 #if !defined(TVMET_NO_IEEE_MATH_ISNAN)
00181 TVMET_IMPLEMENT_MACRO(isnan)
00182 #endif
00183 #if !defined(TVMET_NO_IEEE_MATH_ISINF)
00184 TVMET_IMPLEMENT_MACRO(isinf)
00185 #endif
00186 TVMET_IMPLEMENT_MACRO(finite)
00187 #endif // defined(TVMET_HAVE_IEEE_MATH)
00188 
00189 #undef TVMET_IMPLEMENT_MACRO
00190 
00191 
00192 /*
00193  * unary_function(Matrix<std::complex<T>, Rows, Cols>)
00194  */
00195 #if defined(TVMET_HAVE_COMPLEX)
00196 #define TVMET_IMPLEMENT_MACRO(NAME)         \
00197 template<class T, std::size_t Rows, std::size_t Cols>     \
00198 inline                  \
00199 XprMatrix<                \
00200   XprUnOp<                \
00201     Fcnl_##NAME< std::complex<T> >,         \
00202     MatrixConstReference<std::complex<T>, Rows, Cols>     \
00203   >,                  \
00204   Rows, Cols                \
00205 >                 \
00206 NAME(const Matrix<std::complex<T>, Rows, Cols>& rhs) {      \
00207   typedef XprUnOp<              \
00208     Fcnl_##NAME< std::complex<T> >,         \
00209     MatrixConstReference<std::complex<T>, Rows, Cols>     \
00210   >               expr_type;  \
00211   return XprMatrix<expr_type, Rows, Cols>(expr_type(rhs.const_ref()));  \
00212 }
00213 
00214 TVMET_IMPLEMENT_MACRO(real)
00215 TVMET_IMPLEMENT_MACRO(imag)
00216 TVMET_IMPLEMENT_MACRO(arg)
00217 TVMET_IMPLEMENT_MACRO(norm)
00218 TVMET_IMPLEMENT_MACRO(conj)
00219 
00220 #undef TVMET_IMPLEMENT_MACRO
00221 
00222 #endif // defined(TVMET_HAVE_COMPLEX)
00223 
00224 
00225 } // namespace tvmet
00226 
00227 #endif // TVMET_MATRIX_UNARY_FUNCTIONS_H
00228 
00229 // Local Variables:
00230 // mode:C++
00231 // tab-width:8
00232 // End:

Author: