c++ - How to access/write a matrix in a function using Eigen? -


I am trying to write a function using Eigen which makes a diagonal matrix slightly different from normal. When the element of the diagonal is zero (or relatively close to zero), then it should be set to zero for diagonal element, but otherwise the value should be 1 / (this element). I tried to write a function which receives the diagonal matrix, which I want to reverse (this is actually a nx1 matrix, hence the name) and the second pointer, where I have to put the result:

  template & lt; Typename m1, typename m2 & gt; Void invertSingularValues ​​(Eigen :: EigenBase & lt; m1 & gt; sing_val_vector, Eigen :: EigenBase & lt; m2 & gt; & amp; res) {for (int i = 0; i < sing_val_vector.rows (); i ++) res (i, i) = (sing_val_vector [i] & lt; 0.0000001 0: 1 / sing_val_vector [i]); };   

It seems that I can not access the elements of the matrix using (i, j) or [i] because I get these errors:

< P> No match for an operator [] A ???? (Operant types are: EEGEN :: Egenbage & gt; another ?????? ??????) Ridge (I, I) = (Singing_Wall_Vector [i] & lt; 0.0000001? 0: 1 / Sing_val_vector [i]);

There is no match for any operator [] A ???? (Operand types are: EEGEN :: Eugenebj> one more ????) int ()) (i, i) = (sing_val_vector [i] & lt; 0.0000001 0: 1 / sing_val_vector [i]);

There is no one to call to call (Egene :: EGNbS & gt;) (int & amp ;, int & amp;) ??? (I, i) = (sing_val_vector [i] & lt; 0.0000001? 0: 1 / sing_val_vector [i]);

When I call the function like this:

  invertSingularValues ​​(S.data, S_inv);   

SDATA and SINV EEGEN MATRIX are I. What can I do?

As the compiler says, you can not race (i, i) eigenbase type because eigenbase This functionality is not defined in < / Li>

To ignore any code optimization, something similar will work:

  template & lt; Typename m1, typename m2 & gt; Void invertSingularValues ​​(Eigen :: MatrixBase & lt; m1 & gt; sing_val_vector, Eigen :: MatrixBase & lt; m2 & gt; & amp; res) {for (int i (0); i & lt ; sing_val_vector.rows (); i ++) for (int j 0); j & lt; Sing_val_vector.cols (); j ++) res (i, j) = sing_val_vector (i, j) & lt; 1e-07? 0.0: 1.0 / singing_value_vector (I, J); };    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -