aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Eigen/src/Core/NoAlias.h17
-rw-r--r--test/basicstuff.cpp35
2 files changed, 43 insertions, 9 deletions
diff --git a/Eigen/src/Core/NoAlias.h b/Eigen/src/Core/NoAlias.h
index d34f83b7b..03198879f 100644
--- a/Eigen/src/Core/NoAlias.h
+++ b/Eigen/src/Core/NoAlias.h
@@ -43,6 +43,7 @@
template<typename ExpressionType, template <typename> class StorageBase>
class NoAlias
{
+ typedef typename ExpressionType::Scalar Scalar;
public:
NoAlias(ExpressionType& expression) : m_expression(expression) {}
@@ -50,17 +51,27 @@ class NoAlias
* \sa MatrixBase::lazyAssign() */
template<typename OtherDerived>
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+= */
template<typename OtherDerived>
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-= */
template<typename OtherDerived>
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
template<typename ProductDerived, typename Lhs, typename Rhs>
diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp
index 3e5626454..4ff4a24fa 100644
--- a/test/basicstuff.cpp
+++ b/test/basicstuff.cpp
@@ -31,6 +31,7 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
typedef typename MatrixType::Index Index;
typedef typename MatrixType::Scalar Scalar;
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
+ typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
Index rows = m.rows();
Index cols = m.cols();
@@ -47,6 +48,7 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
+ SquareMatrixType sm1 = SquareMatrixType::Random(rows,rows), sm2(rows,rows);
Scalar x = ei_random<Scalar>();
@@ -121,6 +123,27 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
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)
@@ -177,14 +200,14 @@ void test_basicstuff()
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_1( basicStuff(Matrix<float, 1, 1>()) );
CALL_SUBTEST_2( basicStuff(Matrix4d()) );
- CALL_SUBTEST_3( basicStuff(MatrixXcf(3, 3)) );
- CALL_SUBTEST_4( basicStuff(MatrixXi(8, 12)) );
- CALL_SUBTEST_5( basicStuff(MatrixXcd(20, 20)) );
+ CALL_SUBTEST_3( basicStuff(MatrixXcf(ei_random<int>(1,100), ei_random<int>(1,100))) );
+ CALL_SUBTEST_4( basicStuff(MatrixXi(ei_random<int>(1,100), ei_random<int>(1,100))) );
+ 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_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_5( basicStuffComplex(MatrixXcd(2, 3)) );
+ CALL_SUBTEST_3( basicStuffComplex(MatrixXcf(ei_random<int>(1,100), ei_random<int>(1,100))) );
+ CALL_SUBTEST_5( basicStuffComplex(MatrixXcd(ei_random<int>(1,100), ei_random<int>(1,100))) );
}
CALL_SUBTEST_2(casting());