1*bf2c3715SXin Li #include <Eigen/Dense> 2*bf2c3715SXin Li #include <iostream> 3*bf2c3715SXin Li 4*bf2c3715SXin Li using namespace Eigen; 5*bf2c3715SXin Li 6*bf2c3715SXin Li template <typename Derived1, typename Derived2> copyUpperTriangularPart(MatrixBase<Derived1> & dst,const MatrixBase<Derived2> & src)7*bf2c3715SXin Livoid copyUpperTriangularPart(MatrixBase<Derived1>& dst, const MatrixBase<Derived2>& src) 8*bf2c3715SXin Li { 9*bf2c3715SXin Li /* Note the 'template' keywords in the following line! */ 10*bf2c3715SXin Li dst.template triangularView<Upper>() = src.template triangularView<Upper>(); 11*bf2c3715SXin Li } 12*bf2c3715SXin Li main()13*bf2c3715SXin Liint main() 14*bf2c3715SXin Li { 15*bf2c3715SXin Li MatrixXi m1 = MatrixXi::Ones(5,5); 16*bf2c3715SXin Li MatrixXi m2 = MatrixXi::Random(4,4); 17*bf2c3715SXin Li std::cout << "m2 before copy:" << std::endl; 18*bf2c3715SXin Li std::cout << m2 << std::endl << std::endl; 19*bf2c3715SXin Li copyUpperTriangularPart(m2, m1.topLeftCorner(4,4)); 20*bf2c3715SXin Li std::cout << "m2 after copy:" << std::endl; 21*bf2c3715SXin Li std::cout << m2 << std::endl << std::endl; 22*bf2c3715SXin Li } 23