Re: [eigen] combine matrix blocks |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] combine matrix blocks
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 3 Jul 2009 09:55:08 +0200
- 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=rti/mD4Ub4Ygk+z+gI8eu3fMEt4NK1OMCgck8p2IL+k=; b=ixEIapAjyUsADaejLxs8Zwh4dpIwnkF7gzmZlDhCaegVU+tJU1ZIfZLCl80CiKSW/d zJR0L1wXkOzMcYKTaall4w8ttWyxfrZ+0vt83X4IiwR1dJnCSRHzqibHlRZR5Mrn5VhZ rqyCSdzgHwrR2ac9YGaFp0r61A93SpgWX2wj8=
- 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=gWH+RPC5FB+x1Kz57lakqdFZ9/tzLWIIFPlcJ10fczrG5J8e8E8k6gMj2wyMorcjK6 V+3mAr4D4beNKL8n3+7zEKX9H55l27ckCmxGARQoOC+tYAdIuwCoiFBHZVQ9ee9E7RKp Z188P1udrpXBiAqHzbw42RzK02vAJ/iiXQ/0A=
On Fri, Jul 3, 2009 at 9:12 AM, Stefan Ulbrich<s.ulbrich@xxxxxxxxxxxxxx> wrote:
> thanks for the answer. Actually, block / corner and minor don't allow you to
> select the for example the columns 1,3,4,6. The closest thing I found in
> Eigen is the Minor Class which allows to omit one row/col. I now tried to
> clone and to modificate this class but haven't finished it yet (still
> problems with io.h). This class will take two row-vectors that serve as a
> proxy for the addressing of the coefficients (allows for permutations,
> repetition of elements...). What do you think: do I have to worry about
> speed using this method? Does the use of Minor result in lower speed?
Indeed this requires a novel expression with a coeff(i,j) method which
looks like:
Scalar coeff(i,j) {
return m_matrix.coeff(m_rowIndices[i], m_colIndices[j]);
}
Assuming the compiler is able to move one of the m_*Indices[] out of
the inner evaluation loop, I guess this should be quite efficient.
Regarding API I think it'd be nice to be able to only provide a list
of rows or columns. To this end, the type of m_rowIndices could be a
template parameter for which the possibilities would be any kind of
integer vectors and a special class having n operator[i] always
returning "i". Regarding the names of these additional classes and
methods, I have no clue.
> In the same way I want to create a class that connects matrix with the same
> amount of rows (cols) to a single one.
yes it is quite easy to write such a matrix expression. Here is how
the coeff(i,j) method would look like:
Scalar coeff(i,j) {
if (j<m_matrixA.cols())
return m_matrixA.coeff(i,j);
else
return m_matrixB.coeff(i,j-m_matrixA.cols());
}
The problem is the "if" which will kill the performance (+ no
vectorization, etc.). So, if the memory consumption is not critical
for you I suggest you to copy the matrices to a single bigger one:
MatrixXf A, B, C;
/* ... */
A.resize(B.rows(), B.cols()+C.cols());
A << B, C;
This assignment is fast (vectorized), and then the use of A will be
fast too. Also note that this syntax is very powerful: it allows you
to assemble as many as scalars and/or matrix expressions as you want
in any direction. This is also why you have to set the size of the
matrix A manually. For instance you can also assemble B and C
vertically:
A.resize(B.rows()+C.rows(), B.cols());
A << B, C;
See the tutorial for other more fancy examples.
cheers,
Gael
> cheers,
> stefan
>
> Am 02.07.2009 um 19:46nachm. schrieb Thomas Capricelli:
>
>>
>>
>> Erm, all of this seems already available,have you read the tutorial
>> http://eigen.tuxfamily.org/dox/TutorialCore.html
>>
>> especially the part
>> http://eigen.tuxfamily.org/dox/TutorialCore.html#TutorialCoreMatrixBlocks
>>
>> Anything specific you think about that can not currently be done ?
>>
>> regards,
>> Thomas
>>
>> In data giovedì 02 luglio 2009 18:47:16, Stefan Ulbrich ha scritto:
>> : > Hello,
>>>
>>> in matlab you can select a partial matrix by explicitly specifying
>>> which cols and rows to take from the original matrix, e.g. with
>>> A([1,3],[2 4])
>>> further, it would be interesting to combine blocks into a matrix that
>>> serves as a proxy to the elements: A = [B C]
>>> I'd really would really like to see that functionality in eigen2. Do
>>> you think this is possible? Do you have any suggestions on how to
>>> start implementing it?
>>>
>>> best regards,
>>> Stefan
>>
>> --
>> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
>> http://www.freehackers.org/thomas
>>
>>
>
>
>
>