使用哪个 haskell 数组实现? AKA 各自的优点和缺点是什么
我需要什么? [无序列表]
- 非常
- 对映射、过滤器等的简单并行化支持。
- 高效执行基于数组的计算的能力,如 A=B+C,有点像 matlab 数组。
- SIMD 代码的生成。我想这在不久的将来对于任何事情来说都是不可能的,但是嘿,我可以问:)
- 对矩阵的支持应该至少存在,更高的维度现在优先级较低。
- 能够获取指向它的指针并从 C 指针创建一个指针。
- 其他图书馆的支持。 IE、绑定到流行的 C 数学包、磁盘 I/O 或图像(如果数组是 2D)
我看到了什么?
- haskell-platform 中的数组包。它是幸运的,可以并行
- Data.Vector。有循环融合,但没有在平台上,所以它的成熟度我不知道。
- repa 包,由 DPH 团队贡献,但不能与任何稳定的 ghc 配合使用。今天。
- 对数组实现的支持级别有很多变化。例如, 似乎没有将 2D 矢量转储到图像文件的简单方法。 IOW,haskell 社区显然尚未确定数组实现。
所以请帮我选择。
编辑 A=B+C 指的是按元素添加,而不是列表串联
What do I need? [an unordered list]
- VERY easy parallelization
- support for map, filter etc.
- ability to perform array based computations efficiently, like A=B+C, sort of like matlab arrays.
- Generation of SIMD code. I guess this is out of the question in the near future for anything, but hey, I can ask :)
- support for matrices should be there at a minimum, higher dimensions are lower priority right now.
- ability to get a pointer to it and create one from a C pointer.
- Support from other libraries. IE, bindings to popular C math packages, i/o to disk or images if the arrays are 2D
What do I see?
- Array package in haskell-platform. It's the blessed one and can do parallel
- Data.Vector. Has loop fusion, but not in platform, so its maturity is unknown to me.
- repa package, contributed by the DPH team, but doesn't work well with any stable ghc today.
- Lots of variation in the level of support for array implementations. For instance, there doesn't seem to be an easy way to dump a 2D vector to a image file. IOW, the haskell community apparently hasn't settled on an array implementation.
So please, help me choose.
EDIT A=B+C refers to element wise addition, and not list concatenation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,社区还没有确定一个好的数组实现。我认为提出 Vector API 并删除 Data.Array 将是一个很好的 Haskell Prime 提交。
Vector已经很成熟了!它具有:
它没有:
注意:您可以将字节串转换为任何向量,因此,如果您有一个图像作为字节串,那么通过 Vector.Storable,您可以将图像作为向量执行您想要的操作。
Correct, the community hasn't settled on a good array implementation. I think it would be a good Haskell Prime submission to put forward the Vector API and remove Data.Array.
Vector is very mature! It has:
It does not:
NOTE: You can turn bytestrings into vectors of whatever, so if you have an image as a bytestring then, via Vector.Storable, you might be able to do what you want with the image as a vector.
(我不允许发表评论)
rpg:hmatrix 接受
Data.Vector
吗?它有一个 Data.Packed.Vector 但它们相同吗?是的。 hmatrix 的最后一个版本默认使用
Data.Vector.Storable
作为一维向量(以前它是可选的)。 Hackage 中没有显示对向量的依赖,可能是因为它位于配置标志中。对于 LAPACK 兼容性矩阵不是
Vector
或Vector t
,但它们可以轻松转换(例如:Data.Vector.fromList . toRows
)。(I am not allowed to comment)
rpg: Does hmatrix accept
Data.Vector
? It has aData.Packed.Vector
but are they the same?Yes. The last version of hmatrix uses by default
Data.Vector.Storable
for 1D vectors (previously it was optional). The dependency on vector is not shown in Hackage, probably because it is in a configuration flag.For LAPACK compatibility matrices are not
Vector
orVector t
, but they can be easily converted (e.g.:Data.Vector.fromList . toRows
).如果您想要绑定到流行的 C 库,最好的选择可能是 hmatrix 和 < a href="http://hackage.haskell.org/package/blas" rel="nofollow">blas。 Blas 只是 BLAS 库的绑定,而 hmatrix 提供了一些更高级别的操作。还有许多基于 hmatrix 构建的库提供了更多功能。如果你正在做任何类型的矩阵工作,这就是我会开始的。
矢量包也是一个不错的选择;它稳定并提供卓越的性能。
Data.Vector.Storable
类型表示为 C 数组,因此将它们连接到其他 C 库非常简单。最大的缺点是没有矩阵支持,所以你必须自己做。至于导出为图像格式,大多数 haskell 图像库似乎都使用 ByteStrings。您可以转换为 ByteString,或者绑定到执行您想要的操作的 C 库。如果您找到一个可以满足您要求的 Haskell 库,那么将 hmatrix 数据转换为正确的格式应该很容易。
If you want bindings to popular C libraries, the best options are probably hmatrix and blas. Blas is just a binding to a BLAS library, whereas hmatrix provides some higher-level operations. There are also many libraries built upon hmatrix offering further functionality. If you're doing any sort of matrix work, that's what I would start with.
The vector package is also a good choice; it's stable and provides excellent performance. The
Data.Vector.Storable
types are represented as C arrays, so it's trivial to interface from them to other C libraries. The biggest drawback is that there's no matrix support, so you'd have to do that yourself.As for exporting to an image format, most haskell image libraries seem to use ByteStrings. You could either convert to a ByteString, or bind to a C library that does what you want. If you find a Haskell library that does what you want, it should be easy enough to convert hmatrix data to the proper format.