1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2019 Gael Guennebaud <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li
10*bf2c3715SXin Li #define TEST_ENABLE_TEMPORARY_TRACKING
11*bf2c3715SXin Li
12*bf2c3715SXin Li #include "main.h"
13*bf2c3715SXin Li
14*bf2c3715SXin Li typedef NestByValue<MatrixXd> CpyMatrixXd;
15*bf2c3715SXin Li typedef CwiseBinaryOp<internal::scalar_sum_op<double,double>,const CpyMatrixXd,const CpyMatrixXd> XprType;
16*bf2c3715SXin Li
get_xpr_with_temps(const MatrixXd & a)17*bf2c3715SXin Li XprType get_xpr_with_temps(const MatrixXd& a)
18*bf2c3715SXin Li {
19*bf2c3715SXin Li MatrixXd t1 = a.rowwise().reverse();
20*bf2c3715SXin Li MatrixXd t2 = a+a;
21*bf2c3715SXin Li return t1.nestByValue() + t2.nestByValue();
22*bf2c3715SXin Li }
23*bf2c3715SXin Li
EIGEN_DECLARE_TEST(nestbyvalue)24*bf2c3715SXin Li EIGEN_DECLARE_TEST(nestbyvalue)
25*bf2c3715SXin Li {
26*bf2c3715SXin Li for(int i = 0; i < g_repeat; i++) {
27*bf2c3715SXin Li Index rows = internal::random<Index>(1,EIGEN_TEST_MAX_SIZE);
28*bf2c3715SXin Li Index cols = internal::random<Index>(1,EIGEN_TEST_MAX_SIZE);
29*bf2c3715SXin Li MatrixXd a = MatrixXd(rows,cols);
30*bf2c3715SXin Li nb_temporaries = 0;
31*bf2c3715SXin Li XprType x = get_xpr_with_temps(a);
32*bf2c3715SXin Li VERIFY_IS_EQUAL(nb_temporaries,6);
33*bf2c3715SXin Li MatrixXd b = x;
34*bf2c3715SXin Li VERIFY_IS_EQUAL(nb_temporaries,6+1);
35*bf2c3715SXin Li VERIFY_IS_APPROX(b, a.rowwise().reverse().eval() + (a+a).eval());
36*bf2c3715SXin Li }
37*bf2c3715SXin Li }
38