mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #86 : use internal:: namespace instead of ei_ prefix
This commit is contained in:
@@ -25,20 +25,22 @@
|
||||
#ifndef EIGEN_MATHFUNCTIONS_H
|
||||
#define EIGEN_MATHFUNCTIONS_H
|
||||
|
||||
/** \internal \struct ei_global_math_functions_filtering_base
|
||||
namespace internal {
|
||||
|
||||
/** \internal \struct global_math_functions_filtering_base
|
||||
*
|
||||
* What it does:
|
||||
* Defines a typedef 'type' as follows:
|
||||
* - if type T has a member typedef Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl, then
|
||||
* ei_global_math_functions_filtering_base<T>::type is a typedef for it.
|
||||
* - otherwise, ei_global_math_functions_filtering_base<T>::type is a typedef for T.
|
||||
* global_math_functions_filtering_base<T>::type is a typedef for it.
|
||||
* - otherwise, global_math_functions_filtering_base<T>::type is a typedef for T.
|
||||
*
|
||||
* How it's used:
|
||||
* To allow to defined the global math functions (like ei_sin...) in certain cases, like the Array expressions.
|
||||
* When you do ei_sin(array1+array2), the object array1+array2 has a complicated expression type, all what you want to know
|
||||
* is that it inherits ArrayBase. So we implement a partial specialization of ei_sin_impl for ArrayBase<Derived>.
|
||||
* So we must make sure to use ei_sin_impl<ArrayBase<Derived> > and not ei_sin_impl<Derived>, otherwise our partial specialization
|
||||
* won't be used. How does ei_sin know that? That's exactly what ei_global_math_functions_filtering_base tells it.
|
||||
* To allow to defined the global math functions (like sin...) in certain cases, like the Array expressions.
|
||||
* When you do sin(array1+array2), the object array1+array2 has a complicated expression type, all what you want to know
|
||||
* is that it inherits ArrayBase. So we implement a partial specialization of sin_impl for ArrayBase<Derived>.
|
||||
* So we must make sure to use sin_impl<ArrayBase<Derived> > and not sin_impl<Derived>, otherwise our partial specialization
|
||||
* won't be used. How does sin know that? That's exactly what global_math_functions_filtering_base tells it.
|
||||
*
|
||||
* How it's implemented:
|
||||
* SFINAE in the style of enable_if. Highly susceptible of breaking compilers. With GCC, it sure does work, but if you replace
|
||||
@@ -46,32 +48,32 @@
|
||||
*/
|
||||
|
||||
template<typename T, typename dummy = void>
|
||||
struct ei_global_math_functions_filtering_base
|
||||
struct global_math_functions_filtering_base
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<typename T> struct ei_always_void { typedef void type; };
|
||||
template<typename T> struct always_void { typedef void type; };
|
||||
|
||||
template<typename T>
|
||||
struct ei_global_math_functions_filtering_base
|
||||
struct global_math_functions_filtering_base
|
||||
<T,
|
||||
typename ei_always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
|
||||
typename always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
|
||||
>
|
||||
{
|
||||
typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type;
|
||||
};
|
||||
|
||||
#define EIGEN_MATHFUNC_IMPL(func, scalar) ei_##func##_impl<typename ei_global_math_functions_filtering_base<scalar>::type>
|
||||
#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename ei_##func##_retval<typename ei_global_math_functions_filtering_base<scalar>::type>::type
|
||||
#define EIGEN_MATHFUNC_IMPL(func, scalar) func##_impl<typename global_math_functions_filtering_base<scalar>::type>
|
||||
#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename func##_retval<typename global_math_functions_filtering_base<scalar>::type>::type
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_real *
|
||||
* Implementation of real *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_real_impl
|
||||
struct real_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar run(const Scalar& x)
|
||||
@@ -81,7 +83,7 @@ struct ei_real_impl
|
||||
};
|
||||
|
||||
template<typename RealScalar>
|
||||
struct ei_real_impl<std::complex<RealScalar> >
|
||||
struct real_impl<std::complex<RealScalar> >
|
||||
{
|
||||
static inline RealScalar run(const std::complex<RealScalar>& x)
|
||||
{
|
||||
@@ -90,23 +92,23 @@ struct ei_real_impl<std::complex<RealScalar> >
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_real_retval
|
||||
struct real_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(real, Scalar) ei_real(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_imag *
|
||||
* Implementation of imag *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_imag_impl
|
||||
struct imag_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar run(const Scalar&)
|
||||
@@ -116,7 +118,7 @@ struct ei_imag_impl
|
||||
};
|
||||
|
||||
template<typename RealScalar>
|
||||
struct ei_imag_impl<std::complex<RealScalar> >
|
||||
struct imag_impl<std::complex<RealScalar> >
|
||||
{
|
||||
static inline RealScalar run(const std::complex<RealScalar>& x)
|
||||
{
|
||||
@@ -125,23 +127,23 @@ struct ei_imag_impl<std::complex<RealScalar> >
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_imag_retval
|
||||
struct imag_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) ei_imag(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_real_ref *
|
||||
* Implementation of real_ref *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_real_ref_impl
|
||||
struct real_ref_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar& run(Scalar& x)
|
||||
@@ -155,29 +157,29 @@ struct ei_real_ref_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_real_ref_retval
|
||||
struct real_ref_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real & type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline typename ei_makeconst< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type ei_real_ref(const Scalar& x)
|
||||
inline typename makeconst< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar& x)
|
||||
{
|
||||
return ei_real_ref_impl<Scalar>::run(x);
|
||||
return real_ref_impl<Scalar>::run(x);
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) ei_real_ref(Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_imag_ref *
|
||||
* Implementation of imag_ref *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsComplex>
|
||||
struct ei_imag_ref_default_impl
|
||||
struct imag_ref_default_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar& run(Scalar& x)
|
||||
@@ -191,7 +193,7 @@ struct ei_imag_ref_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_imag_ref_default_impl<Scalar, false>
|
||||
struct imag_ref_default_impl<Scalar, false>
|
||||
{
|
||||
static inline Scalar run(Scalar&)
|
||||
{
|
||||
@@ -204,32 +206,32 @@ struct ei_imag_ref_default_impl<Scalar, false>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_imag_ref_impl : ei_imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
|
||||
struct imag_ref_impl : imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_imag_ref_retval
|
||||
struct imag_ref_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real & type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline typename ei_makeconst< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type ei_imag_ref(const Scalar& x)
|
||||
inline typename makeconst< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar& x)
|
||||
{
|
||||
return ei_imag_ref_impl<Scalar>::run(x);
|
||||
return imag_ref_impl<Scalar>::run(x);
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) ei_imag_ref(Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_conj *
|
||||
* Implementation of conj *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_conj_impl
|
||||
struct conj_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
@@ -238,7 +240,7 @@ struct ei_conj_impl
|
||||
};
|
||||
|
||||
template<typename RealScalar>
|
||||
struct ei_conj_impl<std::complex<RealScalar> >
|
||||
struct conj_impl<std::complex<RealScalar> >
|
||||
{
|
||||
static inline std::complex<RealScalar> run(const std::complex<RealScalar>& x)
|
||||
{
|
||||
@@ -247,23 +249,23 @@ struct ei_conj_impl<std::complex<RealScalar> >
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_conj_retval
|
||||
struct conj_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) ei_conj(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_abs *
|
||||
* Implementation of abs *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_abs_impl
|
||||
struct abs_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar run(const Scalar& x)
|
||||
@@ -273,23 +275,23 @@ struct ei_abs_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_abs_retval
|
||||
struct abs_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(abs, Scalar) ei_abs(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(abs, Scalar) abs(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(abs, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_abs2 *
|
||||
* Implementation of abs2 *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_abs2_impl
|
||||
struct abs2_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar run(const Scalar& x)
|
||||
@@ -299,7 +301,7 @@ struct ei_abs2_impl
|
||||
};
|
||||
|
||||
template<typename RealScalar>
|
||||
struct ei_abs2_impl<std::complex<RealScalar> >
|
||||
struct abs2_impl<std::complex<RealScalar> >
|
||||
{
|
||||
static inline RealScalar run(const std::complex<RealScalar>& x)
|
||||
{
|
||||
@@ -308,92 +310,92 @@ struct ei_abs2_impl<std::complex<RealScalar> >
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_abs2_retval
|
||||
struct abs2_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) ei_abs2(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_norm1 *
|
||||
* Implementation of norm1 *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsComplex>
|
||||
struct ei_norm1_default_impl
|
||||
struct norm1_default_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar run(const Scalar& x)
|
||||
{
|
||||
return ei_abs(ei_real(x)) + ei_abs(ei_imag(x));
|
||||
return abs(real(x)) + abs(imag(x));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_norm1_default_impl<Scalar, false>
|
||||
struct norm1_default_impl<Scalar, false>
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
return ei_abs(x);
|
||||
return abs(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_norm1_impl : ei_norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
|
||||
struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_norm1_retval
|
||||
struct norm1_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) ei_norm1(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_hypot *
|
||||
* Implementation of hypot *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_hypot_impl
|
||||
struct hypot_impl
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
static inline RealScalar run(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
RealScalar _x = ei_abs(x);
|
||||
RealScalar _y = ei_abs(y);
|
||||
RealScalar _x = abs(x);
|
||||
RealScalar _y = abs(y);
|
||||
RealScalar p = std::max(_x, _y);
|
||||
RealScalar q = std::min(_x, _y);
|
||||
RealScalar qp = q/p;
|
||||
return p * ei_sqrt(RealScalar(1) + qp*qp);
|
||||
return p * sqrt(RealScalar(1) + qp*qp);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_hypot_retval
|
||||
struct hypot_retval
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) ei_hypot(const Scalar& x, const Scalar& y)
|
||||
inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_cast *
|
||||
* Implementation of cast *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename OldType, typename NewType>
|
||||
struct ei_cast_impl
|
||||
struct cast_impl
|
||||
{
|
||||
static inline NewType run(const OldType& x)
|
||||
{
|
||||
@@ -401,20 +403,20 @@ struct ei_cast_impl
|
||||
}
|
||||
};
|
||||
|
||||
// here, for once, we're plainly returning NewType: we don't want ei_cast to do weird things.
|
||||
// here, for once, we're plainly returning NewType: we don't want cast to do weird things.
|
||||
|
||||
template<typename OldType, typename NewType>
|
||||
inline NewType ei_cast(const OldType& x)
|
||||
inline NewType cast(const OldType& x)
|
||||
{
|
||||
return ei_cast_impl<OldType, NewType>::run(x);
|
||||
return cast_impl<OldType, NewType>::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_sqrt *
|
||||
* Implementation of sqrt *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_sqrt_default_impl
|
||||
struct sqrt_default_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
@@ -423,7 +425,7 @@ struct ei_sqrt_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_sqrt_default_impl<Scalar, true>
|
||||
struct sqrt_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar&)
|
||||
{
|
||||
@@ -433,26 +435,26 @@ struct ei_sqrt_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_sqrt_impl : ei_sqrt_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct sqrt_impl : sqrt_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_sqrt_retval
|
||||
struct sqrt_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) ei_sqrt(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(sqrt, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_exp *
|
||||
* Implementation of exp *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_exp_default_impl
|
||||
struct exp_default_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
@@ -461,7 +463,7 @@ struct ei_exp_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_exp_default_impl<Scalar, true>
|
||||
struct exp_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar&)
|
||||
{
|
||||
@@ -471,26 +473,26 @@ struct ei_exp_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_exp_impl : ei_exp_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct exp_impl : exp_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_exp_retval
|
||||
struct exp_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(exp, Scalar) ei_exp(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(exp, Scalar) exp(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(exp, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_cos *
|
||||
* Implementation of cos *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_cos_default_impl
|
||||
struct cos_default_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
@@ -499,7 +501,7 @@ struct ei_cos_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_cos_default_impl<Scalar, true>
|
||||
struct cos_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar&)
|
||||
{
|
||||
@@ -509,26 +511,26 @@ struct ei_cos_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_cos_impl : ei_cos_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct cos_impl : cos_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_cos_retval
|
||||
struct cos_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(cos, Scalar) ei_cos(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(cos, Scalar) cos(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(cos, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_sin *
|
||||
* Implementation of sin *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_sin_default_impl
|
||||
struct sin_default_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
@@ -537,7 +539,7 @@ struct ei_sin_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_sin_default_impl<Scalar, true>
|
||||
struct sin_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar&)
|
||||
{
|
||||
@@ -547,26 +549,26 @@ struct ei_sin_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_sin_impl : ei_sin_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct sin_impl : sin_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_sin_retval
|
||||
struct sin_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(sin, Scalar) ei_sin(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(sin, Scalar) sin(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(sin, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_log *
|
||||
* Implementation of log *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_log_default_impl
|
||||
struct log_default_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
@@ -575,7 +577,7 @@ struct ei_log_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_log_default_impl<Scalar, true>
|
||||
struct log_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar&)
|
||||
{
|
||||
@@ -585,26 +587,26 @@ struct ei_log_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_log_impl : ei_log_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct log_impl : log_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_log_retval
|
||||
struct log_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(log, Scalar) ei_log(const Scalar& x)
|
||||
inline EIGEN_MATHFUNC_RETVAL(log, Scalar) log(const Scalar& x)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(log, Scalar)::run(x);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_atan2 *
|
||||
* Implementation of atan2 *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_atan2_default_impl
|
||||
struct atan2_default_impl
|
||||
{
|
||||
typedef Scalar retval;
|
||||
static inline Scalar run(const Scalar& x, const Scalar& y)
|
||||
@@ -614,7 +616,7 @@ struct ei_atan2_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_atan2_default_impl<Scalar, true>
|
||||
struct atan2_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar&, const Scalar&)
|
||||
{
|
||||
@@ -624,26 +626,26 @@ struct ei_atan2_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_atan2_impl : ei_atan2_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct atan2_impl : atan2_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_atan2_retval
|
||||
struct atan2_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(atan2, Scalar) ei_atan2(const Scalar& x, const Scalar& y)
|
||||
inline EIGEN_MATHFUNC_RETVAL(atan2, Scalar) atan2(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(atan2, Scalar)::run(x, y);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_pow *
|
||||
* Implementation of pow *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar, bool IsInteger>
|
||||
struct ei_pow_default_impl
|
||||
struct pow_default_impl
|
||||
{
|
||||
typedef Scalar retval;
|
||||
static inline Scalar run(const Scalar& x, const Scalar& y)
|
||||
@@ -653,12 +655,12 @@ struct ei_pow_default_impl
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_pow_default_impl<Scalar, true>
|
||||
struct pow_default_impl<Scalar, true>
|
||||
{
|
||||
static inline Scalar run(Scalar x, Scalar y)
|
||||
{
|
||||
Scalar res = 1;
|
||||
ei_assert(!NumTraits<Scalar>::IsSigned || y >= 0);
|
||||
eigen_assert(!NumTraits<Scalar>::IsSigned || y >= 0);
|
||||
if(y & 1) res *= x;
|
||||
y >>= 1;
|
||||
while(y)
|
||||
@@ -672,43 +674,43 @@ struct ei_pow_default_impl<Scalar, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_pow_impl : ei_pow_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
struct pow_impl : pow_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_pow_retval
|
||||
struct pow_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(pow, Scalar) ei_pow(const Scalar& x, const Scalar& y)
|
||||
inline EIGEN_MATHFUNC_RETVAL(pow, Scalar) pow(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(pow, Scalar)::run(x, y);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of ei_random *
|
||||
* Implementation of random *
|
||||
****************************************************************************/
|
||||
|
||||
template<typename Scalar,
|
||||
bool IsComplex,
|
||||
bool IsInteger>
|
||||
struct ei_random_default_impl {};
|
||||
struct random_default_impl {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_random_impl : ei_random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
|
||||
struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_random_retval
|
||||
struct random_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) ei_random(const Scalar& x, const Scalar& y);
|
||||
template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) ei_random();
|
||||
template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y);
|
||||
template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random();
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_random_default_impl<Scalar, false, false>
|
||||
struct random_default_impl<Scalar, false, false>
|
||||
{
|
||||
static inline Scalar run(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
@@ -721,7 +723,7 @@ struct ei_random_default_impl<Scalar, false, false>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_random_default_impl<Scalar, false, true>
|
||||
struct random_default_impl<Scalar, false, true>
|
||||
{
|
||||
static inline Scalar run(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
@@ -734,28 +736,28 @@ struct ei_random_default_impl<Scalar, false, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_random_default_impl<Scalar, true, false>
|
||||
struct random_default_impl<Scalar, true, false>
|
||||
{
|
||||
static inline Scalar run(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
return Scalar(ei_random(ei_real(x), ei_real(y)),
|
||||
ei_random(ei_imag(x), ei_imag(y)));
|
||||
return Scalar(random(real(x), real(y)),
|
||||
random(imag(x), imag(y)));
|
||||
}
|
||||
static inline Scalar run()
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
return Scalar(ei_random<RealScalar>(), ei_random<RealScalar>());
|
||||
return Scalar(random<RealScalar>(), random<RealScalar>());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) ei_random(const Scalar& x, const Scalar& y)
|
||||
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y)
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y);
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) ei_random()
|
||||
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
|
||||
{
|
||||
return EIGEN_MATHFUNC_IMPL(random, Scalar)::run();
|
||||
}
|
||||
@@ -767,20 +769,20 @@ inline EIGEN_MATHFUNC_RETVAL(random, Scalar) ei_random()
|
||||
template<typename Scalar,
|
||||
bool IsComplex,
|
||||
bool IsInteger>
|
||||
struct ei_scalar_fuzzy_default_impl {};
|
||||
struct scalar_fuzzy_default_impl {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_scalar_fuzzy_default_impl<Scalar, false, false>
|
||||
struct scalar_fuzzy_default_impl<Scalar, false, false>
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
template<typename OtherScalar>
|
||||
static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
|
||||
{
|
||||
return ei_abs(x) <= ei_abs(y) * prec;
|
||||
return abs(x) <= abs(y) * prec;
|
||||
}
|
||||
static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
|
||||
{
|
||||
return ei_abs(x - y) <= std::min(ei_abs(x), ei_abs(y)) * prec;
|
||||
return abs(x - y) <= std::min(abs(x), abs(y)) * prec;
|
||||
}
|
||||
static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar& prec)
|
||||
{
|
||||
@@ -789,7 +791,7 @@ struct ei_scalar_fuzzy_default_impl<Scalar, false, false>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_scalar_fuzzy_default_impl<Scalar, false, true>
|
||||
struct scalar_fuzzy_default_impl<Scalar, false, true>
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
template<typename OtherScalar>
|
||||
@@ -808,57 +810,57 @@ struct ei_scalar_fuzzy_default_impl<Scalar, false, true>
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_scalar_fuzzy_default_impl<Scalar, true, false>
|
||||
struct scalar_fuzzy_default_impl<Scalar, true, false>
|
||||
{
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
template<typename OtherScalar>
|
||||
static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
|
||||
{
|
||||
return ei_abs2(x) <= ei_abs2(y) * prec * prec;
|
||||
return abs2(x) <= abs2(y) * prec * prec;
|
||||
}
|
||||
static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
|
||||
{
|
||||
return ei_abs2(x - y) <= std::min(ei_abs2(x), ei_abs2(y)) * prec * prec;
|
||||
return abs2(x - y) <= std::min(abs2(x), abs2(y)) * prec * prec;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_scalar_fuzzy_impl : ei_scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
|
||||
struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
|
||||
|
||||
template<typename Scalar, typename OtherScalar>
|
||||
inline bool ei_isMuchSmallerThan(const Scalar& x, const OtherScalar& y,
|
||||
inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y,
|
||||
typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision())
|
||||
{
|
||||
return ei_scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision);
|
||||
return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision);
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
inline bool ei_isApprox(const Scalar& x, const Scalar& y,
|
||||
inline bool isApprox(const Scalar& x, const Scalar& y,
|
||||
typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision())
|
||||
{
|
||||
return ei_scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision);
|
||||
return scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision);
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
inline bool ei_isApproxOrLessThan(const Scalar& x, const Scalar& y,
|
||||
inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y,
|
||||
typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision())
|
||||
{
|
||||
return ei_scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision);
|
||||
return scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision);
|
||||
}
|
||||
|
||||
/******************************************
|
||||
*** The special case of the bool type ***
|
||||
******************************************/
|
||||
|
||||
template<> struct ei_random_impl<bool>
|
||||
template<> struct random_impl<bool>
|
||||
{
|
||||
static inline bool run()
|
||||
{
|
||||
return ei_random<int>(0,1)==0 ? false : true;
|
||||
return random<int>(0,1)==0 ? false : true;
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct ei_scalar_fuzzy_impl<bool>
|
||||
template<> struct scalar_fuzzy_impl<bool>
|
||||
{
|
||||
static inline bool isApprox(bool x, bool y, bool)
|
||||
{
|
||||
@@ -866,4 +868,6 @@ template<> struct ei_scalar_fuzzy_impl<bool>
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
#endif // EIGEN_MATHFUNCTIONS_H
|
||||
|
||||
Reference in New Issue
Block a user