mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
Fix permutation/transposiitons products wrt nested_eval
This commit is contained in:
parent
0c8b0e007b
commit
5c84dd5665
@ -842,17 +842,19 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape,
|
|||||||
* Internal helper class implementing the product between a permutation matrix and a matrix.
|
* Internal helper class implementing the product between a permutation matrix and a matrix.
|
||||||
* This class is specialized for DenseShape below and for SparseShape in SparseCore/SparsePermutation.h
|
* This class is specialized for DenseShape below and for SparseShape in SparseCore/SparsePermutation.h
|
||||||
*/
|
*/
|
||||||
template<typename MatrixType, int Side, bool Transposed, typename MatrixShape>
|
template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape>
|
||||||
struct permutation_matrix_product;
|
struct permutation_matrix_product;
|
||||||
|
|
||||||
template<typename MatrixType, int Side, bool Transposed>
|
template<typename ExpressionType, int Side, bool Transposed>
|
||||||
struct permutation_matrix_product<MatrixType, Side, Transposed, DenseShape>
|
struct permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
|
||||||
{
|
{
|
||||||
|
typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
|
||||||
typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
|
typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
|
||||||
|
|
||||||
template<typename Dest, typename PermutationType>
|
template<typename Dest, typename PermutationType>
|
||||||
static inline void run(Dest& dst, const PermutationType& perm, const MatrixType& mat)
|
static inline void run(Dest& dst, const PermutationType& perm, const ExpressionType& xpr)
|
||||||
{
|
{
|
||||||
|
MatrixType mat(xpr);
|
||||||
const Index n = Side==OnTheLeft ? mat.rows() : mat.cols();
|
const Index n = Side==OnTheLeft ? mat.rows() : mat.cols();
|
||||||
// FIXME we need an is_same for expression that is not sensitive to constness. For instance
|
// FIXME we need an is_same for expression that is not sensitive to constness. For instance
|
||||||
// is_same_xpr<Block<const Matrix>, Block<Matrix> >::value should be true.
|
// is_same_xpr<Block<const Matrix>, Block<Matrix> >::value should be true.
|
||||||
@ -893,7 +895,7 @@ struct permutation_matrix_product<MatrixType, Side, Transposed, DenseShape>
|
|||||||
|
|
||||||
=
|
=
|
||||||
|
|
||||||
Block<const MatrixTypeCleaned,Side==OnTheLeft ? 1 : MatrixType::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixType::ColsAtCompileTime>
|
Block<const MatrixTypeCleaned,Side==OnTheLeft ? 1 : MatrixTypeCleaned::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixTypeCleaned::ColsAtCompileTime>
|
||||||
(mat, ((Side==OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i);
|
(mat, ((Side==OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -951,26 +953,30 @@ struct generic_product_impl<Lhs, Transpose<Rhs>, MatrixShape, PermutationShape,
|
|||||||
* \class transposition_matrix_product
|
* \class transposition_matrix_product
|
||||||
* Internal helper class implementing the product between a permutation matrix and a matrix.
|
* Internal helper class implementing the product between a permutation matrix and a matrix.
|
||||||
*/
|
*/
|
||||||
template<typename MatrixType, int Side, bool Transposed, typename MatrixShape>
|
template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape>
|
||||||
struct transposition_matrix_product
|
struct transposition_matrix_product
|
||||||
{
|
{
|
||||||
template<typename Dest, typename TranspositionType>
|
typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
|
||||||
static inline void run(Dest& dst, const TranspositionType& tr, const MatrixType& mat)
|
typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
|
||||||
{
|
|
||||||
typedef typename TranspositionType::StorageIndex StorageIndex;
|
template<typename Dest, typename TranspositionType>
|
||||||
const Index size = tr.size();
|
static inline void run(Dest& dst, const TranspositionType& tr, const ExpressionType& xpr)
|
||||||
StorageIndex j = 0;
|
{
|
||||||
|
MatrixType mat(xpr);
|
||||||
|
typedef typename TranspositionType::StorageIndex StorageIndex;
|
||||||
|
const Index size = tr.size();
|
||||||
|
StorageIndex j = 0;
|
||||||
|
|
||||||
if(!(is_same<MatrixType,Dest>::value && extract_data(dst) == extract_data(mat)))
|
if(!(is_same<MatrixTypeCleaned,Dest>::value && extract_data(dst) == extract_data(mat)))
|
||||||
dst = mat;
|
dst = mat;
|
||||||
|
|
||||||
for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
|
for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
|
||||||
if(Index(j=tr.coeff(k))!=k)
|
if(Index(j=tr.coeff(k))!=k)
|
||||||
{
|
{
|
||||||
if(Side==OnTheLeft) dst.row(k).swap(dst.row(j));
|
if(Side==OnTheLeft) dst.row(k).swap(dst.row(j));
|
||||||
else if(Side==OnTheRight) dst.col(k).swap(dst.col(j));
|
else if(Side==OnTheRight) dst.col(k).swap(dst.col(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user