[eigen] following up on dynamic allocation
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: [eigen] following up on dynamic allocation
• From: marco stamazza <giunghi@xxxxxxxxx>
• Date: Sun, 20 May 2018 19:29:28 +0800
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=XjSDbgW7rCi7ycmuS8fp97bJTWn1NmoTF5w7S4f9L+I=; b=AXs+reMa1k7rCas9R0SD4jCehs1JmjiMB6x5K3CredwVvGzg1Yi5xeS8vwFie2Z7fp BpkQmIMOvBlu8hnVIIanQJmSFNadKe2FgN/2keBbzi3mLmxQgRKQv+g+KJHjENuiA+gj rmSa5qQwdqeQ+WRhzd777x/R8H0vUb+RUsk/ARX2I1+JiHOKCiLlI4bOrjSfnL868TSV BsuaQq95mhHSmsmNPxLlokOJkDtkTVy399nsyec0EyC3wh8DVyWgeXsHD+T3A+29AVvY nsb4uF0OrqyiinPYmRbw3y+EpmKA5IPKrW/dQHMu4lM6X3kHHjTyxGpETTUtOORqULet RjYA==

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/