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 static int nb_temporaries;
00026
00027 void on_temporary_creation(int size) {
00028
00029 if(size!=0) nb_temporaries++;
00030 }
00031
00032
00033 #define EIGEN_DENSE_STORAGE_CTOR_PLUGIN { on_temporary_creation(size); }
00034
00035 #include "main.h"
00036
00037 #define VERIFY_EVALUATION_COUNT(XPR,N) {\
00038 nb_temporaries = 0; \
00039 XPR; \
00040 if(nb_temporaries!=N) std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; \
00041 VERIFY( (#XPR) && nb_temporaries==N ); \
00042 }
00043
00044 template<typename MatrixType> void product_notemporary(const MatrixType& m)
00045 {
00046
00047
00048 typedef typename MatrixType::Index Index;
00049 typedef typename MatrixType::Scalar Scalar;
00050 typedef typename MatrixType::RealScalar RealScalar;
00051 typedef Matrix<Scalar, 1, Dynamic> RowVectorType;
00052 typedef Matrix<Scalar, Dynamic, 1> ColVectorType;
00053 typedef Matrix<Scalar, Dynamic, Dynamic, ColMajor> ColMajorMatrixType;
00054 typedef Matrix<Scalar, Dynamic, Dynamic, RowMajor> RowMajorMatrixType;
00055
00056 Index rows = m.rows();
00057 Index cols = m.cols();
00058
00059 ColMajorMatrixType m1 = MatrixType::Random(rows, cols),
00060 m2 = MatrixType::Random(rows, cols),
00061 m3(rows, cols);
00062 RowVectorType rv1 = RowVectorType::Random(rows), rvres(rows);
00063 ColVectorType cv1 = ColVectorType::Random(cols), cvres(cols);
00064 RowMajorMatrixType rm3(rows, cols);
00065
00066 Scalar s1 = internal::random<Scalar>(),
00067 s2 = internal::random<Scalar>(),
00068 s3 = internal::random<Scalar>();
00069
00070 Index c0 = internal::random<Index>(4,cols-8),
00071 c1 = internal::random<Index>(8,cols-c0),
00072 r0 = internal::random<Index>(4,cols-8),
00073 r1 = internal::random<Index>(8,rows-r0);
00074
00075 VERIFY_EVALUATION_COUNT( m3 = (m1 * m2.adjoint()), 1);
00076 VERIFY_EVALUATION_COUNT( m3.noalias() = m1 * m2.adjoint(), 0);
00077
00078 VERIFY_EVALUATION_COUNT( m3.noalias() = s1 * (m1 * m2.transpose()), 0);
00079
00080 VERIFY_EVALUATION_COUNT( m3.noalias() = s1 * m1 * s2 * m2.adjoint(), 0);
00081 VERIFY_EVALUATION_COUNT( m3.noalias() = s1 * m1 * s2 * (m1*s3+m2*s2).adjoint(), 1);
00082 VERIFY_EVALUATION_COUNT( m3.noalias() = (s1 * m1).adjoint() * s2 * m2, 0);
00083 VERIFY_EVALUATION_COUNT( m3.noalias() += s1 * (-m1*s3).adjoint() * (s2 * m2 * s3), 0);
00084 VERIFY_EVALUATION_COUNT( m3.noalias() -= s1 * (m1.transpose() * m2), 0);
00085
00086 VERIFY_EVALUATION_COUNT(( m3.block(r0,r0,r1,r1).noalias() += -m1.block(r0,c0,r1,c1) * (s2*m2.block(r0,c0,r1,c1)).adjoint() ), 0);
00087 VERIFY_EVALUATION_COUNT(( m3.block(r0,r0,r1,r1).noalias() -= s1 * m1.block(r0,c0,r1,c1) * m2.block(c0,r0,c1,r1) ), 0);
00088
00089
00090 VERIFY_EVALUATION_COUNT(( m3.block(r0,r0,r1,r1).noalias() = s1 * m1.block(r0,c0,r1,c1) * (s1*m2).block(c0,r0,c1,r1) ), 1);
00091
00092 VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).template triangularView<Lower>() * m2, 0);
00093 VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView<Upper>() * (m2+m2), 1);
00094 VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView<UnitUpper>() * m2.adjoint(), 0);
00095
00096
00097 VERIFY_EVALUATION_COUNT( rm3.col(c0).noalias() = (s1 * m1.adjoint()).template triangularView<UnitUpper>() * (s2*m2.row(c0)).adjoint(), 1);
00098
00099 VERIFY_EVALUATION_COUNT( m1.template triangularView<Lower>().solveInPlace(m3), 0);
00100 VERIFY_EVALUATION_COUNT( m1.adjoint().template triangularView<Lower>().solveInPlace(m3.transpose()), 0);
00101
00102 VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).adjoint().template selfadjointView<Lower>() * (-m2*s3).adjoint(), 0);
00103 VERIFY_EVALUATION_COUNT( m3.noalias() = s2 * m2.adjoint() * (s1 * m1.adjoint()).template selfadjointView<Upper>(), 0);
00104 VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template selfadjointView<Lower>() * m2.adjoint(), 0);
00105
00106
00107 VERIFY_EVALUATION_COUNT( m3.col(c0).noalias() = (s1 * m1).adjoint().template selfadjointView<Lower>() * (-m2.row(c0)*s3).adjoint(), 1);
00108 VERIFY_EVALUATION_COUNT( m3.col(c0).noalias() -= (s1 * m1).adjoint().template selfadjointView<Upper>() * (-m2.row(c0)*s3).adjoint(), 1);
00109
00110 VERIFY_EVALUATION_COUNT( m3.block(r0,c0,r1,c1).noalias() += m1.block(r0,r0,r1,r1).template selfadjointView<Upper>() * (s1*m2.block(r0,c0,r1,c1)), 0);
00111 VERIFY_EVALUATION_COUNT( m3.block(r0,c0,r1,c1).noalias() = m1.block(r0,r0,r1,r1).template selfadjointView<Upper>() * m2.block(r0,c0,r1,c1), 0);
00112
00113 VERIFY_EVALUATION_COUNT( m3.template selfadjointView<Lower>().rankUpdate(m2.adjoint()), 0);
00114
00115
00116 m3.resize(1,1);
00117 VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template selfadjointView<Lower>() * m2.block(r0,c0,r1,c1), 1);
00118 m3.resize(1,1);
00119 VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template triangularView<UnitUpper>() * m2.block(r0,c0,r1,c1), 1);
00120
00121
00122 VERIFY_EVALUATION_COUNT( Scalar tmp = 0; tmp += Scalar(RealScalar(1)) / (m3.transpose().lazyProduct(m3)).diagonal().sum(), 0 );
00123
00124
00125 VERIFY_EVALUATION_COUNT( Scalar tmp = 0; tmp += Scalar(RealScalar(1)) / (m3.transpose() * m3).diagonal().sum(), 0 );
00126 VERIFY_EVALUATION_COUNT( Scalar tmp = 0; tmp += Scalar(RealScalar(1)) / (m3.transpose() * m3).diagonal().array().abs().sum(), 0 );
00127
00128
00129
00130
00131
00132
00133 VERIFY_EVALUATION_COUNT( cvres.noalias() = m1 * cv1, 0 );
00134 VERIFY_EVALUATION_COUNT( cvres.noalias() -= m1 * cv1, 0 );
00135 VERIFY_EVALUATION_COUNT( cvres.noalias() -= m1 * m2.col(0), 0 );
00136 VERIFY_EVALUATION_COUNT( cvres.noalias() -= m1 * rv1.adjoint(), 0 );
00137 VERIFY_EVALUATION_COUNT( cvres.noalias() -= m1 * m2.row(0).transpose(), 0 );
00138 }
00139
00140 void test_product_notemporary()
00141 {
00142 int s;
00143 for(int i = 0; i < g_repeat; i++) {
00144 s = internal::random<int>(16,320);
00145 CALL_SUBTEST_1( product_notemporary(MatrixXf(s, s)) );
00146 s = internal::random<int>(16,320);
00147 CALL_SUBTEST_2( product_notemporary(MatrixXd(s, s)) );
00148 s = internal::random<int>(16,120);
00149 CALL_SUBTEST_3( product_notemporary(MatrixXcf(s,s)) );
00150 s = internal::random<int>(16,120);
00151 CALL_SUBTEST_4( product_notemporary(MatrixXcd(s,s)) );
00152 }
00153 }