简体   繁体   English

Boost :: uBLAS vs Eigen

[英]Boost::uBLAS vs Eigen

I am used to Eigen for almost all my mathematical linear algebra work. 对于几乎所有我的数学线性代数工作,我都习惯了Eigen。 Recently, I have discovered that Boost also provides a C++ template class library that provides Basic Linear Algebra Library ( Boost::uBLAS ). 最近,我发现Boost还提供了一个C ++模板类库,它提供了基本线性代数库( Boost :: uBLAS )。 This got me wondering if I can get all my work based only on boost as it is already a major library for my code. 这让我想知道我是否可以仅使用boost来完成我的所有工作,因为它已经是我的代码的主要库。

A closer look at both didn't really got me a clearer distinction between them: 仔细看看两者并没有让我更清楚地区分它们:

  • Boost::uBLAS : Boost :: uBLAS:

uBLAS provides templated C++ classes for dense, unit and sparse vectors, dense, identity, triangular, banded, symmetric, hermitian and sparse matrices. uBLAS为密集,单位和稀疏向量,密集,同一性,三角形,带状,对称,埃尔米特和稀疏矩阵提供模板化C ++类。 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. 它支持所有标准数字类型,包括std :: complex,整数,并且可以轻松扩展为自定义数字类型。

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. 其不受支持的模块生态系统提供了许多专业功能,如非线性优化,矩阵函数,多项式求解器,FFT等等。

... ...

Does anyone have a better idea about their key differences and on which basis can we choose between them? 有没有人对他们的关键差异有更好的了解,我们可以在哪些基础上做出选择?

I just did a time complexity comparison between boost and eigen for fairly trivial matrix computations. 我只是对相当平凡的矩阵计算进行了增强和特征之间的时间复杂度比较。 These results, limited as they are, seem to denote that boost is a much better alternative. 这些结果虽然有限,但似乎表明增强是一种更好的选择。 I had an FEM code which does the pre-processing parts (setting up the element matrices and stitching them together). 我有一个FEM代码,它执行预处理部分(设置元素矩阵并将它们拼接在一起)。 So naturally, this would involve a lot of memory allocations. 很自然地,这将涉及大量的内存分配。

在此输入图像描述

I wrote identical pieces of codes with Boost and Eigen on C++ (gcc 5.4.0, ubuntu 16.04, Intel i3 Quad Core, 2.40GHz, RAM : 4Gb) and ran them separately for varying node sizes (N) and calculated time using the linux cl-utility. 我在C ++(gcc 5.4.0,ubuntu 16.04,Intel i3四核,2.40GHz,RAM:4Gb)上使用Boost和Eigen编写了相同的代码片段,并针对不同的节点大小(N)分别运行它们并使用linux计算时间CL-工具。 As far as I'm concerned, I have decided to proceed with my code in Boost. 就我而言,我决定继续使用Boost中的代码。

I'm rewriting a substantial project from boost::uBLAS to Eigen. 我正在重写一个从boost :: uBLAS到Eigen的实质项目。 This is production code in a commercial environment. 这是商业环境中的生产代码。 I was the one who chose uBLAS back in 2006 and now recommended the change to Eigen. 我是2006年选择uBLAS的人,现在推荐改为Eigen。

uBLAS results in very little actual vectorization performed by the compiler. uBLAS导致编译器执行的实际矢量化非常少。 I can look at the assembly output of big source files, compiled to amd64 architecture, with SSE, using the float type, and not find a single ***ps instruction (addps, mulps, subps, 4 way packed single-precision floating point instructions) and only ***ss instructions (addss, ..., scalar single-precision). 我可以看看大源文件的汇编输出,编译为amd64架构,使用SSE,使用float类型,而不是找到单个*** ps指令(addps,mulps,subps,4路打包单精度浮点说明)和*** ss指令(addss,...,标量单精度)。

With Eigen, the library is written to make sure that vector instructions result. 使用Eigen,编写库以确保导致向量指令。

Eigen is very feature complete. Eigen非常完整。 Has lots of matrix factorizations and solvers. 有很多矩阵因子分解和求解器。 In boost::uBLAS the LU factorization is an undocumented add-on, a piece of contributed code. 在boost :: uBLAS中,LU分解是一个未记录的附加组件,是一段贡献代码。 Eigen has additions for 3D geometry, such as rotations and quaternions, not uBLAS. Eigen增加了3D几何体,例如旋转和四元数,而不是uBLAS。

uBLAS is slightly more complete on the most basic operations. uBLAS在最基本的操作上略胜一筹。 Eigen lacks some things, such as projection (indexing a matrix using another matrix), while uBLAS has it. Eigen缺少一些东西,比如投影(使用另一个矩阵索引矩阵),而uBLAS则有。 For features that both have, Eigen is more terse, resulting in expressions that are easier to read. 对于两者都具有的功能,Eigen更简洁,导致表达更容易阅读。

Then, uBLAS is completely stale. 然后,uBLAS完全陈旧。 I can't understand how anyone considers it in 2016/2017. 我无法理解2016/2017年度有人如何看待它。 Read the FAQ: 阅读常见问题:

Q: Should I use uBLAS for new projects? 问:我应该将uBLAS用于新项目吗? A: At the time of writing (09/2012) there are a lot of good matrix libraries available, eg, MTL4, armadillo, eigen. 答:在撰写本文时(09/2012),有许多可用的良好矩阵库,例如MTL4,犰狳,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提供了一组稳定的,经过良好测试的矢量和矩阵类,这是线性代数和三角方程组求解器的典型操作。 uBLAS offers dense, structured and sparse matrices - all using similar interfaces. uBLAS提供密集,结构化和稀疏的矩阵 - 所有这些都使用类似的接口。 And finally uBLAS offers good (but not outstanding) performance. 最后uBLAS提供了良好(但并不突出)的性能。 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的最后一次重大改进是在2008年,自2009年以来没有发生重大变化。因此,应该问自己一些问题来帮助做出决定:可用性? uBLAS is part of boost and thus available in many environments. uBLAS是提升的一部分,因此可用于许多环境。 Easy to use? 易于使用? uBLAS is easy to use for simple things, but needs decent C++ knowledge when you leave the path. uBLAS易于用于简单的事情,但是当你离开路径时需要体面的C ++知识。 Performance? 性能? There are faster alternatives. 有更快的选择。 Cutting edge? 前沿? uBLAS is more than 10 years old and missed all new stuff from C++11. uBLAS已经超过10年了,并且错过了C ++ 11中的所有新东西。

Choose Eigen if you care the performance and performance gain introduced by expression templates, and choose uBlas if you only want to learn expression templates. 如果您关心表达式模板引入的性能和性能增益,请选择Eigen,如果您只想学习表达式模板,请选择uBlas。

http://eigen.tuxfamily.org/index.php?title=Benchmark http://eigen.tuxfamily.org/index.php?title=Benchmark

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM