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

Block matrices as lvalue

Tags: None
(comma "," separated)
normvcr
Registered Member
Posts
12
Karma
0
OS

Block matrices as lvalue

Mon Jun 04, 2012 7:02 am
I know that
Code: Select all
VectorXd a(3);
VectorXd b(10);
b.head(3) = a;

sets the first 3 elements of b to the vector a.
However, supose, instead, that I have a function, f,
which sets the first 3 elements of a vector:
Code: Select all
void f( VectorXd& vec )
{
  vec(0) = 10;
  vec(1) = 20;
  vec(2) = 30;
}

The following does not compile
Code: Select all
  f( b.head(3) )

Do I need to construct a 3-vector, pass it to f,
and then copy the result into b.head(3)? In many
matrix libraries, a block matric may be treated as
any othe matrix, but it seems not in Eigen.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
normvcr
Registered Member
Posts
12
Karma
0
OS

Re: Block matrices as lvalue

Mon Jun 04, 2012 7:27 pm
ggael wrote:See this page of the doc: http://eigen.tuxfamily.org/dox-devel/To ... Types.html

Thanks. Great reference, and essesntial to understand for using Eigen more fully.

In my case, I will need to do a further hack to make things work, since
my function is actually a virtual member function of a class, and, so, cannot be templatized.
I suppose I will need to replace the virtual mechanism by having a new template paramaeter to
the class for the derived type (as Eigen does), and set a pointer to the derived type in
the constructor.

I am new at Eigen. I hope this is all worth it ... :-)


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell