Re: [eigen] how to create a "virtual" array or matrix? |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] how to create a "virtual" array or matrix?*From*: Carlos Becker <carlosbecker@xxxxxxxxx>*Date*: Mon, 7 Jun 2010 21:52:49 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=ZuWEorzsFk6ggpN7E6lDpbbit451tkduQf9KyT1t8bw=; b=g8xa8x8l8ODmrpg6dOkSuiwK1mfShsq7TXid5xNlgDKX18Jyv5Mj7v+97Wv4aNv1L0 nm3VfsQ4MYcjD70ds5JvAytomT2LkCpg60QRyp7vGanYkvoOYig0UjFKfNAkfg/TtDvO 65hIrSu7IM0oDK09EgQ7pTKggP5/XjqHetyss=*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; b=LDnCrd3Q3DWpzYQ2RtVoCzTeAMSTQvwLVuhw/dKMNBNvHaAIFpG5jZZdAPAW9ktX/D ZWv6E+XfdPaOwDQDWpTW1zSbwJN/wjg4K7hDDeo5iLEsHNr9mMleZOo5NAyim6ThRJeT 6IVnqjxT2wdGdn/XmiWsHVF4t315R51CBC5Q0=

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,

Carlos

On Mon, Jun 7, 2010 at 9:20 PM, David Roundy <roundyd@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi all,

I'd like to create an object that describes an easily-computable

array. In particular, I want to work with some vectors describing

functions of position. In order to easily manipulate these, I'd like

to create an object containing the value $|\vec{r}|^2$. I could, of

course, fill a vector with this value, but that would be a waste of

memory, since it's really cheap to compute. And these vectors will

eventually end up being quite large (maybe a GB or so), so I'd prefer

not to allocate the memory. In the past, I'd have just written a loop

to sum over all positions, but that leads to ugly and hard-to-maintain

code, since a non-trivial loop then shows up many times in the code

(there's a bit of trickiness involving finding the Wigner-Seitz cell).

And it seems that template expressions provide almost precisely what

I want.

Is there a class that does this, e.g. something like

class VirtualMatrix<...? {

VirtualMatrix(double (*func)(int, int));

}

which could just take a function of indices and turns it into a matrix?

If there isn't something like this built into eigen, would it be easy

to create? I've tried (briefly) to create a new class deriving

MatrixBase, but immediately ran into trouble. Perhaps I just know too

little about C++ templates to use eigen effectively. :(

David Roundy

**Follow-Ups**:**Re: [eigen] how to create a "virtual" array or matrix?***From:*joel falcou

**Re: [eigen] how to create a "virtual" array or matrix?***From:*David Roundy

**References**:**[eigen] how to create a "virtual" array or matrix?***From:*David Roundy

**Messages sorted by:**[ date | thread ]- Prev by Date:
**[eigen] how to create a "virtual" array or matrix?** - Next by Date:
**Re: [eigen] how to create a "virtual" array or matrix?** - Previous by thread:
**[eigen] how to create a "virtual" array or matrix?** - Next by thread:
**Re: [eigen] how to create a "virtual" array or matrix?**

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