Re: [eigen] Qt's container support |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Qt's container support
- From: Keir Mierle <mierle@xxxxxxxxx>
- Date: Tue, 20 Jan 2009 07:55:17 -0800
- 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=EQPI8nPnyB+/yeM5T2UepfmItoEt+4sddKgAKJ0YajU=; b=JESFRfWm1H+0xKVkiojqRZ1gYHWT9/vwxMB8QMvqmQJVNboQhiqcKdOJCZcJcK79jV 0bP1gjPATf3R7WOAlXs8u54S5++rOr9ej5hPLaAEi5H1pJp5jn1OElaz6tb18ic+X8qU 9jMJaJkQQKFf2o45Ulms2rZqgQjzsF0WnMrug=
- 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=WgtzKR+7b6BQWicVG9utotlCA+eUGjySFT0v2FoSfK1/AgfL0wBYnw35KybhS5H3Hf zsQtUebJoJBHdKTvcbONySpsQQFqeFCyT6yYfZwBzbsyhee32gKS1JP7eIRKSionwABy StPOBjMJm1VMVYiA7AGuoO2MRU9wtrSyNePJk=
On Tue, Jan 20, 2009 at 1:38 AM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
>
> Hi all,
>
> I think that being able to store Eigen's matrices in Qt's containers
> is very important (especially QVector<>), and just like std::vector,
> there are a couple of issues:
>
> Issue 1:
> QVector has a bug which avoids the use of QVector with types having a
> custom operator new
> - problem solved in Qt 4.5
> - for earlier versions defining
> EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5
> before including Eigen/Core seems to do the job.
> => PROBLEM SOLVED.
>
> Issue 2:
> the second problem is to enforce QVector to allocate aligned memory
> buffers. Fortunately, Qt's developers had the good idea to define
> wrapper functions around malloc/free/realloc called qMalloc, qFree
> etc.
> So the workaround is simply to redefine these functions to call
> ei_align_malloc. I added a Eigen/QtAlignedMalloc header which exactly
> does that (I'll commit it once the next issue will be solved).
> => PROBLEM SOLVED
>
> Issue3:
> The last issue I found is with QVector::fill(const T&,size_t) which is
> the equivalent of std::vector<T>::resize(size_t,T). Here the argument
> is passed by reference so no alignment issue. The problem is the use
> of the default ctor and operator= to initialize/copy the new elements
> while our operator= does not allow to set an uninitialized matrix.
> Solutions:
> a) allow operator= to set/resize an uninitialized matrix
What is wrong with (a)? I'd like to have this anyway.
Consider
MatrixXd A, B, C, D;
A << some data values;
ComputeBCAndDFromA(A, &B, &C, &D); /* fails */
B.resize(...); /* resize to appropriate size */
C.resize(...); /* resize to appropriate size */
D.resize(...); /* resize to appropriate size */
ComputeBCAndDFromA(A, &B, &C, &D); /* works? */
void ComputeBCAndDFromA(...) {
*B = ....
*C = ...
*D = ...
}
I realize you can use set to assign to B, C, and D inside
ComputeBCAndDfromA, but I consistently get this wrong and consider it
to be an API wart. For example, I can never remember when I have to
use .set() and when I can use operator=; especially with regards to
blocks.
What is necessary to make assigning to matrices and blocks consistent?
> b) specialize QVector for Eigen's matrix type using a similar trick
> than for std::vector such that we only have to redefine the fill()
> method to use Matrix::set()
> c) do nothing and enforce the user to use .resize() followed by a for
> loop instead of fill().
>
> I vote for solution b)
>
> any opinion ?
>
> Gael.
>
>