c++ - Boost::uBLAS 与 Eigen

标签 c++ boost eigen

我几乎所有的数学线性代数工作都习惯使用 Eigen。 最近,我发现 Boost 还提供了一个 C++ 模板类库,它提供了 Basic Linear Algebra Library ( Boost::uBLAS )。这让我想知道我是否可以仅基于 boost 完成我的所有工作,因为它已经是我代码的主要库。

仔细观察两者并没有真正让我更清楚地区分它们:

  • boost::uBLAS:

uBLAS provides templated C++ classes for dense, unit and sparse vectors, dense, identity, triangular, banded, symmetric, hermitian and sparse matrices. Views into vectors and matrices can be constructed via ranges, slices, adaptor classes and indirect arrays. The library covers the usual basic linear algebra operations on vectors and matrices: reductions like different norms, addition and subtraction of vectors and matrices and multiplication with a scalar, inner and outer products of vectors, matrix vector and matrix matrix products and triangular solver.

...

  • Eigen :

It supports all matrix sizes, from small fixed-size matrices to arbitrarily large dense matrices, and even sparse matrices.

It supports all standard numeric types, including std::complex, integers, and is easily extensible to custom numeric types.

It supports various matrix decompositions and geometry features.

Its ecosystem of unsupported modules provides many specialized features such as non-linear optimization, matrix functions, a polynomial solver, FFT, and much more.

...

有没有人对它们的主要区别有更好的了解,我们可以根据什么在它们之间进行选择?

最佳答案

我正在重写一个从 boost::uBLAS 到 Eigen 的重要项目。这是商业环境中的生产代码。我是 2006 年选择 uBLAS 的人,现在建议更改为 Eigen。

uBLAS 导致编译器执行的实际矢量化非常少。我可以查看大源文件的汇编输出,编译为 amd64 架构,使用 SSE,使用 float 类型,但找不到单个 ***ps 指令(addps、mulps、subps、4 路压缩单精度 float 指令)并且只有 ***ss 指令(addss,...,标量单精度)。

使用 Eigen,编写库以确保 vector 指令结果。

Eigen 的功能非常齐全。有很多矩阵分解和求解器。在 boost::uBLAS 中,LU 分解是一个未记录的附加组件,是一段贡献的代码。 Eigen 添加了 3D 几何,例如旋转和四元数,而不是 uBLAS。

uBLAS 在最基本的操作上稍微更完整。 Eigen 缺少一些东西,比如投影(使用另一个矩阵索引一个矩阵),而 uBLAS 有。对于两者都具有的特征,Eigen 更简洁,导致表达式更易于阅读。

然后,uBLAS 就完全过时了。我不明白在 2016/2017 年有人怎么看待它。阅读常见问题解答:

Q: Should I use uBLAS for new projects? A: At the time of writing (09/2012) there are a lot of good matrix libraries available, e.g., MTL4, armadillo, eigen. uBLAS offers a stable, well tested set of vector and matrix classes, the typical operations for linear algebra and solvers for triangular systems of equations. uBLAS offers dense, structured and sparse matrices - all using similar interfaces. And finally uBLAS offers good (but not outstanding) performance. On the other side, the last major improvement of uBLAS was in 2008 and no significant change was committed since 2009. So one should ask himself some questions to aid the decision: Availability? uBLAS is part of boost and thus available in many environments. Easy to use? uBLAS is easy to use for simple things, but needs decent C++ knowledge when you leave the path. Performance? There are faster alternatives. Cutting edge? uBLAS is more than 10 years old and missed all new stuff from C++11.

关于c++ - Boost::uBLAS 与 Eigen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37221040/

相关文章:

c++ - 使用 C++ 在 R 中乘以复杂矩阵

c++ - MKL 不适用于使用 Eigen 和 OpenMP 的 C++ 代码

c++ - BFS 迷宫帮助 C++

c++ - 将文件数据分配给结构数组

c++ - 在线程中使用 boost::asio::deadline_timer

c++ - 编译boost c++代码错误

c++ - 如何将 boost::geometry::rtree 与 glm::vec3 一起用作自定义点类型?

c++ - Eigen 广播比较

c++ - 多维动态矩阵如何创建一个?

c++ - 将 CARingBuffer 添加到项目中