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

VectorXd::reverse doing in-place reverse?

Tags: None
(comma "," separated)
Galmok
Registered Member
Posts
9
Karma
0
OS
Documentation on 'reverse' is lacking regarding whether it does in-place reverse or not.

I have a VectorXd called e.g. test and is filled with 5 numbers, from 1 to 5:

1
2
3
4
5

This does nothing:

test.reverse();


This however does something:

test = test.reverse();

5
4
3
4
5

This looks like in-place reversing that doesn't use intermediate storage.

Do I always have to put the output of reverse into a new vector or is there a simple way to get a vector reversed without doubling the storage?
Galmok
Registered Member
Posts
9
Karma
0
OS
Solved it by doing it with a temporary vector...

VectorXd tmp = test.reverse();
test = tmp;
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
well, the documentation says:

Returns: an expression of the reverse of *this.

So just like any other functions (transpose, normalize, adjoint, replicate) it's clear that it does nothing until the expression gets assigned to another object.

http://eigen.tuxfamily.org/dox/classEig ... ce4b4649e2

There is also a reverseInPlace() function.
Galmok
Registered Member
Posts
9
Karma
0
OS
Appreciate the hints. :)


Bookmarks



Who is online

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