Re: [eigen] Accepting different matrix type in the decompositions |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Accepting different matrix type in the decompositions
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 20 Jul 2010 11:18:43 -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=eeF6ShgsFPs9KmharTuFAuPdusQlpHEsTaSvj8hnZis=; b=AFmdB8Bhod3obgsFVg2kw8pzAq/MWn1WK2gszwrfgnE2SXdQQbPrmjwkFCg5Tqj2Xd WsOOA0sCtaJoonsg6KY49nYgyHUqG5RGNmFF0XjQAjV8R1fqyGq+oZHFyIDfs81A99Sd WQkL64rhGcKy98yGqmDHRhSCtqpVcVdNUESJ8=
- 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=Oesn9D6rhyZbdasuPp7lDY68ywXa7coECuruKxqd0DNOvYIhvboinQciQMtqLFAOz/ LaMt7SXBxipKnS1fHLVjeMdmTOgTILijGU71B6035zxEvfA3NcdpDmz8RQ9iICA1RpxK Myo4bW4ows+3ec7OmdvUhuP4/zRuOV1ZaBPig=
2010/7/20 Gael Guennebaud <gael.guennebaud@xxxxxxxxx>:
> Hi,
>
> this makes sense to me.
>
> Note that we have to make sure the actual decomposition is not
> performed by the templated compute() method, but by an internal
> function (to reduce binary code duplication...). This is already the
> case for a few decs (typically the ones working per block), but not
> for all. Anyway, this is a simple change.
I agree with Adrien's suggestion and with your remark :-)
Benoit
>
> gael
>
> On Tue, Jul 20, 2010 at 9:52 AM, ESCANDE Adrien 222264
> <adrien.escande@xxxxxx> wrote:
>>
>> Hello again,
>>
>> the different decompositions (QR, LU...) I looked at are all templated by a type MatrixType and have, among others, a method compute(const MatrixType& matrix) with a line m_matrix = matrix, and a constructor
>> Decomposition(const MatrixType& matrix) calling compute.
>> I think it wouldn't hurt to template these two methods by a type InputMatrixName:
>> template<typename MatrixType>
>> template<typename InputMatrixType>
>> Decomposition<MatrixType>::Decomposition(const InputMatrixType& matrix)
>>
>> and
>>
>> template<typename MatrixType>
>> template<typename InputMatrixType>
>> Decomposition<MatrixType>::compute(const InputMatrixType& matrix)
>>
>> this way, when InputMatrixType is different from MatrixType, there is no need to create a temporary object for the conversion, and this conversion is only made at the line m_matrix = matrix.
>>
>> In the usual case where the user use the .decomposition() method of MatrixBase<Derived> (for example matrix.colPivHouseholderQR()), we have MatrixType = Derived::PlainObject and InputMatrixBase = Derived, and there's no need to call eval() within decomposition.
>>
>> And this simplify the writing in other cases. My use case (a complete orthogonal decomposition):
>> ColPivHouseholderQR<MatrixXd> LQ(M.transpose());
>> HouseholderQR<MatrixXd> qr(LQ.matrixQR().topLeftCorner(LQ.rank(), LQ.cols()).triangularView<Upper>().transpose());
>> I don't even want to imagine the MatrixType I should have wrote for the HouseholderQR...
>> By adding the InputMatrixType template, I avoid there two temporaries.
>>
>> I wanted to add a static assert to check for the compatibility of MatrixType and InputMatrixType, but ei_is_same_type<MatrixType, InputMatrixType::PlainObject>::ret seems to be a too strict condition. I just test the same scalar type for now.
>>
>> Adrien
>>
>>
>>
>
>
>