[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Permuted Matrix
- From: "ESCANDE Adrien 222264" <adrien.escande@xxxxxx>
- Date: Mon, 19 Jul 2010 23:39:11 +0200
- Thread-index: AcsnitNNn01UuoE3RyCk+C9aXcJsog==
- Thread-topic: Permuted Matrix
I'd like to implement a permuted matrix i.e. a matrix P base on another M, such as P(i,j) = M(r[i], c[j]) for some permutation vectors r and c. It is very similar to the subject of another thread (how to create a "virtual" array or matrix) whose conclusion was to look at the way Minor class is implemented.
Based on this Minor example, it is indeed easy to implement a PermutedMatrix class for read-only purpose. It goes like this:
template<typename MatrixType> class PermutedMatrix
: public MatrixBase<PermutedMatrix<MatrixType> >
overload of coeff and coeffRef
One can then access to coefficients of the matrix, use block expression, triangular view,...
Writing in such a matrix is however a problem: PermutedMatrix can't have the DirectAccessBit bit because the "layout of the array of coefficients" is not "exactly the natural one suggested by rows(), cols(), outerStride(), innerStride(), and the RowMajorBit" DirectAccessBit documentation).
Thus PermutedMatrix only derives from DenseCoeffsBase<Derived, false> and not DenseCoeffsBase<Derived, true>. In particular, it does not inherit the good operator() (Index, Index), and the copyCoeffByOuterInner(Index, Index, const DenseBase<OtherDerived>&) methods, the latter being needed in the assignation.
Adding these missing methods directly in PermutedMatrix solves part of the problem: one can do P(i,j) = some_value or P = some_matrix, but they are still missing in expression based on PermutedMatrix , thus one can not do P.block(i,j,r,c) = another_matrix, because the copyCoeffByOuterInner of DenseCoeffsBase<Expr<PermutedMatrix<MatrixType> > > (in my example, Expr is Block) is not correctly defined.
Do I miss something on this problem ? Any direction I could take, or flag I don't know of ? I'm not very familiar with Eigen internals yet, so any pointers would be welcome.