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 linearStructure(const MatrixType& m)
00028 {
00029
00030
00031
00032
00033 typedef typename MatrixType::Scalar Scalar;
00034 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00035
00036 int rows = m.rows();
00037 int cols = m.cols();
00038
00039
00040
00041 MatrixType m1 = MatrixType::Random(rows, cols),
00042 m2 = MatrixType::Random(rows, cols),
00043 m3(rows, cols),
00044 mzero = MatrixType::Zero(rows, cols);
00045
00046 Scalar s1 = ei_random<Scalar>();
00047 while (ei_abs(s1)<1e-3) s1 = ei_random<Scalar>();
00048
00049 int r = ei_random<int>(0, rows-1),
00050 c = ei_random<int>(0, cols-1);
00051
00052 VERIFY_IS_APPROX(-(-m1), m1);
00053 VERIFY_IS_APPROX(m1+m1, 2*m1);
00054 VERIFY_IS_APPROX(m1+m2-m1, m2);
00055 VERIFY_IS_APPROX(-m2+m1+m2, m1);
00056 VERIFY_IS_APPROX(m1*s1, s1*m1);
00057 VERIFY_IS_APPROX((m1+m2)*s1, s1*m1+s1*m2);
00058 VERIFY_IS_APPROX((-m1+m2)*s1, -s1*m1+s1*m2);
00059 m3 = m2; m3 += m1;
00060 VERIFY_IS_APPROX(m3, m1+m2);
00061 m3 = m2; m3 -= m1;
00062 VERIFY_IS_APPROX(m3, m2-m1);
00063 m3 = m2; m3 *= s1;
00064 VERIFY_IS_APPROX(m3, s1*m2);
00065 if(NumTraits<Scalar>::HasFloatingPoint)
00066 {
00067 m3 = m2; m3 /= s1;
00068 VERIFY_IS_APPROX(m3, m2/s1);
00069 }
00070
00071
00072 VERIFY_IS_APPROX((-m1)(r,c), -(m1(r,c)));
00073 VERIFY_IS_APPROX((m1-m2)(r,c), (m1(r,c))-(m2(r,c)));
00074 VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
00075 VERIFY_IS_APPROX((s1*m1)(r,c), s1*(m1(r,c)));
00076 VERIFY_IS_APPROX((m1*s1)(r,c), (m1(r,c))*s1);
00077 if(NumTraits<Scalar>::HasFloatingPoint)
00078 VERIFY_IS_APPROX((m1/s1)(r,c), (m1(r,c))/s1);
00079
00080
00081 VERIFY_IS_APPROX(m1+m1.block(0,0,rows,cols), m1+m1);
00082 VERIFY_IS_APPROX(m1.cwise() * m1.block(0,0,rows,cols), m1.cwise() * m1);
00083 VERIFY_IS_APPROX(m1 - m1.block(0,0,rows,cols), m1 - m1);
00084 VERIFY_IS_APPROX(m1.block(0,0,rows,cols) * s1, m1 * s1);
00085 }
00086
00087 void test_eigen2_linearstructure()
00088 {
00089 for(int i = 0; i < g_repeat; i++) {
00090 CALL_SUBTEST_1( linearStructure(Matrix<float, 1, 1>()) );
00091 CALL_SUBTEST_2( linearStructure(Matrix2f()) );
00092 CALL_SUBTEST_3( linearStructure(Vector3d()) );
00093 CALL_SUBTEST_4( linearStructure(Matrix4d()) );
00094 CALL_SUBTEST_5( linearStructure(MatrixXcf(3, 3)) );
00095 CALL_SUBTEST_6( linearStructure(MatrixXf(8, 12)) );
00096 CALL_SUBTEST_7( linearStructure(MatrixXi(8, 12)) );
00097 CALL_SUBTEST_8( linearStructure(MatrixXcd(20, 20)) );
00098 }
00099 }