mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-11 23:51:49 +08:00
Fix linear indexing in generic block evaluation.
(grafted from 12efc7d41b80259b996be5781bf596c249c90d3f )
This commit is contained in:
parent
bfc66e8b9a
commit
15752027ec
@ -1020,7 +1020,8 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& block)
|
EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& block)
|
||||||
: m_argImpl(block.nestedExpression()),
|
: m_argImpl(block.nestedExpression()),
|
||||||
m_startRow(block.startRow()),
|
m_startRow(block.startRow()),
|
||||||
m_startCol(block.startCol())
|
m_startCol(block.startCol()),
|
||||||
|
m_linear_offset(InnerPanel?(XprType::IsRowMajor ? block.startRow()*block.cols() : block.startCol()*block.rows()):0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
typedef typename XprType::Scalar Scalar;
|
typedef typename XprType::Scalar Scalar;
|
||||||
@ -1039,6 +1040,9 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
CoeffReturnType coeff(Index index) const
|
CoeffReturnType coeff(Index index) const
|
||||||
{
|
{
|
||||||
|
if (InnerPanel)
|
||||||
|
return m_argImpl.coeff(m_linear_offset.value() + index);
|
||||||
|
else
|
||||||
return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1051,6 +1055,9 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
Scalar& coeffRef(Index index)
|
Scalar& coeffRef(Index index)
|
||||||
{
|
{
|
||||||
|
if (InnerPanel)
|
||||||
|
return m_argImpl.coeffRef(m_linear_offset.value() + index);
|
||||||
|
else
|
||||||
return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1065,6 +1072,9 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
EIGEN_STRONG_INLINE
|
EIGEN_STRONG_INLINE
|
||||||
PacketType packet(Index index) const
|
PacketType packet(Index index) const
|
||||||
{
|
{
|
||||||
|
if (InnerPanel)
|
||||||
|
return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index);
|
||||||
|
else
|
||||||
return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
|
return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
|
||||||
RowsAtCompileTime == 1 ? index : 0);
|
RowsAtCompileTime == 1 ? index : 0);
|
||||||
}
|
}
|
||||||
@ -1080,6 +1090,9 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
EIGEN_STRONG_INLINE
|
EIGEN_STRONG_INLINE
|
||||||
void writePacket(Index index, const PacketType& x)
|
void writePacket(Index index, const PacketType& x)
|
||||||
{
|
{
|
||||||
|
if (InnerPanel)
|
||||||
|
return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index, x);
|
||||||
|
else
|
||||||
return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
|
return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
|
||||||
RowsAtCompileTime == 1 ? index : 0,
|
RowsAtCompileTime == 1 ? index : 0,
|
||||||
x);
|
x);
|
||||||
@ -1089,6 +1102,7 @@ protected:
|
|||||||
evaluator<ArgType> m_argImpl;
|
evaluator<ArgType> m_argImpl;
|
||||||
const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
|
const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
|
||||||
const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
|
const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
|
||||||
|
const variable_if_dynamic<Index, InnerPanel ? Dynamic : 0> m_linear_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: This evaluator does not actually use the child evaluator;
|
// TODO: This evaluator does not actually use the child evaluator;
|
||||||
|
@ -37,7 +37,7 @@ template<typename MatrixType> void block(const MatrixType& m)
|
|||||||
typedef typename MatrixType::RealScalar RealScalar;
|
typedef typename MatrixType::RealScalar RealScalar;
|
||||||
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||||
typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
|
typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
|
||||||
typedef Matrix<Scalar, Dynamic, Dynamic> DynamicMatrixType;
|
typedef Matrix<Scalar, Dynamic, Dynamic, MatrixType::IsRowMajor?RowMajor:ColMajor> DynamicMatrixType;
|
||||||
typedef Matrix<Scalar, Dynamic, 1> DynamicVectorType;
|
typedef Matrix<Scalar, Dynamic, 1> DynamicVectorType;
|
||||||
|
|
||||||
Index rows = m.rows();
|
Index rows = m.rows();
|
||||||
@ -131,7 +131,7 @@ template<typename MatrixType> void block(const MatrixType& m)
|
|||||||
VERIFY(numext::real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows));
|
VERIFY(numext::real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows));
|
||||||
VERIFY(numext::real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols));
|
VERIFY(numext::real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols));
|
||||||
|
|
||||||
// chekc that linear acccessors works on blocks
|
// check that linear acccessors works on blocks
|
||||||
m1 = m1_copy;
|
m1 = m1_copy;
|
||||||
if((MatrixType::Flags&RowMajorBit)==0)
|
if((MatrixType::Flags&RowMajorBit)==0)
|
||||||
VERIFY_IS_EQUAL(m1.leftCols(c1).coeff(r1+c1*rows), m1(r1,c1));
|
VERIFY_IS_EQUAL(m1.leftCols(c1).coeff(r1+c1*rows), m1(r1,c1));
|
||||||
@ -155,6 +155,13 @@ template<typename MatrixType> void block(const MatrixType& m)
|
|||||||
VERIFY_IS_APPROX( ((m1+m2).block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)).transpose() );
|
VERIFY_IS_APPROX( ((m1+m2).block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)).transpose() );
|
||||||
VERIFY_IS_APPROX( ((m1+m2).transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)).transpose() );
|
VERIFY_IS_APPROX( ((m1+m2).transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)).transpose() );
|
||||||
|
|
||||||
|
VERIFY_IS_APPROX( (m1*1).topRows(r1), m1.topRows(r1) );
|
||||||
|
VERIFY_IS_APPROX( (m1*1).leftCols(c1), m1.leftCols(c1) );
|
||||||
|
VERIFY_IS_APPROX( (m1*1).transpose().topRows(c1), m1.transpose().topRows(c1) );
|
||||||
|
VERIFY_IS_APPROX( (m1*1).transpose().leftCols(r1), m1.transpose().leftCols(r1) );
|
||||||
|
VERIFY_IS_APPROX( (m1*1).transpose().middleRows(c1,c2-c1+1), m1.transpose().middleRows(c1,c2-c1+1) );
|
||||||
|
VERIFY_IS_APPROX( (m1*1).transpose().middleCols(r1,r2-r1+1), m1.transpose().middleCols(r1,r2-r1+1) );
|
||||||
|
|
||||||
// evaluation into plain matrices from expressions with direct access (stress MapBase)
|
// evaluation into plain matrices from expressions with direct access (stress MapBase)
|
||||||
DynamicMatrixType dm;
|
DynamicMatrixType dm;
|
||||||
DynamicVectorType dv;
|
DynamicVectorType dv;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user