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

Assign a result of a logic operation between Eigen/Dense arr

Tags: None
(comma "," separated)
L
Registered Member
Posts
7
Karma
0
Hi Friends,

I am dealing with <Eigen> library.

I can cout<<(PointsSorted.col(0).array()<0)<<endl;
The output is:

1 1 1 1 1 0 0 0 0 0

But how can I assign this output to a std::vector. I have a slow solution to do this by a pointer.I am wondering if there is a faster way like:

vector<int> v;
v.push_back((PointsSorted.col(0).array()<0));

But it does not work by this way. What's the problem? Does anyone know the type of (PointsSorted.col(0).array()<0)?

L
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
For instance:
Code: Select all
int n = PointsSorted.rows()
v.resize(n);
VectorXi::Map(v.data(), n) = (PointsSorted.col(0).array()<0).cast<int>();
L
Registered Member
Posts
7
Karma
0
I tried this codes:

vector <int> v;
int n = PointsSorted.rows();
v.resize(n);
VectorXi::Map(v.data(), n) = (PointsSorted.col(0).array()<0).cast<int>();

and error message as:
"error: no matching function for call to 'Map'
VectorXi::Map(v.data(), n) = (PointsSorted.col(0).array()<0).cast<int>();"

It seems that Map is to store std:: array into Eigen:: object. I need the opposite way.

Thanks,

L
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This must work. Here is a self-contained working example:
Code: Select all
#include <iostream>
#include <vector>
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;

int main()
{
  MatrixXd points = MatrixXd::Random(6,6);
  int n = points.rows();
  std::vector<int> v(n);
  VectorXi::Map(v.data(), n) = (points.col(0).array()<0).cast<int>();
  for(int i=0; i<n; ++i) cout << v[i];
  cout << endl;
}
L
Registered Member
Posts
7
Karma
0
No, same error:" no matching function for call to 'Map'

The documentation shows Map is under the class "Eigen::", not "VectorXi::",
and the format is :
class Eigen::Map< PlainObjectType, MapOptions, StrideType >

I am confused....

L
L
Registered Member
Posts
7
Karma
0
It works now. My bad.

Thanks for the help,

L


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft