[英]How can I use stl iterators with Eigen?
I am trying to use the Library Eigen in a project and I have to sort a vector.我正在尝试在项目中使用 Library Eigen,我必须对向量进行排序。 I tried to follow the documentation and it says that the library should work in the predictable way with the STL iterators and algorithms https://eigen.tuxfamily.org/dox-devel/group__TutorialSTL.html .
我尝试按照文档进行操作,它说该库应该以可预测的方式与 STL 迭代器和算法https://eigen.tuxfamily.org/dox-devel/group__TutorialSTL.7AFC35FDC70.8526 However when I try to run the following test code
但是,当我尝试运行以下测试代码时
#include <iostream>
#include <algorithm>
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Core>
int main()
{
Eigen::Array4i v = Eigen::Array4i::Random().abs();
std::cout << "Here is the initial vector v:\n" << v.transpose() << "\n";
std::sort(v.begin(), v.end());
std::cout << "Here is the sorted vector v:\n" << v.transpose() << "\n";
return 0;
}
I get the two following errors:我收到以下两个错误:
error: ‘Eigen::Array4i’ {aka ‘class Eigen::Array<int, 4, 1>’} has no member named ‘begin’
9 | std::sort(v.begin(), v.end());
| ^~~~~
error: ‘Eigen::Array4i’ {aka ‘class Eigen::Array<int, 4, 1>’} has no member named ‘end’
9 | std::sort(v.begin(), v.end());
I tested it with gcc 9.1.0 and 7.4.0 and my version of Eigen is 3.3.4.我用 gcc 9.1.0 和 7.4.0 对其进行了测试,我的 Eigen 版本是 3.3.4。 I am using Ubuntu 18.04 and the library is in the usual location /usr/include.
我正在使用 Ubuntu 18.04,该库位于通常的位置 /usr/include。 All the other functionality I tried seem to work properly.
我尝试过的所有其他功能似乎都可以正常工作。 Is it a well known bug, is it a compiler problem or is it a version problem?
这是一个众所周知的错误,是编译器问题还是版本问题?
If you don't want to wait for the release of Eigen 3.4, you can use this:如果你不想等待 Eigen 3.4 的发布,你可以使用这个:
std::sort(v.data(), v.data() + v.size());
The .data()
method can replace the missing .begin()
, but the .end()
method must be constructed manually. .data()
方法可以替换缺失的.begin()
,但.end()
方法必须手动构建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.