我什么时候需要使用 Bigarray?为什么?

发布于 2024-08-10 04:39:36 字数 194 浏览 4 评论 0原文

Bigarray 模块的文档有些含糊。它指出该模块中数组的目的是保存“大数组”,但它并没有真正定义“大数组”的含义。什么时候应该使用 Bigarray 而不是常规数组?是否存在一定数量的元素,超过该数量我就应该使用 Bigarray?是几千个吗?百万?数十亿?

是什么让 Bigarray 能够更好地处理大数组?是什么让常规数组能够更好地处理...非大数组?

The documentation on the Bigarray module is somewhat vague. It states that the purpose of arrays in that module is to hold "large arrays", but it doesn't really define what it means by "large array". When should I use a Bigarray over a regular array? Is there a certain number of elements beyond which I should just use a Bigarray? Is it in the thousands? Millions? Billions?

And what makes a Bigarray better at dealing with big arrays? What makes a regular array better at dealing with... non-big arrays?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-08-17 04:39:36

我找到了答案(来自此页面

: bigarray 库实现大型、多维、数值数组。这些数组称为“大数组”,以区别于模块数组中描述的标准 Caml 数组。 “大数组”与标准 Caml 数组的主要区别如下:

  • 大数组与 Caml 数组不同,大小不受限制(浮点数组在 32 位平台上限制为 2097151 个元素,其他数组类型限制为 4194303 个元素)。
  • 大数组是多维的。支持 1 到 16 之间的任意数量的维度。相比之下,Caml 数组是一维的,需要将多维数组编码为数组的数组。
  • 大数组只能包含整数和浮点数,而 Caml 数组可以包含任意 Caml 数据类型。然而,大数组提供了更节省空间的整数和浮点元素存储,特别是因为除了标准 Caml 类型的 double 之外,它们还支持“小”类型,例如单精度浮点数以及 8 和 16 位整数- 精度浮点数以及 32 和 64 位整数。
  • 大数组的内存布局与 C 和 Fortran 中的数组完全兼容,允许大数组在 Caml 代码和 C/Fortran 代码之间来回传递,根本不需要数据复制。
  • 大数组支持普通数组无法有效提供的有趣的高级操作,例如提取子数组和沿某些维度“切片”多维数组,所有这些都不需要任何复制。

I found the answer to this (from this page):

The bigarray library implements large, multi-dimensional, numerical arrays. These arrays are called “big arrays” to distinguish them from the standard Caml arrays described in Module Array. The main differences between “big arrays” and standard Caml arrays are as follows:

  • Big arrays are not limited in size, unlike Caml arrays (float array are limited to 2097151 elements on a 32-bit platform, other array types to 4194303 elements).
  • Big arrays are multi-dimensional. Any number of dimensions between 1 and 16 is supported. In contrast, Caml arrays are mono-dimensional and require encoding multi-dimensional arrays as arrays of arrays.
  • Big arrays can only contain integers and floating-point numbers, while Caml arrays can contain arbitrary Caml data types. However, big arrays provide more space-efficient storage of integer and floating-point elements, in particular because they support “small” types such as single-precision floats and 8 and 16-bit integers, in addition to the standard Caml types of double-precision floats and 32 and 64-bit integers.
  • The memory layout of big arrays is entirely compatible with that of arrays in C and Fortran, allowing large arrays to be passed back and forth between Caml code and C / Fortran code with no data copying at all.
  • Big arrays support interesting high-level operations that normal arrays do not provide efficiently, such as extracting sub-arrays and “slicing” a multi-dimensional array along certain dimensions, all without any copying.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文