Re: [eigen] Using Eigen::Map to use eigen operations on my data |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Using Eigen::Map to use eigen operations on my data
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Thu, 29 Oct 2009 16:49:56 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=b67i5juboWHXRz3kVrSU9Y3b7NHtaoVJbKYS44YiRmo=; b=DP6nuhvz4Q1nZECmAzdGOC0NPKNcETI/OH7Ng0R035axw2NGe3xZlgaBNeSbVKnFXv V4Eo01ydY2VSTUfTpbH5CMulz8TnrN12/2NHTjCuww6aRnd6q0Jq/lZMGE++ojO5Dsc6 FwpZS1FSiPGm6gnMV4q1mxOfKHPLn7OPN4f/Q=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=TqdWliLGFUu5zQgjAF+2pZLNs73YS4TqOPPtS9Xuu4RsR9nUvFo353ejELcmQVVQzx zELpLaFPS6eR6bDUyB3nLq08fW149c+lWk91futhROLdP486vbgl2Jf4ib6TVMvWrbDG wHi4hVPzfeSxNir4fvMwJQjznTKeWDq+kj39A=
2009/10/29 Robert Lupton the Good <rhl@xxxxxxxxxxxxxxxxxxx>:
> I must be missing something. The following code prints:
> [1 2 3 4]
> 1 0
> 0 1
>
> although I thought that the point of Map was to create an object that shared
> memory with an underlying array. What am I Missing?
>
> R
>
> #include <iostream>
> #include "Eigen/Core.h"
>
> using namespace std;
> using namespace Eigen;
>
> void identity(MatrixXf *mat) {
> (*mat)(0, 0) = (*mat)(1, 1) = 1;
> (*mat)(1, 0) = (*mat)(0, 1) = 0;
> }
>
> int main() {
> float data[4] = { 1, 2, 3, 4 };
> MatrixXf mat2x2 = MatrixXf(Map<MatrixXf>(data, 2, 2));
Here you are constructing a new MatrixXf, mat2x2, from the map.
after this line, mat2x2 is just another matrix and doesn't even
remember that it was copied from the Map.
>
> identity(&mat2x2);
Here you are calling identity on that matrix, not on the Map.
If you want to initialize an array as the identity matrix, do:
Map<MatrixXf>(data, 2, 2).setIdentity();
if you want to write your own function, make it like this:
template<typename Derived>
void identity(MatrixBase<Derived> *x)
>
> cout << "[" << data[0] << " " << data[1] << " " << data[2] << " " <<
> data[3] << "]\n" << mat2x2 << endl;
> }
>
>
>
>