ref.cpp revision 615d816d068b4d0f5e8df601930b5f160bf7eda1
17faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// This file is part of Eigen, a lightweight C++ template library 27faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// for linear algebra. 37faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// 47faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// Copyright (C) 20013 Gael Guennebaud <gael.guennebaud@inria.fr> 57faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// 67faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// This Source Code Form is subject to the terms of the Mozilla 77faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// Public License v. 2.0. If a copy of the MPL was not distributed 87faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 97faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 107faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// This unit test cannot be easily written to work with EIGEN_DEFAULT_TO_ROW_MAJOR 117faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR 127faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez#undef EIGEN_DEFAULT_TO_ROW_MAJOR 137faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez#endif 147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 157faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezstatic int nb_temporaries; 167faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 177faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezinline void on_temporary_creation(int) { 187faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez // here's a great place to set a breakpoint when debugging failures in this test! 197faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez nb_temporaries++; 207faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 217faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 227faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 237faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez#define EIGEN_DENSE_STORAGE_CTOR_PLUGIN { on_temporary_creation(size); } 247faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 257faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez#include "main.h" 267faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 277faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez#define VERIFY_EVALUATION_COUNT(XPR,N) {\ 287faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez nb_temporaries = 0; \ 297faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez XPR; \ 307faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez if(nb_temporaries!=N) std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; \ 317faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY( (#XPR) && nb_temporaries==N ); \ 327faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez } 337faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 347faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 357faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// test Ref.h 367faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 377faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename MatrixType> void ref_matrix(const MatrixType& m) 387faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{ 397faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename MatrixType::Index Index; 407faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename MatrixType::Scalar Scalar; 417faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename MatrixType::RealScalar RealScalar; 427faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Matrix<Scalar,Dynamic,Dynamic,MatrixType::Options> DynMatrixType; 437faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Matrix<RealScalar,Dynamic,Dynamic,MatrixType::Options> RealDynMatrixType; 447faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 457faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<MatrixType> RefMat; 467faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<DynMatrixType> RefDynMat; 477faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<const DynMatrixType> ConstRefDynMat; 487faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<RealDynMatrixType , 0, Stride<Dynamic,Dynamic> > RefRealMatWithStride; 497faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 507faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index rows = m.rows(), cols = m.cols(); 517faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 527faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez MatrixType m1 = MatrixType::Random(rows, cols), 537faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez m2 = m1; 547faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 557faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index i = internal::random<Index>(0,rows-1); 567faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index j = internal::random<Index>(0,cols-1); 577faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index brows = internal::random<Index>(1,rows-i); 587faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index bcols = internal::random<Index>(1,cols-j); 597faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 607faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefMat rm0 = m1; 617faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm0, m1); 627faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefDynMat rm1 = m1; 637faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm1, m1); 647faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefDynMat rm2 = m1.block(i,j,brows,bcols); 657faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm2, m1.block(i,j,brows,bcols)); 667faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rm2.setOnes(); 677faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez m2.block(i,j,brows,bcols).setOnes(); 687faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(m1, m2); 697faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 707faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez m2.block(i,j,brows,bcols).setRandom(); 717faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rm2 = m2.block(i,j,brows,bcols); 727faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(m1, m2); 737faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 747faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 757faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez ConstRefDynMat rm3 = m1.block(i,j,brows,bcols); 767faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez m1.block(i,j,brows,bcols) *= 2; 777faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez m2.block(i,j,brows,bcols) *= 2; 787faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm3, m2.block(i,j,brows,bcols)); 797faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefRealMatWithStride rm4 = m1.real(); 807faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm4, m2.real()); 817faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rm4.array() += 1; 827faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez m2.real().array() += 1; 837faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(m1, m2); 847faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 857faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 867faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename VectorType> void ref_vector(const VectorType& m) 877faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{ 887faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename VectorType::Index Index; 897faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename VectorType::Scalar Scalar; 907faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename VectorType::RealScalar RealScalar; 917faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Matrix<Scalar,Dynamic,1,VectorType::Options> DynMatrixType; 927faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> MatrixType; 937faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Matrix<RealScalar,Dynamic,1,VectorType::Options> RealDynMatrixType; 947faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 957faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<VectorType> RefMat; 967faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<DynMatrixType> RefDynMat; 977faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<const DynMatrixType> ConstRefDynMat; 987faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<RealDynMatrixType , 0, InnerStride<> > RefRealMatWithStride; 997faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef Ref<DynMatrixType , 0, InnerStride<> > RefMatWithStride; 1007faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1017faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index size = m.size(); 1027faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1037faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VectorType v1 = VectorType::Random(size), 1047faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez v2 = v1; 1057faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez MatrixType mat1 = MatrixType::Random(size,size), 1067faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez mat2 = mat1, 1077faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez mat3 = MatrixType::Random(size,size); 1087faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1097faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index i = internal::random<Index>(0,size-1); 1107faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez Index bsize = internal::random<Index>(1,size-i); 1117faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1127faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefMat rm0 = v1; 1137faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm0, v1); 1147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefDynMat rv1 = v1; 1157faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rv1, v1); 1167faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefDynMat rv2 = v1.segment(i,bsize); 1177faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rv2, v1.segment(i,bsize)); 1187faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rv2.setOnes(); 1197faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez v2.segment(i,bsize).setOnes(); 1207faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(v1, v2); 1217faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1227faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez v2.segment(i,bsize).setRandom(); 1237faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rv2 = v2.segment(i,bsize); 1247faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(v1, v2); 1257faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1267faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez ConstRefDynMat rm3 = v1.segment(i,bsize); 1277faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez v1.segment(i,bsize) *= 2; 1287faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez v2.segment(i,bsize) *= 2; 1297faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm3, v2.segment(i,bsize)); 1307faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1317faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefRealMatWithStride rm4 = v1.real(); 1327faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm4, v2.real()); 1337faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rm4.array() += 1; 1347faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez v2.real().array() += 1; 1357faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(v1, v2); 1367faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1377faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RefMatWithStride rm5 = mat1.row(i).transpose(); 1387faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(rm5, mat1.row(i).transpose()); 1397faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rm5.array() += 1; 1407faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez mat2.row(i).array() += 1; 1417faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_EQUAL(mat1, mat2); 1427faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez rm5.noalias() = rm4.transpose() * mat3; 1437faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez mat2.row(i) = v2.real().transpose() * mat3; 1447faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_IS_APPROX(mat1, mat2); 1457faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 1467faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1477faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename PlainObjectType> void check_const_correctness(const PlainObjectType&) 1487faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{ 1497faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez // verify that ref-to-const don't have LvalueBit 1507faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez typedef typename internal::add_const<PlainObjectType>::type ConstPlainObjectType; 1517faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY( !(internal::traits<Ref<ConstPlainObjectType> >::Flags & LvalueBit) ); 1527faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY( !(internal::traits<Ref<ConstPlainObjectType, Aligned> >::Flags & LvalueBit) ); 1537faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY( !(Ref<ConstPlainObjectType>::Flags & LvalueBit) ); 1547faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY( !(Ref<ConstPlainObjectType, Aligned>::Flags & LvalueBit) ); 1557faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 1567faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1577faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1587faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_1(Ref<VectorXf> a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1597faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1607faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_2(const Ref<const VectorXf>& a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1617faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1627faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_3(Ref<VectorXf,0,InnerStride<> > a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1637faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1647faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_4(const Ref<const VectorXf,0,InnerStride<> >& a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1657faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1667faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_5(Ref<MatrixXf,0,OuterStride<> > a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1677faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1687faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_6(const Ref<const MatrixXf,0,OuterStride<> >& a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1697faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename B> 1707faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezEIGEN_DONT_INLINE void call_ref_7(Ref<Matrix<float,Dynamic,3> > a, const B &b) { VERIFY_IS_EQUAL(a,b); } 1717faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1727faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezvoid call_ref() 1737faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{ 1747faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VectorXcf ca = VectorXcf::Random(10); 1757faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VectorXf a = VectorXf::Random(10); 1767faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RowVectorXf b = RowVectorXf::Random(10); 1777faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez MatrixXf A = MatrixXf::Random(10,10); 1787faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez RowVector3f c = RowVector3f::Random(); 1797faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez const VectorXf& ac(a); 1807faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VectorBlock<VectorXf> ab(a,0,3); 1817faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez const VectorBlock<VectorXf> abc(a,0,3); 1827faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1837faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1847faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_1(a,a), 0); 1857faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_1(b,b.transpose()), 0); 186615d816d068b4d0f5e8df601930b5f160bf7eda1Tim Murray// call_ref_1(ac,a<c); // does not compile because ac is const 1877faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_1(ab,ab), 0); 1887faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_1(a.head(4),a.head(4)), 0); 1897faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_1(abc,abc), 0); 1907faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_1(A.col(3),A.col(3)), 0); 191615d816d068b4d0f5e8df601930b5f160bf7eda1Tim Murray// call_ref_1(A.row(3),A.row(3)); // does not compile because innerstride!=1 1927faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_3(A.row(3),A.row(3).transpose()), 0); 1937faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_4(A.row(3),A.row(3).transpose()), 0); 194615d816d068b4d0f5e8df601930b5f160bf7eda1Tim Murray// call_ref_1(a+a, a+a); // does not compile for obvious reason 1957faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 1967faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez MatrixXf tmp = A*A.col(1); 1977faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(A*A.col(1), tmp), 1); // evaluated into a temp 1987faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(ac.head(5),ac.head(5)), 0); 1997faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(ac,ac), 0); 2007faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(a,a), 0); 2017faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(ab,ab), 0); 2027faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(a.head(4),a.head(4)), 0); 2037faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez tmp = a+a; 2047faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(a+a,tmp), 1); // evaluated into a temp 2057faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_2(ca.imag(),ca.imag()), 1); // evaluated into a temp 2067faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 2077faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_4(ac.head(5),ac.head(5)), 0); 2087faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez tmp = a+a; 2097faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_4(a+a,tmp), 1); // evaluated into a temp 2107faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_4(ca.imag(),ca.imag()), 0); 2117faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 2127faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_5(a,a), 0); 2137faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_5(a.head(3),a.head(3)), 0); 2147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_5(A,A), 0); 215615d816d068b4d0f5e8df601930b5f160bf7eda1Tim Murray// call_ref_5(A.transpose(),A.transpose()); // does not compile because storage order does not match 2167faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_5(A.block(1,1,2,2),A.block(1,1,2,2)), 0); 2177faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_5(b,b), 0); // storage order do not match, but this is a degenerate case that should work 2187faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_5(a.row(3),a.row(3)), 0); 2197faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 2207faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(a,a), 0); 2217faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(a.head(3),a.head(3)), 0); 2227faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(A.row(3),A.row(3)), 1); // evaluated into a temp thouth it could be avoided by viewing it as a 1xn matrix 2237faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez tmp = A+A; 2247faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(A+A,tmp), 1); // evaluated into a temp 2257faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(A,A), 0); 2267faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(A.transpose(),A.transpose()), 1); // evaluated into a temp because the storage orders do not match 2277faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_6(A.block(1,1,2,2),A.block(1,1,2,2)), 0); 2287faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 2297faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez VERIFY_EVALUATION_COUNT( call_ref_7(c,c), 0); 2307faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 2317faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 2327faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezvoid test_ref() 2337faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{ 2347faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez for(int i = 0; i < g_repeat; i++) { 2357faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_1( ref_vector(Matrix<float, 1, 1>()) ); 2367faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_1( check_const_correctness(Matrix<float, 1, 1>()) ); 2377faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_2( ref_vector(Vector4d()) ); 2387faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_2( check_const_correctness(Matrix4d()) ); 2397faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_3( ref_vector(Vector4cf()) ); 2407faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_4( ref_vector(VectorXcf(8)) ); 2417faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_5( ref_vector(VectorXi(12)) ); 2427faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_5( check_const_correctness(VectorXi(12)) ); 2437faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 2447faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_1( ref_matrix(Matrix<float, 1, 1>()) ); 2457faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_2( ref_matrix(Matrix4d()) ); 2467faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_1( ref_matrix(Matrix<float,3,5>()) ); 2477faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_4( ref_matrix(MatrixXcf(internal::random<int>(1,10),internal::random<int>(1,10))) ); 2487faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_4( ref_matrix(Matrix<std::complex<double>,10,15>()) ); 2497faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_5( ref_matrix(MatrixXi(internal::random<int>(1,10),internal::random<int>(1,10))) ); 2507faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez CALL_SUBTEST_6( call_ref() ); 2517faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez } 2527faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 253