mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 19:29:02 +08:00
noalias was wrongly skipping automatic transposition
This commit is contained in:
parent
4824db6444
commit
62eb4dc99b
@ -43,6 +43,7 @@
|
|||||||
template<typename ExpressionType, template <typename> class StorageBase>
|
template<typename ExpressionType, template <typename> class StorageBase>
|
||||||
class NoAlias
|
class NoAlias
|
||||||
{
|
{
|
||||||
|
typedef typename ExpressionType::Scalar Scalar;
|
||||||
public:
|
public:
|
||||||
NoAlias(ExpressionType& expression) : m_expression(expression) {}
|
NoAlias(ExpressionType& expression) : m_expression(expression) {}
|
||||||
|
|
||||||
@ -50,17 +51,27 @@ class NoAlias
|
|||||||
* \sa MatrixBase::lazyAssign() */
|
* \sa MatrixBase::lazyAssign() */
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
|
EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
|
||||||
{ return m_expression.lazyAssign(other.derived()); }
|
{ return ei_assign_selector<ExpressionType,OtherDerived,false>::run(m_expression,other.derived()); }
|
||||||
|
|
||||||
/** \sa MatrixBase::operator+= */
|
/** \sa MatrixBase::operator+= */
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
|
EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
|
||||||
{ return m_expression.lazyAssign(m_expression + other.derived()); }
|
{
|
||||||
|
typedef SelfCwiseBinaryOp<ei_scalar_sum_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
|
||||||
|
SelfAdder tmp(m_expression);
|
||||||
|
ei_assign_selector<SelfAdder,OtherDerived,false>::run(tmp,other.derived());
|
||||||
|
return m_expression;
|
||||||
|
}
|
||||||
|
|
||||||
/** \sa MatrixBase::operator-= */
|
/** \sa MatrixBase::operator-= */
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
|
EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
|
||||||
{ return m_expression.lazyAssign(m_expression - other.derived()); }
|
{
|
||||||
|
typedef SelfCwiseBinaryOp<ei_scalar_difference_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
|
||||||
|
SelfAdder tmp(m_expression);
|
||||||
|
ei_assign_selector<SelfAdder,OtherDerived,false>::run(tmp,other.derived());
|
||||||
|
return m_expression;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||||
template<typename ProductDerived, typename Lhs, typename Rhs>
|
template<typename ProductDerived, typename Lhs, typename Rhs>
|
||||||
|
@ -31,6 +31,7 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
|||||||
typedef typename MatrixType::Index Index;
|
typedef typename MatrixType::Index Index;
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||||
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
|
||||||
|
|
||||||
Index rows = m.rows();
|
Index rows = m.rows();
|
||||||
Index cols = m.cols();
|
Index cols = m.cols();
|
||||||
@ -47,6 +48,7 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
|||||||
VectorType v1 = VectorType::Random(rows),
|
VectorType v1 = VectorType::Random(rows),
|
||||||
v2 = VectorType::Random(rows),
|
v2 = VectorType::Random(rows),
|
||||||
vzero = VectorType::Zero(rows);
|
vzero = VectorType::Zero(rows);
|
||||||
|
SquareMatrixType sm1 = SquareMatrixType::Random(rows,rows), sm2(rows,rows);
|
||||||
|
|
||||||
Scalar x = ei_random<Scalar>();
|
Scalar x = ei_random<Scalar>();
|
||||||
|
|
||||||
@ -121,6 +123,27 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
|||||||
m1 = m2;
|
m1 = m2;
|
||||||
VERIFY(m1==m2);
|
VERIFY(m1==m2);
|
||||||
VERIFY(!(m1!=m2));
|
VERIFY(!(m1!=m2));
|
||||||
|
|
||||||
|
// check automatic transposition
|
||||||
|
sm2.setZero();
|
||||||
|
for(typename MatrixType::Index i=0;i<rows;++i)
|
||||||
|
sm2.col(i) = sm1.row(i);
|
||||||
|
VERIFY_IS_APPROX(sm2,sm1.transpose());
|
||||||
|
|
||||||
|
sm2.setZero();
|
||||||
|
for(typename MatrixType::Index i=0;i<rows;++i)
|
||||||
|
sm2.col(i).noalias() = sm1.row(i);
|
||||||
|
VERIFY_IS_APPROX(sm2,sm1.transpose());
|
||||||
|
|
||||||
|
sm2.setZero();
|
||||||
|
for(typename MatrixType::Index i=0;i<rows;++i)
|
||||||
|
sm2.col(i).noalias() += sm1.row(i);
|
||||||
|
VERIFY_IS_APPROX(sm2,sm1.transpose());
|
||||||
|
|
||||||
|
sm2.setZero();
|
||||||
|
for(typename MatrixType::Index i=0;i<rows;++i)
|
||||||
|
sm2.col(i).noalias() -= sm1.row(i);
|
||||||
|
VERIFY_IS_APPROX(sm2,-sm1.transpose());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MatrixType> void basicStuffComplex(const MatrixType& m)
|
template<typename MatrixType> void basicStuffComplex(const MatrixType& m)
|
||||||
@ -177,14 +200,14 @@ void test_basicstuff()
|
|||||||
for(int i = 0; i < g_repeat; i++) {
|
for(int i = 0; i < g_repeat; i++) {
|
||||||
CALL_SUBTEST_1( basicStuff(Matrix<float, 1, 1>()) );
|
CALL_SUBTEST_1( basicStuff(Matrix<float, 1, 1>()) );
|
||||||
CALL_SUBTEST_2( basicStuff(Matrix4d()) );
|
CALL_SUBTEST_2( basicStuff(Matrix4d()) );
|
||||||
CALL_SUBTEST_3( basicStuff(MatrixXcf(3, 3)) );
|
CALL_SUBTEST_3( basicStuff(MatrixXcf(ei_random<int>(1,100), ei_random<int>(1,100))) );
|
||||||
CALL_SUBTEST_4( basicStuff(MatrixXi(8, 12)) );
|
CALL_SUBTEST_4( basicStuff(MatrixXi(ei_random<int>(1,100), ei_random<int>(1,100))) );
|
||||||
CALL_SUBTEST_5( basicStuff(MatrixXcd(20, 20)) );
|
CALL_SUBTEST_5( basicStuff(MatrixXcd(ei_random<int>(1,100), ei_random<int>(1,100))) );
|
||||||
CALL_SUBTEST_6( basicStuff(Matrix<float, 100, 100>()) );
|
CALL_SUBTEST_6( basicStuff(Matrix<float, 100, 100>()) );
|
||||||
CALL_SUBTEST_7( basicStuff(Matrix<long double,Dynamic,Dynamic>(10,10)) );
|
CALL_SUBTEST_7( basicStuff(Matrix<long double,Dynamic,Dynamic>(ei_random<int>(1,100),ei_random<int>(1,100))) );
|
||||||
|
|
||||||
CALL_SUBTEST_3( basicStuffComplex(MatrixXcf(21, 17)) );
|
CALL_SUBTEST_3( basicStuffComplex(MatrixXcf(ei_random<int>(1,100), ei_random<int>(1,100))) );
|
||||||
CALL_SUBTEST_5( basicStuffComplex(MatrixXcd(2, 3)) );
|
CALL_SUBTEST_5( basicStuffComplex(MatrixXcd(ei_random<int>(1,100), ei_random<int>(1,100))) );
|
||||||
}
|
}
|
||||||
|
|
||||||
CALL_SUBTEST_2(casting());
|
CALL_SUBTEST_2(casting());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user