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

Compile problems with mixing Array and RowVector types

Tags: None
(comma "," separated)
raman
Registered Member
Posts
8
Karma
0
OS
Hi all,
I'm testing some code on the latest version of eigen (3.1.2). I expected that "*=" operators would work with array types but it sometimes compiles and sometimes doesn't as shown in the examples below.
Code: Select all
#include <Eigen/Dense>
#include <iostream>
using namespace Eigen;

int main()
{
   ArrayXd a(3, 1);
   RowVectorXd v(3, 1); // everything compiles if we use VectorXd v(3, 1)
   
   a << 1, 2, 3;
   v << 4, 5, 6;
   
   a = v;
   a = v.array(); // compiler error
   v = a;
   v = a.matrix(); // compiler error
   
   a.array() *= a.array();
   a.array() *= v.array(); // compiler error
   v.array() *= a.array(); // compiler error
   v.array() *= v.array();
   
   a.array() *= a.array()*a.array();
   a.array() *= a.array()*v.array();
   a.array() *= v.array()*a.array();
   a.array() *= v.array()*v.array();
   
   v.array() *= a.array()*a.array(); // compiler error
   v.array() *= a.array()*v.array(); // compiler error
   v.array() *= v.array()*a.array();
   v.array() *= v.array()*v.array();
}


If I use VectorXd instead of RowVectorXd, everything compiles fine. Is this a limitation because RowVectorXd is 1 x Dynamic while ArrayXd is Dynamic x 1? I general I have not had problems assigning a RowVectorXd to a VectorXd or vice versa.

Thanks!
Raman
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
The issue is indeed that ArrayXd is Dynamic x 1. Assigning a row vector to a column vector is allowed though (that's the only exception). That's why a = v; and v = a; work. However, I agree that a = v.array(); and v = a.matrix(); should compile!!
raman
Registered Member
Posts
8
Karma
0
OS
Thanks for the clarification! I'm using row vectors in all my code and it'll be a mess to change them to column vectors. Unfortunately there isn't an Array type of size 1 x Dynamic. Actually the code compiles if I define "a" as ArrayXXd(1, 3), so I guess that's a workaround:
Code: Select all
   ArrayXXd a(1, 3);
   RowVectorXd v(3);

But surprisingly it also works if a is defined as ArrayXXd(3, 1).
Thanks,
Raman
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You can define a 1D row array yourself:

typedef Array<double,1,Dynamic> RowArrayXd;


Bookmarks



Who is online

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