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: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Mon, 7 Jun 2010 16:28:51 -0400
- 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 :content-transfer-encoding; bh=URBa/9Ir6E9mPmSGeHwTmOIxohrZKkAgknZFXKfa6T0=; b=lWZGUU9zk2jIDMRiHns7AxNg6t3J5P9VfXfdEZ1/iaQKeGg0+KyrvBowMD5u4EnmRY /xFGbOQqOx6GFF+aBSNEGfSi7WaOX0PVLUNhTnbyB7aYPTIpveISUf533kT8hA2/He1y 2K/ORYIUIRRSN31/iucVW6pi5X6dTPLjSSKOI=
- 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=IJx00eKGGKp8lmqJ/is2xE7fO7sWJ75uIljY2WMBA/B6dhHLh3bsOv5V/P+GzN9Ds6 /OqObYCg7dx4OGAZvGBt8yfvM/ekJKCRKrzDAhzgtju6WVpOwI6eCxQZoQqEg39U/TlB VvvNdeAtfIrssCbMXbD3cApK0l/6QIAdMVqPQ=
I'm a work now so only have time to give a very short answer, so here goes.
In general, if you want to create a matrix expression from a functor
computing the coefficients, what you need is NullaryExpr:
http://eigen.tuxfamily.org/dox-devel/classEigen_1_1DenseBase.html#a84c2897928216cfb21ab81917e03b3a0
(and nevermind the typo telling you to look at Zero()).
If you want this to depend on another matrix expression, see
unaryExpr(). Depending on 2 other expression, see binaryExpr().
But in your special case you might not need that at all:
2010/6/7 David Roundy <roundyd@xxxxxxxxxxxxxxxxxxxxxxx>:
> 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.
Right. If you want an abstract matrix/vector expression where all the
coeffs have a given value, see Constant():
http://eigen.tuxfamily.org/dox-devel/classEigen_1_1DenseBase.html#abb7652b9ae2c6ee26be9db276613c4f6
again nevermind the Zero() typo, Constant() is meant.
For more general cases, see above.
Benoit
> 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
>
>
>