c++ - 将 Boost 累加器与 Eigen::Vector 类型一起使用

标签 c++ boost eigen boost-accumulators

我在将 Eigen::VectorXd 类型与 Boost 累加器库结合使用时遇到了一些问题:

#include <iostream>
#include <Eigen/Core>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/mean.hpp>

using namespace boost::accumulators;
using namespace Eigen;

int main()
{
   Vector2f a(1.0, 2.0), b(3.0, 10.0);

   accumulator_set<Vector2f, stats<tag::mean> > acc(Vector2f::Zero());

   acc(a);
   acc(b);

   std::cout << mean(acc) << std::endl;
   std::cout << ((a+b)/2.0) << std::endl;

   return 0;
}

在我的系统上这会产生:

4.41629e-39
0
2
6

因此,虽然直接计算很好(特征向量支持所有常用的数值运算符),但 Boost 累加器在运行时会失败而不会出现错误。

最佳答案

用户定义类型需要特化 std::numeric_limits。 见https://svn.boost.org/trac/boost/ticket/5491

关于c++ - 将 Boost 累加器与 Eigen::Vector 类型一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7908982/

相关文章:

c++ - QComboBox 数组访问

c++ - boost::filesystem::exists 在带有 boost v1.75 的 CentOS 8 docker 上抛出操作不允许异常

c++ - map 上的 find_if 问题

c++ - 从模板类创建对象时出错

C++:重载 != When == 重载

c++ - 不同平台的相同源的二进制大小如何变化

c++ - 尝试用对象实现多态

c++ - 如何确保在动态库文件中使用静态链接的 Boost

Numpy vs Eigen vs Xtensor 线性代数基准奇数

c++ - 使用 C++ 编写的算法实时处理数据