00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026
00027 template<typename MatrixType> void basicStuff(const MatrixType& m)
00028 {
00029 typedef typename MatrixType::Scalar Scalar;
00030 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00031
00032 int rows = m.rows();
00033 int cols = m.cols();
00034
00035
00036
00037 MatrixType m1 = MatrixType::Random(rows, cols),
00038 m2 = MatrixType::Random(rows, cols),
00039 m3(rows, cols),
00040 mzero = MatrixType::Zero(rows, cols),
00041 identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
00042 ::Identity(rows, rows),
00043 square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>::Random(rows, rows);
00044 VectorType v1 = VectorType::Random(rows),
00045 v2 = VectorType::Random(rows),
00046 vzero = VectorType::Zero(rows);
00047
00048 Scalar x = ei_random<Scalar>();
00049
00050 int r = ei_random<int>(0, rows-1),
00051 c = ei_random<int>(0, cols-1);
00052
00053 m1.coeffRef(r,c) = x;
00054 VERIFY_IS_APPROX(x, m1.coeff(r,c));
00055 m1(r,c) = x;
00056 VERIFY_IS_APPROX(x, m1(r,c));
00057 v1.coeffRef(r) = x;
00058 VERIFY_IS_APPROX(x, v1.coeff(r));
00059 v1(r) = x;
00060 VERIFY_IS_APPROX(x, v1(r));
00061 v1[r] = x;
00062 VERIFY_IS_APPROX(x, v1[r]);
00063
00064 VERIFY_IS_APPROX( v1, v1);
00065 VERIFY_IS_NOT_APPROX( v1, 2*v1);
00066 VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1);
00067 if(NumTraits<Scalar>::HasFloatingPoint)
00068 VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1.norm());
00069 VERIFY_IS_NOT_MUCH_SMALLER_THAN(v1, v1);
00070 VERIFY_IS_APPROX( vzero, v1-v1);
00071 VERIFY_IS_APPROX( m1, m1);
00072 VERIFY_IS_NOT_APPROX( m1, 2*m1);
00073 VERIFY_IS_MUCH_SMALLER_THAN( mzero, m1);
00074 VERIFY_IS_NOT_MUCH_SMALLER_THAN(m1, m1);
00075 VERIFY_IS_APPROX( mzero, m1-m1);
00076
00077
00078
00079
00080
00081
00082
00083 VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows,cols)(r,c), static_cast<Scalar>(1));
00084
00085
00086 square.col(r) = square.row(r).eval();
00087 Matrix<Scalar, 1, MatrixType::RowsAtCompileTime> rv(rows);
00088 Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> cv(rows);
00089 rv = square.row(r);
00090 cv = square.col(r);
00091 VERIFY_IS_APPROX(rv, cv.transpose());
00092
00093 if(cols!=1 && rows!=1 && MatrixType::SizeAtCompileTime!=Dynamic)
00094 {
00095 VERIFY_RAISES_ASSERT(m1 = (m2.block(0,0, rows-1, cols-1)));
00096 }
00097
00098 VERIFY_IS_APPROX(m3 = m1,m1);
00099 MatrixType m4;
00100 VERIFY_IS_APPROX(m4 = m1,m1);
00101
00102
00103 m3 = m1;
00104 m1.swap(m2);
00105 VERIFY_IS_APPROX(m3, m2);
00106 if(rows*cols>=3)
00107 {
00108 VERIFY_IS_NOT_APPROX(m3, m1);
00109 }
00110 }
00111
00112 void test_eigen2_basicstuff()
00113 {
00114 for(int i = 0; i < g_repeat; i++) {
00115 CALL_SUBTEST_1( basicStuff(Matrix<float, 1, 1>()) );
00116 CALL_SUBTEST_2( basicStuff(Matrix4d()) );
00117 CALL_SUBTEST_3( basicStuff(MatrixXcf(3, 3)) );
00118 CALL_SUBTEST_4( basicStuff(MatrixXi(8, 12)) );
00119 CALL_SUBTEST_5( basicStuff(MatrixXcd(20, 20)) );
00120 CALL_SUBTEST_6( basicStuff(Matrix<float, 100, 100>()) );
00121 CALL_SUBTEST_7( basicStuff(Matrix<long double,Dynamic,Dynamic>(10,10)) );
00122 }
00123 }