[eigen] Rework of numtraits / math functions (note: all integer types are now supported!) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Rework of numtraits / math functions (note: all integer types are now supported!)
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Wed, 28 Apr 2010 19:09:35 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=YGxwBKE3i4yg/j7lb4GpSDdTe/7wCywFqyDiZwkiC4Y=; b=hAOzMAUSgc2a92qfUYvVG12rTZdQViTCLgl+CWXwHbfODVlhegiYsjUknSklb5XPh/ lCDzMmOlJA7T8MYOZ/uK7f1wXFxKYV87YsJzUIJrZX4TRCA9arU5wrVRw9w7P9YTYjQ+ fE7O3ZSkP5O1L8tcA+XiH6nzFwehZ294v+TRQ=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=IKmjF0t+wWFIe2kGp8yZGKuuQSMZ1Zwd4G3v3o58o14YBF4gn/zLPBkrSukui81BRj PUmvsXFud0ifz2VnudPEaeBuH7tsSaoSx327YnV5d5kA7GLDKWHopkJrXIlAoLZO0cjT ZYUbNpcwvTjkMerOw++BXKvgC0gCGVAuEcVM0=
Hi List,
*** The big news ***
All integer types, from "unsigned char" to "long long", are now
correctly supported. There's a new unit test for that: integer_types.
This is a consequence of a big rework of NumTraits (does no longer
inherit numeric_limits) and of our global math functions (ei_sin...)
which are now templated.
*** Interface changes ***
All that also means some interface changes if you are adding support
for custom types.
The NumTraits changes are small, see the "Customizing Eigen" dox page
once it'll be updated.
For the math functions, the changes are a bit bigger as you can see in
MathFunctions.h. Let's take ei_sin as an example. It's a matter of
adding a specialization of a struct ei_sin_impl<Scalar> for your type.
Suppose that you want to add ei_sin() support for your custom
FixedPoint type. You'd do something like that:
namespace Eigen
{
struct ei_sin_impl<FixedPoint>
{
// here you tell Eigen what's the return type of ei_sin(FixedPoint)
typedef FixedPoint retval;
// and here you implement the function
static inline FixedPoint run(const FixedPoint& x)
{
return my_fixedpoint_sin_function(x);
}
};
}
So yes, that's more verbose than before. But isn't it worth it, to get
that generic system that supports e.g. all integer types for free?
Another remark is that part of our global math functions were already
like that (e.g. ei_random) so we used to have a discrepancy between
templated and non-templated functions. Finally, if a user has to
support a lot of math functions for his custom type, he'll be able to
write a macro to factor the code.
*** Call for good wills ***
If you're looking for a useful task to accomplish, here's one: update
the dox page (doc/I00_CustomizingEigen.dox) to explain how to do these
specializations of math functions (like above). Instead of Adolc's
adouble which is quite special, and already handled in an unsupported
module, how about carrying on the FixedPoint example?
*** Testing needed ***
Especially in the Array support (so 'array' unit test), I'm using
SFINAE, that is highly susceptible of breaking MSC support.
Benoit