xref: /aosp_15_r20/external/eigen/doc/examples/function_taking_ref.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li #include <iostream>
2*bf2c3715SXin Li #include <Eigen/SVD>
3*bf2c3715SXin Li using namespace Eigen;
4*bf2c3715SXin Li using namespace std;
5*bf2c3715SXin Li 
inv_cond(const Ref<const MatrixXf> & a)6*bf2c3715SXin Li float inv_cond(const Ref<const MatrixXf>& a)
7*bf2c3715SXin Li {
8*bf2c3715SXin Li   const VectorXf sing_vals = a.jacobiSvd().singularValues();
9*bf2c3715SXin Li   return sing_vals(sing_vals.size()-1) / sing_vals(0);
10*bf2c3715SXin Li }
11*bf2c3715SXin Li 
main()12*bf2c3715SXin Li int main()
13*bf2c3715SXin Li {
14*bf2c3715SXin Li   Matrix4f m = Matrix4f::Random();
15*bf2c3715SXin Li   cout << "matrix m:" << endl << m << endl << endl;
16*bf2c3715SXin Li   cout << "inv_cond(m):          " << inv_cond(m)                      << endl;
17*bf2c3715SXin Li   cout << "inv_cond(m(1:3,1:3)): " << inv_cond(m.topLeftCorner(3,3))   << endl;
18*bf2c3715SXin Li   cout << "inv_cond(m+I):        " << inv_cond(m+Matrix4f::Identity()) << endl;
19*bf2c3715SXin Li }
20