|Re: [eigen] Map's and not Maps|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Map's and not Maps
- From: "Gael Guennebaud" <gael.guennebaud@xxxxxxxxx>
- Date: Mon, 8 Dec 2008 12:58:14 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=5SEf+JqLaLTIbqXACqDZbgw1X2SRGk2dsURvWfm1wOU=; b=jMr5z1V33Rsnb8iOFyyVcHkdtRANuUHqM7wUM9hiFOvw4m7PdkMMOwecydNwkUJhuI ui+FiWPs/4LN+eVzjdwd9zlLh6xuQf2hU58bnlhQRcoAR+1QRRWEw36DCnaLwL11O+CS /1jYqBfZHhC3bF+/Tn+fSeusVwKyERi22CZ8c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=NYO3V+1WNF6BNnM8I50QTR9q/XnTDd3oNO/1ARNAFnMIMJbGgywPmkTgLUJ18Eu6zP 1AsZuyYHLtDnS0duQiLCzz3j0M//2/6u2piQExAhp2vYuFJo/8/Wc6e3ojW7LlnkqZXs aR8QvHBSJm6Zm5WRQaGNrjMwwKbUGZRhevstw=
you guessed right, the major issue avoiding such a construction is owing to the alignment of the data. Indeed, the vectorization of some fixed size vector/matrix types assume that the data are correctly aligned. So, in a general, you cannot avoid to generate 2 versions of SomeCoolFunction, one with the vectorization and one without (see below).
In the very specific cases where the vectorization is disabled and/or you know the vector type won't be vectorized by Eigen or you know the data are aligned, then you can still simply cast your pointer:
float result = SomeCoolFunction(*reinterpret_cast<Vector3f*>(inputdata), bla);
For instance, for Vector3f this is always ok because this type cannot be vectorized. (if we forget the use of reinterpret_cast which is not super clean)
A much more general solution is to template SomeCoolFunction and use static assertions to check the input types, eg:
float SomeCoolFunction(MatrixBase<Derived>& v, void* somedata)
The advantage of this approach is that you can take as input any vector _expression_ like a sub vector of a matrix:
A drawback might be that the same code could be generated multiple time (though the compiler/linker are supposed to be able to factorize such redundancies automatically, but I don't really trust them for that).
I agree that this solution is not optimal from a user perspective, but currently I cannot see any better solution to that issue.
On Mon, Dec 8, 2008 at 12:06 PM, Benjamin Schindler <bschindler@xxxxxxxxxxxxxxx>
There is currently one thing which I really don't like atm in eigen. For ease, I use a lot of direct vector's. But all the data I get from outside is in the form of pointers, so I have to use maps. One thing I would really love to have is a way to be able to do the following:
float SomeCoolFunction(Vector3f& v, void* somedata);
float result = SomeCoolFunction(input, bla);
This is currently not possibel and I'm not sure what exactly is needed to support this kind of stuff and in which way this would impact performance (One can't assume alignment for example etc). But from a design perspective, this would be just amazing :)