xref: /aosp_15_r20/external/eigen/doc/examples/TemplateKeyword_simple.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li #include <Eigen/Dense>
2*bf2c3715SXin Li #include <iostream>
3*bf2c3715SXin Li 
4*bf2c3715SXin Li using namespace Eigen;
5*bf2c3715SXin Li 
copyUpperTriangularPart(MatrixXf & dst,const MatrixXf & src)6*bf2c3715SXin Li void copyUpperTriangularPart(MatrixXf& dst, const MatrixXf& src)
7*bf2c3715SXin Li {
8*bf2c3715SXin Li   dst.triangularView<Upper>() = src.triangularView<Upper>();
9*bf2c3715SXin Li }
10*bf2c3715SXin Li 
main()11*bf2c3715SXin Li int main()
12*bf2c3715SXin Li {
13*bf2c3715SXin Li   MatrixXf m1 = MatrixXf::Ones(4,4);
14*bf2c3715SXin Li   MatrixXf m2 = MatrixXf::Random(4,4);
15*bf2c3715SXin Li   std::cout << "m2 before copy:" << std::endl;
16*bf2c3715SXin Li   std::cout << m2 << std::endl << std::endl;
17*bf2c3715SXin Li   copyUpperTriangularPart(m2, m1);
18*bf2c3715SXin Li   std::cout << "m2 after copy:" << std::endl;
19*bf2c3715SXin Li   std::cout << m2 << std::endl << std::endl;
20*bf2c3715SXin Li }
21