mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #1562: optimize evaluation of small products of the form s*A*B by rewriting them as: s*(A.lazyProduct(B)) to save a costly temporary. Measured speedup from 2x to 5x...
(grafted from d428a199ab
)
This commit is contained in:
@@ -111,6 +111,17 @@ template<typename MatrixType> void product(const MatrixType& m)
|
||||
vcres.noalias() -= m1.transpose() * v1;
|
||||
VERIFY_IS_APPROX(vcres, vc2 - m1.transpose() * v1);
|
||||
|
||||
// test scaled products
|
||||
res = square;
|
||||
res.noalias() = s1 * m1 * m2.transpose();
|
||||
VERIFY_IS_APPROX(res, ((s1*m1).eval() * m2.transpose()));
|
||||
res = square;
|
||||
res.noalias() += s1 * m1 * m2.transpose();
|
||||
VERIFY_IS_APPROX(res, square + ((s1*m1).eval() * m2.transpose()));
|
||||
res = square;
|
||||
res.noalias() -= s1 * m1 * m2.transpose();
|
||||
VERIFY_IS_APPROX(res, square - ((s1*m1).eval() * m2.transpose()));
|
||||
|
||||
// test d ?= a+b*c rules
|
||||
res.noalias() = square + m1 * m2.transpose();
|
||||
VERIFY_IS_APPROX(res, square + m1 * m2.transpose());
|
||||
|
||||
@@ -35,6 +35,8 @@ void test_product_large()
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST_1( product(MatrixXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_2( product(MatrixXd(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_2( product(MatrixXd(internal::random<int>(1,10), internal::random<int>(1,10))) );
|
||||
|
||||
CALL_SUBTEST_3( product(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_4( product(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2), internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))) );
|
||||
CALL_SUBTEST_5( product(Matrix<float,Dynamic,Dynamic,RowMajor>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
|
||||
Reference in New Issue
Block a user