10 #ifndef EIGEN_MATHFUNCTIONS_H 11 #define EIGEN_MATHFUNCTIONS_H 37 template<
typename T,
typename dummy =
void>
43 template<
typename T>
struct always_void {
typedef void type; };
48 typename
always_void<typename
T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
51 typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type;
54 #define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type> 55 #define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>::type 61 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
65 static inline RealScalar run(
const Scalar& x)
71 template<
typename Scalar>
75 static inline RealScalar run(
const Scalar& x)
84 template<
typename Scalar>
95 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
99 static inline RealScalar run(
const Scalar&)
101 return RealScalar(0);
105 template<
typename Scalar>
109 static inline RealScalar run(
const Scalar& x)
118 template<
typename Scalar>
128 template<
typename Scalar>
132 static inline RealScalar& run(Scalar& x)
134 return reinterpret_cast<RealScalar*
>(&x)[0];
136 static inline const RealScalar& run(
const Scalar& x)
138 return reinterpret_cast<const RealScalar*
>(&x)[0];
142 template<
typename Scalar>
152 template<
typename Scalar,
bool IsComplex>
156 static inline RealScalar& run(Scalar& x)
158 return reinterpret_cast<RealScalar*
>(&x)[1];
160 static inline const RealScalar& run(
const Scalar& x)
162 return reinterpret_cast<RealScalar*
>(&x)[1];
166 template<
typename Scalar>
169 static inline Scalar run(Scalar&)
173 static inline const Scalar run(
const Scalar&)
179 template<
typename Scalar>
182 template<
typename Scalar>
192 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
195 static inline Scalar run(
const Scalar& x)
201 template<
typename Scalar>
204 static inline Scalar run(
const Scalar& x)
211 template<
typename Scalar>
221 template<
typename Scalar>
225 static inline RealScalar run(
const Scalar& x)
231 template<
typename RealScalar>
234 static inline RealScalar run(
const std::complex<RealScalar>& x)
236 return real(x)*real(x) + imag(x)*imag(x);
240 template<
typename Scalar>
250 template<
typename Scalar,
bool IsComplex>
254 static inline RealScalar run(
const Scalar& x)
257 return abs(real(x)) + abs(imag(x));
261 template<
typename Scalar>
264 static inline Scalar run(
const Scalar& x)
271 template<
typename Scalar>
274 template<
typename Scalar>
284 template<
typename Scalar>
288 static inline RealScalar run(
const Scalar& x,
const Scalar& y)
294 RealScalar _x = abs(x);
295 RealScalar _y = abs(y);
296 RealScalar p = (max)(_x, _y);
297 if(p==RealScalar(0))
return RealScalar(0);
298 RealScalar q = (min)(_x, _y);
300 return p * sqrt(RealScalar(1) + qp*qp);
304 template<
typename Scalar>
314 template<
typename OldType,
typename NewType>
317 static inline NewType run(
const OldType& x)
319 return static_cast<NewType
>(x);
325 template<
typename OldType,
typename NewType>
326 inline NewType cast(
const OldType& x)
335 template<
typename Scalar,
bool IsInteger>
338 typedef Scalar retval;
340 static inline Scalar run(
const Scalar& x,
const Scalar& y)
347 return RealScalar(0.5) * log((y + x) / (y - x));
349 return z + z*z*z / RealScalar(3);
353 template<
typename Scalar>
356 static inline Scalar run(
const Scalar&,
const Scalar&)
358 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
363 template<
typename Scalar>
366 template<
typename Scalar>
376 template<
typename Scalar,
bool IsInteger>
379 typedef Scalar retval;
380 static inline Scalar run(
const Scalar& x,
const Scalar& y)
387 template<
typename Scalar>
390 static inline Scalar run(Scalar x, Scalar y)
406 template<
typename Scalar>
409 template<
typename Scalar>
424 template<
typename Scalar>
427 template<
typename Scalar>
433 template<
typename Scalar>
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(
const Scalar& x,
const Scalar& y);
434 template<
typename Scalar>
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random();
436 template<
typename Scalar>
439 static inline Scalar run(
const Scalar& x,
const Scalar& y)
441 return x + (y-x) *
Scalar(std::rand()) /
Scalar(RAND_MAX);
443 static inline Scalar run()
450 floor_log2_terminate,
452 floor_log2_move_down,
458 enum { middle = (lower + upper) / 2,
459 value = (upper <= lower + 1) ? int(floor_log2_terminate)
460 : (n < (1 << middle)) ? int(floor_log2_move_down)
461 : (n==0) ?
int(floor_log2_bogus)
462 : int(floor_log2_move_up)
466 template<
unsigned int n,
468 int upper =
sizeof(
unsigned int) * CHAR_BIT - 1,
472 template<
unsigned int n,
int lower,
int upper>
478 template<
unsigned int n,
int lower,
int upper>
484 template<
unsigned int n,
int lower,
int upper>
487 enum { value = (n >= ((
unsigned int)(1) << (lower+1))) ? lower+1 : lower };
490 template<
unsigned int n,
int lower,
int upper>
496 template<
typename Scalar>
501 static inline Scalar run(
const Scalar& x,
const Scalar& y)
503 return x +
Scalar((NonInteger(y)-x+1) * std::rand() / (RAND_MAX + NonInteger(1)));
506 static inline Scalar run()
508 #ifdef EIGEN_MAKING_DOCS 512 scalar_bits =
sizeof(
Scalar) * CHAR_BIT,
513 shift = EIGEN_PLAIN_ENUM_MAX(0,
int(rand_bits) - int(scalar_bits)),
516 return Scalar((std::rand() >> shift) - offset);
521 template<
typename Scalar>
524 static inline Scalar run(
const Scalar& x,
const Scalar& y)
526 return Scalar(random(real(x), real(y)),
527 random(imag(x), imag(y)));
529 static inline Scalar run()
532 return Scalar(random<RealScalar>(), random<RealScalar>());
536 template<
typename Scalar>
537 inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(
const Scalar& x,
const Scalar& y)
539 return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y);
542 template<
typename Scalar>
543 inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
545 return EIGEN_MATHFUNC_IMPL(random, Scalar)::run();
556 template<
typename Scalar>
557 inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(
const Scalar& x)
559 return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x);
562 template<
typename Scalar>
563 inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(
const Scalar& x)
568 template<
typename Scalar>
569 inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x)
571 return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x);
574 template<
typename Scalar>
575 inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(
const Scalar& x)
577 return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x);
580 template<
typename Scalar>
581 inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(
const Scalar& x)
586 template<
typename Scalar>
587 inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x)
589 return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x);
592 template<
typename Scalar>
593 inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(
const Scalar& x)
595 return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x);
598 template<
typename Scalar>
599 inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(
const Scalar& x)
601 return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x);
604 template<
typename Scalar>
605 inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(
const Scalar& x)
607 return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x);
610 template<
typename Scalar>
611 inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(
const Scalar& x,
const Scalar& y)
613 return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y);
616 template<
typename Scalar>
617 inline EIGEN_MATHFUNC_RETVAL(atanh2, Scalar) atanh2(
const Scalar& x,
const Scalar& y)
619 return EIGEN_MATHFUNC_IMPL(atanh2, Scalar)::run(x, y);
622 template<
typename Scalar>
623 inline EIGEN_MATHFUNC_RETVAL(pow, Scalar) pow(
const Scalar& x,
const Scalar& y)
625 return EIGEN_MATHFUNC_IMPL(pow, Scalar)::run(x, y);
630 template<
typename T> bool (isfinite)(
const T& x)
648 template<
typename Scalar>
652 template<
typename OtherScalar>
653 static inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
const RealScalar& prec)
656 return abs(x) <= abs(y) * prec;
658 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
662 return abs(x - y) <= (min)(abs(x), abs(y)) * prec;
664 static inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
666 return x <= y || isApprox(x, y, prec);
670 template<
typename Scalar>
674 template<
typename OtherScalar>
675 static inline bool isMuchSmallerThan(
const Scalar& x,
const Scalar&,
const RealScalar&)
679 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar&)
683 static inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
const RealScalar&)
689 template<
typename Scalar>
693 template<
typename OtherScalar>
694 static inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
const RealScalar& prec)
696 return numext::abs2(x) <= numext::abs2(y) * prec * prec;
698 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
701 return numext::abs2(x - y) <= (min)(numext::abs2(x), numext::abs2(y)) * prec * prec;
705 template<
typename Scalar>
708 template<
typename Scalar,
typename OtherScalar>
709 inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
715 template<
typename Scalar>
716 inline bool isApprox(
const Scalar& x,
const Scalar& y,
722 template<
typename Scalar>
723 inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
735 static inline bool run()
737 return random<int>(0,1)==0 ?
false :
true;
743 typedef bool RealScalar;
745 template<
typename OtherScalar>
746 static inline bool isMuchSmallerThan(
const bool& x,
const bool&,
const bool&)
751 static inline bool isApprox(
bool x,
bool y,
bool)
756 static inline bool isApproxOrLessThan(
const bool& x,
const bool& y,
const bool&)
768 #endif // EIGEN_MATHFUNCTIONS_H Definition: MathFunctions.h:129
Definition: MathFunctions.h:407
Definition: MathFunctions.h:153
Definition: MathFunctions.h:473
Definition: MathFunctions.h:193
Definition: MathFunctions.h:82
Definition: MathFunctions.h:456
Definition: MathFunctions.h:470
Definition: MathFunctions.h:96
Definition: MathFunctions.h:377
Definition: MathFunctions.h:180
Definition: MathFunctions.h:706
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Definition: TypeSafeIdHash.h:44
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Definition: MathFunctions.h:85
Definition: MathFunctions.h:43
Definition: MathFunctions.h:116
Definition: MathFunctions.h:315
Definition: MathFunctions.h:38
Definition: MathFunctions.h:428
Definition: MathFunctions.h:364
Definition: MathFunctions.h:410
Definition: MathFunctions.h:305
Definition: MathFunctions.h:275
Definition: MathFunctions.h:425
Definition: MathFunctions.h:646
Definition: MathFunctions.h:422
Definition: MathFunctions.h:143
Definition: MathFunctions.h:119
Definition: BandTriangularSolver.h:13
Definition: MathFunctions.h:241
Definition: MathFunctions.h:336
Definition: MathFunctions.h:285
Definition: MathFunctions.h:62
Definition: MathFunctions.h:183
Definition: MathFunctions.h:222
Definition: MathFunctions.h:212
Definition: MathFunctions.h:272
Definition: MathFunctions.h:251
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
Definition: MathFunctions.h:367