Re: [eigen] To initialize or not to initialize

[ Thread Index | Date Index | More Archives ]

2010/4/16 Adolfo Rodríguez Tsouroukdissian <adolfo.rodriguez@xxxxxxxxxxxxxxxxx>:
> Looking into the code of various decompositions I've seen that the
> constructors for input matrix are sometimes implemented like this (dummy
> example):
> fooDecomp(const MatrixType& matrix) : m_mat(matrix.rows(), matrix.rows())
> {
>   compute(matrix);
> }
> and sometimes like this:
> fooDecomp(const MatrixType& matrix) // <- Notice no initialization
> {
>   compute(matrix);
> }
> First of all, I'd like to propose uniforming this (I could do it), but I
> also wanted to know how big a difference is there between the two
> alternatives.

The better version is the one with the initialization list. The other,
without initialization list, means that in case of a dynamic matrix,
it is initialized with size 0 and then resized by the compute()
method. This amounts almost exactly to the same, there is just a tiny
bit of inefficiency here.

OK to uniformize all decompositions with initialization lists.

> I know that in general it's best to follow the first approach and initialize
> class members, but is it still so in the case of Eigen matrices?. Are the
> differences greater when certain macros are defines, such as

It doesn't make a difference evec if EIGEN_INITIALIZE_BY_ZERO is
defined, because the matrices get filled by the compute() method

Don't bother about EIGEN_INITIALIZE_BY_ZERO. The only reason why I was
OK for it was that it was a small  local change that the rest of Eigen
doesn't need to care about. If that changed, we'd probably prefer to
remove that option, than have one more thing to constantly worry


> TIA,
> Adolfo
> --
> Adolfo Rodríguez Tsouroukdissian, Ph. D.
> Robotics engineer
> Tel. +34.93.414.53.47
> Fax.+
> AVISO DE CONFIDENCIALIDAD: Este mensaje y sus documentos adjuntos, pueden
> contener información privilegiada y/o confidencial que está dirigida
> exclusivamente a su destinatario. Si usted recibe este mensaje y no es el
> destinatario indicado, o el empleado encargado de su entrega a dicha
> persona, por favor, notifíquelo inmediatamente y remita el mensaje original
> a la dirección de correo electrónico indicada. Cualquier copia, uso o
> distribución no autorizados de esta comunicación queda estrictamente
> prohibida.
> CONFIDENTIALITY NOTICE: This e-mail and the accompanying document(s) may
> contain confidential information which is privileged and intended only for
> the individual or entity to whom they are addressed.  If you are not the
> intended recipient, you are hereby notified that any disclosure, copying,
> distribution or use of this e-mail and/or accompanying document(s) is
> strictly prohibited.  If you have received this e-mail in error, please
> immediately notify the sender at the above e-mail address.

Mail converted by MHonArc 2.6.19+