Re: [eigen] how to create a "virtual" array or matrix?
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] how to create a "virtual" array or matrix?
• From: David Roundy <roundyd@xxxxxxxxxxxxxxxxxxxxxxx>
• Date: Mon, 7 Jun 2010 13:27:38 -0700

```I think I wasn't very clear.  I am using a VectorXd to store the
number density (of a fluid), which is a function of position, so I
maintain a mapping from indices in the vector to points on a 3D grid
in space.

class Grid : public VectorXd {
public:
explicit Grid(Lattice lat, int nx, int ny, int nz)
...
};

I would like to represent the magnitude of the position at each point
(or the x component of the position, or whatever) without storing any
(large) data, since it's easy to compute on the fly.

David

On Mon, Jun 7, 2010 at 12:52 PM, Carlos Becker <carlosbecker@xxxxxxxxx> wrote:
> Hi David, I am not sure if I am understanding but you want to do. But, if
> you have your vectors already allocated somewhere you can use the Map
> function of Eigen to map that memory into an Eigen matrix without
> duplicating it so you can do something like:
> Map<MatrixXf> vectors( startingPointer, numRows, numCols );
> float totalSum = vectors.array().square().colwise().sum();
> (I haven't tested this code but this is the idea)
> You can also map a single vector since the solution above would be mapping
> several of them. Also take into account if you are using row- or
> column-major alignment.
> I hope it helps,

```

 Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/