Registered Member
|
is it possible to create a zero expression that would have a dimension of 'any'. The usage is that I have a vector inside an object. For one variant of the constructor the vector can not be initialised because I do not know the appropriate size in that case. But I do know that it should be zero (and will remain zero forever), hence I would like to have a zero expression that would behave as a zero vector of the correct dimension whenever used in an eigen expression. The clumsy alternative is to check for an uninitialised vector in every operation and execute a special case as if it was zero.
|
Moderator
|
Do you know the the vector will be zero at compile-time or only at runtime? In the first case you could workaround by warping your "vector" within a member returning a VectorXd::Zero(n) object (I guess that when the vector is going to be used then you will know which size it must have). In the later case, then the type must be a VectorXd (or similar), and so it must have a proper size with proper values before being used.
|
Registered Member
|
I only know the size at run-time.
It seems to me that since Eigen uses expression templates it should be possible to have a zero-expression template which contains no data, does no dimension checking, and evals to a no-op for addition/subtraction and returns a zero matrix or vector of the appropriate size for multiplication, NANs on inversion. I wondered if such a thing already existed, if not I will file a feature request (or implement myself if I ever get time). |
Moderator
|
Yes, such a feature has been planed: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=112, but there is nothing concrete yet.
I still think you can make use of: VectorType::Zero(n):
unless you really cannot implement such a get_size() method.... |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient