2
votes

I'm a neophyte of C++ programmation. I have to implement a program witch calculates the pseudoinverse of a matrix. As the Eigen tutorial suggests, I have written a code like this:

    #include <stdio.h>
    #include <stdlib.h>
    #include <Core>
    #include <iostream>
    #include <Eigen/Dense>
    #include <Eigen/SVD>
    #include <Eigen/Eigen>
    using namespace Eigen;
    using namespace std;



    void pinv(MatrixXf& pinvmat)
     {
    ei_assert(m_isInitialized && "SVD is not initialized.");
   double  pinvtoler=1.e-6;                       // choose tolerance 
    SingularValuesType m_sigma_inv=m_sigma;
    for ( long i=0; i<m_workMatrix.cols(); ++i) {
    if ( m_sigma(i) > pinvtoler )
     m_sigma_inv(i)=1.0/m_sigma(i);
   else m_sigma_inv(i)=0;
   }
    pinvmat = (m_matV*m_sigma_inv.asDiagonal()*m_matU.transpose());


   }

    int main()
   {

    MatrixXf A(3,2);
    A<<1,2,3,4,5,6;
    pinv(A);
    cout << "pinv =" << endl << A << endl;
    return 0;
   }

If I try to compile it I'll get the errors:

tut_eigen/pinv.cpp: In function ‘void pinv(Eigen::MatrixXf&)’:
tut_eigen/pinv.cpp:18:14: error: ‘m_isInitialized’ was not declared in this scope
tut_eigen/pinv.cpp:18:58: error: ‘ei_assert’ was not declared in this scope
tut_eigen/pinv.cpp:20:4: error: ‘SingularValuesType’ was not declared in this scope
tut_eigen/pinv.cpp:20:23: error: expected ‘;’ before ‘m_sigma_inv’
tut_eigen/pinv.cpp:21:22: error: ‘m_workMatrix’ was not declared in this scope
tut_eigen/pinv.cpp:22:19: error: ‘m_sigma’ was not declared in this scope
tut_eigen/pinv.cpp:23:19: error: ‘m_sigma_inv’ was not declared in this scope
tut_eigen/pinv.cpp:24:22: error: ‘m_sigma_inv’ was not declared in this scope
tut_eigen/pinv.cpp:26:15: error: ‘m_matV’ was not declared in this scope
tut_eigen/pinv.cpp:26:22: error: ‘m_sigma_inv’ was not declared in this scope
tut_eigen/pinv.cpp:26:47: error: ‘m_matU’ was not declared in this scope

Why?? They are not declared in SVD file?

1
Using the m_ prefix on variables are typically used for class member variables. Some of these variables (like m_sigma) are not declared anywhere.Some programmer dude
Where are m_sigma , m_sigma_inv, m_isInitialized etc, declared?Desert Ice

1 Answers

2
votes

I suspect you talk about this "tutorial" which isn't so much a tutorial but an FAQ assuming you know a bit about the library already (it would be helpful if you link to your sources of information, BTW).

What this says is that you can add the pinv() method to the SVD "from the outside". I assume they mean that you can derive from SVD and provide the pinv() method in your derived class. Just typing the function somewhere doesn't give the compiler the necessary context to determine where referenced names are located.