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

Zero Expression

Tags: None
(comma "," separated)
pups
Registered Member
Posts
2
Karma
0

Zero Expression

Wed Mar 30, 2016 8:38 am
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.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Zero Expression

Thu Mar 31, 2016 9:33 pm
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.
pups
Registered Member
Posts
2
Karma
0

Re: Zero Expression

Mon Apr 04, 2016 11:26 am
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).
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Zero Expression

Mon Apr 04, 2016 1:13 pm
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):

Code: Select all
class ... {
   typedef ... VectorType;
  const VectorType::ConstantReturnType my_vec() const {
    return VectorType::Zero(this->get_size());
  }
};

unless you really cannot implement such a get_size() method....


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient