This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 291

Summary: Missing Aliasing assert or a bug
Product: Eigen Reporter: Hordur Johannsson <hordurj>
Component: Core - generalAssignee: Nobody <eigen.nobody>
Status: NEW ---    
Severity: enhancement CC: chtz, gael.guennebaud, jacob.benoit.1
Priority: ---    
Version: 3.0   
Hardware: All   
OS: All   
Whiteboard:

Description Hordur Johannsson 2011-06-09 15:50:46 UTC
VectorXd a(2);
 a << 1,2;
 a = a.segment(0,1);
 cout << a;

outputs:
 0

using eval fixes the bug.
  a.segment(0,1).eval()

If this is the expected behaviour it would be useful to have an aliasing assert for this case.
Comment 1 Gael Guennebaud 2011-06-09 16:51:13 UTC
Detecting all cases of aliasing is a very difficult task. Though we do detect a few cases involving transpose, the programmer is supposed to know what he is doing.
Comment 2 Christoph Hertzberg 2011-06-09 21:20:10 UTC
Just a side note:
I guess this particular example could also be implemented using 
  a.conservativeResize(1);

A general suggestion for this problem:
If a vector/matrix changes its size during assignment, one could:
* allocate a new (temp) vector
* assign the expression to the temp vector
* swap the vectors
* deallocate the temp vector (happens automatically)

I guess this would cause virtually no overhead in most cases, OTOH it might be a bad idea, if users rely on this behavior and then a vector accidentally does not change its size ...
Comment 3 Nobody 2019-12-04 10:50:54 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/291.