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*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Tue, 20 Jul 2010 10:18:23 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=DzK/UGI9BV3MhpCj3NBg8jGv9hJWLlZhFd450IJkhPU=; b=FlOHc+9bpqDZ7hx/w4RDsJO6a1Xva2S3BwXxW8xOD6lSakiTo/3smgc7dCC76H8jc/ k5sJysEMXgKvIzXiSp9nYYIINY4J4zFzcZ4610Ff88FNSbVB/+mA4VEFOB+9OdKRjrHP CZl0I3GJYE/BR9ykfPt1Sdl52Wjx/d0MGkfsk=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=TY9TURaHucF5ZA4jwObYOXB0SzIO6F8TjkfnqRuojzx0frGoHzpRLUGbymmFaT2asL 4FCrgE4UzuvMWJYbCi042LmVwzOqOIeKFrEZsVPMUNRFPI3dwsDPR+t+KZKIS8W/R2mz blUgKNu70TR5NbIFfNXFQJuirsPc2ShS0GLdg=

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. 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 > > >

**Follow-Ups**:**Re: [eigen] Accepting different matrix type in the decompositions***From:*Benoit Jacob

**References**:**[eigen] Accepting different matrix type in the decompositions***From:*ESCANDE Adrien 222264

**Messages sorted by:**[ date | thread ]- Prev by Date:
**[eigen] Accepting different matrix type in the decompositions** - Next by Date:
**Re: [eigen] Permuted Matrix** - Previous by thread:
**[eigen] Accepting different matrix type in the decompositions** - Next by thread:
**Re: [eigen] Accepting different matrix type in the decompositions**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |