You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
682 B

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