aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2012-06-18 21:49:55 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2012-06-18 21:49:55 +0200
commit47a77d3e38459b3bd35332a4875e2f40d62f4a23 (patch)
treeab4682eec721abcb1a09736cf303b1484037d4bc /doc
parent791e28f25d75941a6e0fc317464cbb52cb312944 (diff)
update custom scalar type doc
Diffstat (limited to 'doc')
-rw-r--r--doc/I00_CustomizingEigen.dox37
1 files changed, 16 insertions, 21 deletions
diff --git a/doc/I00_CustomizingEigen.dox b/doc/I00_CustomizingEigen.dox
index d0a5dd5a5..623ef31e1 100644
--- a/doc/I00_CustomizingEigen.dox
+++ b/doc/I00_CustomizingEigen.dox
@@ -120,14 +120,17 @@ Eigen::MatrixBase<Eigen::Matrix<std::complex<float>, 10000, 1, 2, 10000, 1>
\anchor user_defined_scalars \section CustomScalarType Using custom scalar types
-By default, Eigen currently supports the following scalar types: \c int, \c float, \c double, \c std::complex<float>, \c std::complex<double>, \c long \c double, \c long \c long \c int (64 bits integers), and \c bool. The \c long \c double is especially useful on x86-64 systems or when the SSE2 instruction set is enabled because it enforces the use of x87 registers with extended accuracy.
+By default, Eigen currently supports standard floating-point types (\c float, \c double, \c std::complex<float>, \c std::complex<double>, \c long \c double), as well as all integrale types (e.g., \c int, \c unsigned \c int, \c short, etc.), and \c bool.
+On x86-64 systems, \c long \c double permits to locally enforces the use of x87 registers with extended accuracy (in comparison to SSE).
In order to add support for a custom type \c T you need:
-# make sure the common operator (+,-,*,/,etc.) are supported by the type \c T
-# add a specialization of struct Eigen::NumTraits<T> (see \ref NumTraits)
--# define a couple of math functions for your type such as: internal::sqrt, internal::abs, etc...
+-# define the math functions that makes sense for your type. This includes standard ones like sqrt, pow, sin, tan, conj, real, imag, etc, as well as abs2 which is Eigen specific.
(see the file Eigen/src/Core/MathFunctions.h)
+The math function should be defined in the same namespace than \c T, or in the \c std namespace though that second appraoch is not recommended.
+
Here is a concrete example adding support for the Adolc's \c adouble type. <a href="https://projects.coin-or.org/ADOL-C">Adolc</a> is an automatic differentiation library. The type \c adouble is basically a real value tracking the values of any number of partial derivatives.
\code
@@ -141,6 +144,7 @@ Here is a concrete example adding support for the Adolc's \c adouble type. <a hr
namespace Eigen {
template<> struct NumTraits<adtl::adouble>
+ : NumTraits<double> // permits to get the epsilon, dummy_precision, lowest, highest functions
{
typedef adtl::adouble Real;
typedef adtl::adouble NonInteger;
@@ -152,30 +156,21 @@ template<> struct NumTraits<adtl::adouble>
IsSigned = 1,
RequireInitialization = 1,
ReadCost = 1,
- AddCost = 1,
- MulCost = 1
+ AddCost = 3,
+ MulCost = 3
};
};
}
-namespace Eigen {
- namespace internal {
-
- inline const adtl::adouble& conj(const adtl::adouble& x) { return x; }
- inline const adtl::adouble& real(const adtl::adouble& x) { return x; }
- inline adtl::adouble imag(const adtl::adouble&) { return 0.; }
- inline adtl::adouble abs(const adtl::adouble& x) { return adtl::fabs(x); }
- inline adtl::adouble abs2(const adtl::adouble& x) { return x*x; }
-
- using adtl::sqrt;
- using adtl::exp;
- using adtl::log;
- using adtl::sin;
- using adtl::cos;
- using adtl::pow;
-
- }
+namespace adtl {
+
+inline const adouble& conj(const adouble& x) { return x; }
+inline const adouble& real(const adouble& x) { return x; }
+inline adouble imag(const adouble&) { return 0.; }
+inline adouble abs(const adouble& x) { return fabs(x); }
+inline adouble abs2(const adouble& x) { return x*x; }
+
}
#endif // ADOLCSUPPORT_H