Re: [eigen] Eigen objects as vectors and matrices |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 02.07.2012 17:41, Brad Bell wrote:
I want to an object both as a matrix and as a vector, so I am
constructing the object using
Matrix<double, Dynamic, Dynamic> object(m*n, 1);
and then plan to do an
object. conservativeResize(m, n)
before using it as a matrix. The problem is that the bracket operator
object[i]
does not seem to work when object is a vector (and the software I am
using access vectors this way).
operator[] intentionally only works if the expression is known to be a
vector at compile time. A reason for that is to avoid silly bugs such as
object[1,2] which is legal C++ for object[2].
Is there a reason, you need Matrix and Vector to have the same type?
If you just want to share their memory, you can construct a Map to
object.data():
MatrixXd object(m,n);
// Vector Expression:
VectorXd::Map(object.data(), object.size())
Christoph
--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------