This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Resizing a block expression

Tags: None
(comma "," separated)
dandelin
Registered Member
Posts
6
Karma
0

Resizing a block expression

Thu Jan 08, 2015 12:47 pm
I frequently find myself attempting to resize a matrix block before copying it to a fixed-size matrix or using it in a function call. Something like

Matrix<double, 9, Dynamic> A;
Matrix3d B = A.col(0).conservativeResize(3, 3);

This is not allowed so my current work-around is to make B a dynamic matrix:

MatrixXd B = A.col(0);
B.conservativeResize(3, 3);

If I really want a fixed-size matrix, I have make another copy,

Matrix3d C = B;

Is there a better way to accomplish this?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Resizing a block expression

Thu Jan 08, 2015 8:38 pm
What you want is to "reshape" an expression, not resizing it. You can workaround using Map on the lhs or rhs, e.g.:
Code: Select all
Matrix3d B;
Map<VectorXd>(B.data(), 9) = A.col(0);


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]