|[eigen] Qt's container support|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] Qt's container support
- From: "Gael Guennebaud" <gael.guennebaud@xxxxxxxxx>
- Date: Tue, 20 Jan 2009 10:38:41 +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:mime-version:content-type:content-transfer-encoding :content-disposition; bh=ttzqx57hQzn01RYvswXpcIH9mkxaIY5Eh8VazlAmKbQ=; b=muKanuiXvLVtEKITaBEQ/GalyfWXwcuf1B7RGLysX17Lc2knrMoC+6Txa11FI+8xEm D3SZIGII1kST3I1kzzSTTwbJOkueGRjqRFRxV+Rr0CTE6MroQKnPCfODm0dYbghl2XPj c06RAsdtF69OryO0UE6YN0Q3OTQ5y3MqjZXsg=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=WlscVkPTMtGAIjAyv5okKmdUInwMQQPfZmFmMRRUyBQruDQCMIls2VmCzzvE5Ratpg w27jcQ/mX1PmvBIvYkrmiuD1WNExAflHiF4PXYMTM6L+G6F3fRV8HJiqDodAjzASuAxy t1w+WPDyda+P13sT0ozshI3RnWXw9NrTnkXRQ=
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:
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
before including Eigen/Core seems to do the job.
=> PROBLEM SOLVED.
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
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
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.
a) allow operator= to set/resize an uninitialized matrix
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 ?