diff options
author | Gael Guennebaud <g.gael@free.fr> | 2010-09-02 19:18:34 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2010-09-02 19:18:34 +0200 |
commit | 62eb4dc99bb79a0e2015548c248d6270928533f1 (patch) | |
tree | 51a6dcd1e16ecfdbe515a140e296f35af6ef50a4 /test | |
parent | 4824db64443d4057a3e183548aa4c63ea2c1060f (diff) |
noalias was wrongly skipping automatic transposition
Diffstat (limited to 'test')
-rw-r--r-- | test/basicstuff.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
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()); |