[eigen] following up on dynamic allocation

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi Eigen developers,
I want to initialize a row major matrix and fill it with a transposed.

I am confused about how to do it
Eigen::MatrixXd mktrasp(Eigen::MatrixXd X const int n, const int p){
  Eigen::Matrix<double, p, n, RowMajor> T;
  T = X.transpose();
  return T;
}

Gives the compiler errors

error: 'p' cannot appear in a constant-_expression_
error: 'n' cannot appear in a constant-_expression_

I imagine this happens because n and p are not known at compile time.

So I tried this solution

Eigen::MatrixXd mktrasp(Eigen::MatrixXd X, const int n, const int p){
  Eigen::Matrix<double, Dynamic, Dynamic, RowMajor> T(p, n);
  T = X.transpose();
  return T;
}

This works but I have completely lost the plot. Is T a dynamic matrix or fixed size now? Is it safe to do this? Can you suggest a better approach?

I am not much of a programmer. So apologies if the question has a trivial answer.

Thanks, Marco

--
"Anyone who lives within their means suffers from a lack of imagination."


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/