Re: [eigen] numerical differentiation |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] numerical differentiation
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sun, 27 Sep 2009 22:27:50 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=DLXLv/KMmLuIxvwHHrJ3LNyX0IsOHuf2R1LXKUULzME=; b=EvE+w3a4QjlxME/h2/YrbLx8Xb1NzSWcBLDUrRmCi7uHmp2ETJV+l9BdpOo7L51vhy 1pA0ceGEIVeHjrBTXrxl6vzo+GmGfmiDgUVdP6e7GkRiOVn47nNuCiO3oAL4Fv5XDhU9 xxDSpBkwri1RKrneifYQU4BJ2D6OB7j4gx3d8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=idP9YwWHX5muAXQC2d/WM1W63whQT0lGsdWBhRt8f2t/fUSCDsTXMj/YMChLdh6FPc D2u3o4IVwktyIK0dyWQe0j3FUXJJeGC72t/Bqm6Qrbl/y9bN/LjU42+PhlM/K+q/QdNz NCWF7hlrwowmkRP8yRQNxDOjJlG5UIslq/CAw=
2009/9/27 Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>:
>
>
> Well, anyway, i've put one in unsupported/NumericalDiff on my eigen fork, it
> provides Forward and Central, with (quite basic) unit tests :
>
> http://bitbucket.org/orzel/eigen2-
> cminpack/src/tip/unsupported/Eigen/src/NumericalDiff/NumericalDiff.h
> http://bitbucket.org/orzel/eigen2-
> cminpack/src/tip/unsupported/test/NumericalDiff.cpp
>
> I use a template parameter 'mode' to select which one is used... and i have
> two questions related to this:
>
> * in the code i use a switch(mode), in the hope that the compiler will
> optimize this and only the relevant code will be compiled-in, and no test will
> be made at run-time for the switch... can you confirm ?
Yes, no problem. Since mode is explicitly known at compile time (as a
template parameter), i know that at least GCC will always resolve the
branching at compile time, even in full debug mode.
>
> * i'm afraid that the enum for the mode is cluttering the namespace.. how
> could i do better ?
Good question. This is a general problem that we have to solve before
eigen3. For now, say that if it compiles it's OK.
Ideas for general solutions:
* use namespaced/typed enums. This is the clean solution, but it's
hard to do without making the API cumbersome.
Perhaps we could have small structs containing enums like
struct NumericalDiffMode {
enum NumericalDiffMode {
Forward,
Central
};
};
and then a using-statement:
using NumericalDiffMode::NumericalDiffMode;
(or a typedef if that doesnt work).
Then the only difference from what we currently have is that the enum
values are namespaced and typed. Which I think is good!
What do you think?
Benoit