Re: [eigen] How to create a Matrix<...> without copying data ? |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] How to create a Matrix<...> without copying data ?*From*: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>*Date*: Mon, 17 May 2010 11:44:11 -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=ViHmaXXVKLb2jnJuX4lFDXJLJhSeNWDeyPcsbxZDsCY=; b=U5VHFXKigS97WNXIe3nylJOaVib88ebMjKjaJVr+W3xfNsz/NtO8+AgRpuQnCZmGpo 32UpoygZ1a23GPOYz0zCI792ltoQCKo1rmwvDMskjFespllIpRtQZhwkpEO6gYQKQuwU xmU4NgAeCHbukxD+yAqaSk8Lc4u3SQCAJ3uHA=*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=ogbkTaeTvclWI5bkXFvu4tm/saDpTJC1NeAjwj1pU5jkq7nsLs5pOQ1lbtkSsyXdQf BHeGIKvA/5dxkwyb+K5qGCgaex/qER5jqnrdfuQYpUjSYjDGKQUoW2r17U3R3vfiw68G WTjoGSuMeld6f8gY+fO31KFTYn01fe7InM/AI=

2010/5/17 <vincent.lejeune@xxxxxxxxxx>: > > Another question... > > > > I have my own LU decomposition function. I want to encapsulate it in a > > class like PartialPivLU, in order to benefit from already written function > > that compute permutation matrix, perform matrix reconstruction, and so > > on... > > But the compute method and the blocked_lu methods of this class, are not > > virtual. That means that if I write a class that inherit from PartialPivLU, > > the compute method that will be used is the one from PartialPivLU. > > Is there a workaround, beside copy/pasting the PartialPivLU to meet my > > needs ? You can still inherit, just make sure to override in your derived class any method calling compute(), fortunately I think that's only the constructors, which you would have had to redefine anyway. Not being virtual doesn't mean that you can't override in a derived class. It just means that code calling the base class method will still be calling the base class method, won't automatically use the derived class method. Benoit > > > > Thx, > > Vincent. > > > > On Mon, 17 May 2010 09:02:41 -0400, Benoit Jacob > > <jacob.benoit.1@xxxxxxxxx> > > wrote: > >> Yes, Eigen defaults to column-major. You can change that per-matrix by > >> using the RowMajor option, for example: > >> > >> typedef Matrix<double, Dynamic, Dynamic, RowMajor> MyRowMajorMatrixXd; > >> > >> or you can change the global default, breaking the ABI, by doing > >> > >> #define EIGEN_DEFAULT_TO_ROW_MAJOR > >> > >> Benoit > >> > >> 2010/5/17 <vincent.lejeune@xxxxxxxxxx>: > >>> > >>> Thx. > >>> > >>> BTW are Eigen matrix stored in column major format, as with > > blas/lapack, > >>> > >>> by default ? > >>> > >>> Is there a command to change storage order of a matrix ? > >>> > >>> > >>> > >>> On Mon, 17 May 2010 13:32:22 +0200, Gael Guennebaud > >>> > >>> <gael.guennebaud@xxxxxxxxx> wrote: > >>> > >>>> On Mon, May 17, 2010 at 12:30 PM, Benoit Jacob > >>> > >>>> <jacob.benoit.1@xxxxxxxxx>wrote: > >>> > >>>> > >>> > >>>>> You can do: > >>> > >>>>> > >>> > >>>>> PartialPivLU<MatrixXd> lu(matrix.block(...)); > >>> > >>>>> > >>> > >>>>> or, from your double* pointer, > >>> > >>>>> > >>> > >>>>> PartialPivLU<MatrixXd> > >>> > >>>>> lu(Map<MatrixXd>(pointer,rows,cols).block(...)); > >>> > >>>>> > >>> > >>>>> or you can even get rid of the block() call by doing a strided Map. > >>> > >>>>> > >>> > >>>>> What we don't allow at the moment is in-place LU, i.e. allowing to > > not > >>> > >>>>> even copy that block. > >>> > >>>>> > >>> > >>>> > >>> > >>>> well, if you are not afraid about using internal functions, and so > >>> > >>>> functions > >>> > >>>> which can be removed/changed in the future, you can use this one: > >>> > >>>> > >>> > >>>> template<typename MatrixType, typename IntVector> > >>> > >>>> void ei_partial_lu_inplace(MatrixType& lu, IntVector& > >>> > >>> row_transpositions, > >>> > >>>> int& nb_transpositions); > >>> > >>>> > >>> > >>>> e.g., > >>> > >>>> > >>> > >>>> // declare a name variable for the block because current C++ standard > >>> > >>>> sucks. > >>> > >>>> Block<MyMatrix> bl(matrix, ....); > >>> > >>>> VectorXi row_transpositions(matrix.rows()); > >>> > >>>> int nb_transpositions; > >>> > >>>> > >>> > >>>> ei_partial_lu_inplace(bl, row_transpositions, nb_transpositions); > >>> > >>>> > >>> > >>>> The problem is that now you cannot exploit this LU dec via the > >>> > >>> PartialPivLU > >>> > >>>> API, but maybe that's enough for your needs... ? > >>> > >>>> > >>> > >>>> gael > >>> > >>>> > >>> > >>>> > >>> > >>>>> > >>> > >>>>> Benoit > >>> > >>>>> > >>> > >>>>> 2010/5/17 <vincent.lejeune@xxxxxxxxxx>: > >>> > >>>>> > > >>> > >>>>> > Hi, > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > I have a matrix stored as a double* in columnsmajor format. > >>> > >>>>> > > >>> > >>>>> > I would like to compute the LU factorisation of a part of the > > matrix > >>> > >>>>> (that > >>> > >>>>> > > >>> > >>>>> > is, not the whole matrix, just a sub square of it) inplace, ie I do > >>> > >>> not > >>> > >>>>> > > >>> > >>>>> > want to copy data to an temporary buffer. > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > Is it possible using Eigen ? I saw that PartialPivLU class copy > > input > >>> > >>>>> > > >>> > >>>>> > matrix when constructed... > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > Thx, > >>> > >>>>> > > >>> > >>>>> > Vincent > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > > >>> > >>>>> > >>> > >>>>> > >>> > >>>>> > >>> > >>> > >>> > > >

**References**:**[eigen] How to create a Matrix<...> without copying data ?***From:*vincent.lejeune

**Re: [eigen] How to create a Matrix<...> without copying data ?***From:*Benoit Jacob

**Re: [eigen] How to create a Matrix<...> without copying data ?***From:*Gael Guennebaud

**Re: [eigen] How to create a Matrix<...> without copying data ?***From:*vincent.lejeune

**Re: [eigen] How to create a Matrix<...> without copying data ?***From:*Benoit Jacob

**Re: [eigen] How to create a Matrix<...> without copying data ?***From:*vincent.lejeune

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] How to create a Matrix<...> without copying data ?** - Next by Date:
**Re: [eigen] Indexes: why signed instead of unsigned?** - Previous by thread:
**Re: [eigen] How to create a Matrix<...> without copying data ?** - Next by thread:
**[eigen] Blocked QR decomposition ?**

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