高性能 C++多维数组
我正在寻找有关 C++ 高性能多维数组库/类的建议。我真正需要的是:
动态分配数组的能力,其大小在运行时确定
访问和修改的能力单个数组值(快速)
能够使用简单的数组算术,例如
array1 = array2 + 2 * array3
< /p>维护良好的库
我遇到过各种库,包括:
Blitz++,它看起来正是我需要的,但看起来不太好维护良好(最新的稳定版本是 5 年前)
Boost,它不支持数组运算,并且与 Blitz++ 相比似乎相当慢。
Jonn Bowman 的 array.h 没有文档。
还有人对上述选项有任何其他建议或意见吗?
I am looking for advice regarding high performance multi-dimensional array libraries/classes for C++. What I really need is:
the ability to dynamically allocate arrays with a size determined at run-time
the ability to access and modify single array values (fast)
to be able to use simple array arithmetic such as
array1 = array2 + 2 * array3
a well-maintained library
I have come across various libraries, including:
Blitz++, which looks exactly what I need, but which doesn't seem very well maintained (latest stable release was 5 years ago)
Boost, which doesn't support array arithmetic, and appears to be a quite slow compared to say Blitz++.
Jonn Bowman's array.h which has no documentation.
Does anyone have any other suggestions or comments about the above options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
Eigen 维护得非常好(至少现在,有新版本每个月都会发布)并支持您需要的其他操作。
Eigen is extremely well-maintained (right now, at least, there are new versions coming out every month) and supports the other operations you need.
此处进行了一项广泛且相对较新的调查,包括基准。
我相信您可以通过将 Boost.UBlas 绑定到 LAPACK 或 Intel MKL 等底层数值库来加速 Boost.UBlas,但还没有这样做。
fwiw,最常出现的候选实现是 Boost.UBlas 和 MTL。根据我的经验,广泛采用更有可能促进持续的支持和发展。
There is a broad and relatively recent survey, including benchmarks, here.
I believe that you can speed up Boost.UBlas by binding it to underlying numerical libraries like LAPACK or Intel MKL, but have not done that.
fwiw, the implementations that seem to come up most often as candidates are Boost.UBlas and MTL. It's my experience that wide adoption is more likely to foster ongoing support and development.
Necomi 似乎提供了您想要的功能。
它支持任意多维数字,其维度可以在运行时固定,提供对单个元素的快速访问,同时还支持算术(除其他外)表达式。
Necomi seems to provide the features you would like.
It includes support for an arbitrary multi-dimensional numbers whose dimensions can be fixed at runtime, provides fast access to single elements, while also supporting arithmetic (among others) expressions.
还有另一个无耻的自我推销,
https://github.com/dwwork/FortCpp/
我已经在 GitHub 上发布了我个人对此问题的解决方案。
无论如何,我都不是 C++ 专家,但我想我至少应该把它扔掉。
Also another shameless self-promotion,
https://github.com/dwwork/FortCpp/
I've posted my own personal solution to this problem up on GitHub.
I'm not a C++ expert by any stretch, but I thought I'd at least throw it out there.
也许你想尝试我的“Multi”库: https://gitlab.com/correaa/boost- multi
生成类似于 A.base() + i*stride_1 + j 的机器代码*stride_2。 https://gitlab.com/correaa/ boost-multi#whats-up-with-the-multiple-bracket-notation
array1 = array2 + 2 * array3
嗯,不是那样的,我决定将数组算术与数据结构分开。
话虽如此,该库与 STL 算法非常兼容(如果您的步骤允许,它有一个使用 BLAS 的适配器)。
过度简化有关访问模式的一些问题,......
我将尽我所能维护它,我也欢迎贡献者。
Maybe you would like to try my "Multi" library: https://gitlab.com/correaa/boost-multi
Generates machine code similar to
A.base() + i*stride_1 + j*stride_2
. https://gitlab.com/correaa/boost-multi#whats-up-with-the-multiple-bracket-notationarray1 = array2 + 2 * array3
Well, not like that, I decided to keep array arithmetic separate from the data structure.
Having said that, the library is very compatible with STL algorithms (and it has an adaptor to use BLAS if your strides permit).
Oversimplifying some issues about access patterns, ...
I will maintain it as long as I could, I also welcome contributors.
也许存在诸如 BLAS、CBLAS 之类的库,但不记得在哪里。
http://www.netlib.org/blas/
Maybe library such as BLAS, a CBLAS exists, but don't remember where.
http://www.netlib.org/blas/
从性能角度来看,我尝试过 boost::MultiArray 和 Armadillo。两者都不是很快,因为与数组或向量相比,两者的访问时间都很慢,而且我能够在 x1(4:10) = x2(1:6) + x2(2:7) 等操作中击败这些包+ x2(3:8) 通过使用简单的手工编码循环(我确信在我的编译器优化的帮助下)。当您进行矩阵乘法时,这些软件包可能会通过 LAPACK 和 BLAS 提供一些好处,但您始终可以自己使用这些接口。
From a performance perspective, I have tried boost::MultiArray and Armadillo. Neither were fast, in that both had slow access time compared to arrays or vectors, and I was able to beat these packages in an operation such as x1(4:10) = x2(1:6) + x2(2:7) + x2(3:8) by using a simple hand-coded loop (with the help of my compiler's optimization, I'm sure). When you get into matrix multiplication, these packages might offer some benefit via LAPACK and BLAS but you can always use those interfaces on your own.
需要注意的是,这是无耻的自我推销,
https://github.com/ndarray/ndarray
可能值得研究。
虽然它不提供优化的数学运算符,但它确实为此提供了 Eigen 接口。它真正突出的地方在于通过 SWIG 或 Boost.Python 提供与 Python/NumPy 的互操作性。
With the caveat that this is shameless self-promotion,
https://github.com/ndarray/ndarray
may be worth looking into.
While it doesn't provide optimized mathematical operators, it does provide an interface to Eigen for that. Where it really stands out is in providing interoperability with Python/NumPy through SWIG or Boost.Python.