This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Initialization

Tags: None
(comma "," separated)
ostasse
Registered Member
Posts
7
Karma
0

Initialization

Wed Feb 06, 2013 10:51 am
Hi,
This email is about the current strategy related to the array initialization.
If I have understood correctly,
the default current initialization of the array is left to the user.
This is nice because it forces the algorithms relying on eigen to correctly initialize the matrices.

If one wish to set everything to zero it is possible to set the
EIGEN_INITIALIZE_MATRICES_BY_ZERO macro.

However there is no mechanisms to force the matrices to take a value wrong enough
to make the algorithm failed in conjunction with unitary tests if the matrices are not properly initialized.

The problem may appears later on when the value will be randomly "bad enough".
For instance, on a development platform a value not properly initialized will be set to 1e-319 and on a deployment platform the
value will be set to 1.0.

Could it be possible to propose a macro such as
EIGEN_INITIALIZE_MATRICES_BY_NAN to make sure that all
the matrices are initialized to a VERY wrong value ?
(Zero is not always a good solution, see rotation matrices for instance.)

This would be fantastic for debugging purposes.

Best Regards,
Olivier Stasse.
ostasse
Registered Member
Posts
7
Karma
0

Re: Initialization

Thu Feb 07, 2013 6:42 am
Hi,
Just a follow up on my previous post
with the following modification of PlaingObjectBase.h
Code: Select all
#ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
# define EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=Scalar(0);
#else
# ifdef EIGEN_INITIALIZE_MATRICES_BY_NAN
#   warning "Compiled with EIGEN_INITIALIZE_MATRICES_BY_NAN"
#   include <limits>
#   define EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN();
# else
#   define EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
# endif
#endif

recompiling the current repository in RELEASE mode with
Code: Select all
-DEIGEN_INITIALIZE_MATRICES_BY_NAN

make check gives:
The following tests FAILED:
543 - sparselu_4 (Failed)
558 - NonLinearOptimization (Failed)
600 - FFTW (Failed)
623 - minres_1 (Failed)
625 - levenberg_marquardt (Failed)

This is also a problem for regression tests aiming at evaluating computational time,
because some of the random initialization leads to denormalization.

Best,
Olivier
ostasse
Registered Member
Posts
7
Karma
0

Re: Initialization

Thu Feb 07, 2013 11:00 am
Hi again...
... so it seems that the unitary tests are failing anyway.
Therefore my previous post did not show anything useful..

So let us consider this small example
Code: Select all
#include <iostream>
# include "Eigen/Dense"

typedef Eigen::Matrix<double, 4,4> Matrix4d;

int main(void)
{
  Matrix4d x;
  std::cout << x << std::endl;
}

for which the typical output is:
Code: Select all
4.91066e-270 1.39065e-309 4.90963e-270 -7.19701e-42
  -0.0142836 -1.86093e-41 4.85935e-270   -0.0142835
1.52092e-314 -3.10726e-42 4.90963e-270  -1.9642e-41
4.86219e-270 4.87431e-270 4.87394e-270   -7.197e-42

Where some initialization are close to zero and therefore misleading,
instead of putting them to zero why not having this with the appropriate flag:
Code: Select all
nan nan nan nan
nan nan nan nan
nan nan nan nan
nan nan nan nan


Which is more easy to spot in a complex library.
ostasse
Registered Member
Posts
7
Karma
0

Re: Initialization

Thu Feb 07, 2013 5:41 pm
Thanks a lot for your reactivity !
Best,
Olivier.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Initialization  Topic is solved

Thu Feb 07, 2013 5:45 pm
ok, for the record, I think that's a good idea and it's there: https://bitbucket.org/eigen/eigen/commi ... c4c6cf786b
ostasse
Registered Member
Posts
7
Karma
0

Re: Initialization

Thu Feb 07, 2013 9:27 pm
Just in case to avoid any misunderstanding ...
In my previous post I was referring to your email on the eigen mailing list about the extension
that you implemented very quickly !
So, thank you very much for your reactivity.
Best,
Olivier.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]