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