MOAB  4.9.3pre
GlobalFunctions.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2010-2012 Gael Guennebaud <[email protected]>
00005 // Copyright (C) 2010 Benoit Jacob <[email protected]>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_GLOBAL_FUNCTIONS_H
00012 #define EIGEN_GLOBAL_FUNCTIONS_H
00013 
00014 #define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR) \
00015   template<typename Derived> \
00016   inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
00017   (NAME)(const Eigen::ArrayBase<Derived>& x) { \
00018     return Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived>(x.derived()); \
00019   }
00020 
00021 #define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \
00022   \
00023   template<typename Derived> \
00024   struct NAME##_retval<ArrayBase<Derived> > \
00025   { \
00026     typedef const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> type; \
00027   }; \
00028   template<typename Derived> \
00029   struct NAME##_impl<ArrayBase<Derived> > \
00030   { \
00031     static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \
00032     { \
00033       return typename NAME##_retval<ArrayBase<Derived> >::type(x.derived()); \
00034     } \
00035   };
00036 
00037 namespace Eigen
00038 {
00039   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op)
00040   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op)
00041   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op)
00042   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(inverse,scalar_inverse_op)
00043   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op)
00044   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op)
00045   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op)
00046   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan,scalar_atan_op)
00047   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op)
00048   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos,scalar_acos_op)
00049   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op)
00050   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op)
00051   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op)
00052   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op)
00053   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op)
00054   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op)
00055   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op)
00056   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op)
00057   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op)
00058   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10,scalar_log10_op)
00059   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op)
00060   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2,scalar_abs2_op)
00061   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg,scalar_arg_op)
00062   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op)
00063   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square,scalar_square_op)
00064   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube,scalar_cube_op)
00065   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op)
00066   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op)
00067   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op)
00068   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op)
00069   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op)
00070   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op)
00071   EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign,scalar_sign_op)
00072   
00073   template<typename Derived>
00074   inline const Eigen::CwiseUnaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar>, const Derived>
00075   pow(const Eigen::ArrayBase<Derived>& x, const typename Derived::Scalar& exponent) {
00076     return x.derived().pow(exponent);
00077   }
00078 
00088   template<typename Derived,typename ExponentDerived>
00089   inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>
00090   pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<ExponentDerived>& exponents) 
00091   {
00092     return Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>(
00093       x.derived(),
00094       exponents.derived()
00095     );
00096   }
00097   
00108   template<typename Derived>
00109   inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>
00110   pow(const typename Derived::Scalar& x, const Eigen::ArrayBase<Derived>& exponents) 
00111   {
00112     typename Derived::ConstantReturnType constant_x(exponents.rows(), exponents.cols(), x);
00113     return Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>(
00114       constant_x,
00115       exponents.derived()
00116     );
00117   }
00118   
00122   template <typename Derived>
00123   inline const Eigen::CwiseUnaryOp<Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>, const Derived>
00124     operator/(const typename Derived::Scalar& s, const Eigen::ArrayBase<Derived>& a)
00125   {
00126     return Eigen::CwiseUnaryOp<Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>, const Derived>(
00127       a.derived(),
00128       Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>(s)  
00129     );
00130   }
00131 
00132   namespace internal
00133   {
00134     EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op)
00135     EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op)
00136     EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op)
00137   }
00138 }
00139 
00140 // TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...)
00141 
00142 #endif // EIGEN_GLOBAL_FUNCTIONS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines