Re: [eigen] numerical differentiation

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


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



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/