Python 与 C++ 的尴尬世界
The Awkward World of Python and C++
AI总结:
本文提出 Awkward Array v2 中仅头文件的 C++ 库,通过 LayoutBuilder 和 GrowableBuffer 实现 C++ 与 Python 的无 ABI 依赖、免拷贝数据集成,简化了 HEP 领域跨语言开发与打包。
摘要:
将 Python 与 C++ 绑定以利用两种语言的最佳特性具有不可否认的好处。这对于高能物理(HEP)及其他科学界尤其重要,因为这些领域已在 C++ 框架上投入了大量资源,同时正迅速将数据分析迁移到 Python。Scikit-HEP 的 Python 库 Awkward Array 第 2 版引入了一组仅头文件(header-only)的 C++ 库,不依赖任何应用程序二进制接口(ABI)。用户可以在编译时直接包含这些库,而无需链接平台特定的库。这一新进展使 Awkward Arrays 在其他项目中的集成更加容易、更具可移植性,因为该实现可以轻松地与 Awkward Array 代码库的其余部分分离。代码非常精简;它不包含在 Python 中使用 Awkward Arrays 所需的全部代码,也不包含对 Python 或 pybind11 的引用。C++ 用户可以用它来创建数组,然后仅通过原始缓冲区、字符串和整数将其复制到 Python,无需任何专用数据类型。这段 C++ 代码还简化了 ROOT 中即时编译(JIT)的过程。这种实现方法解决了一些缺点,例如在原生依赖可能具有挑战性的情况下打包项目的问题。在本文中,我们展示了使用仅头文件方法集成 C++ 和 Python 的技术。我们还描述了新的 LayoutBuilder 和 GrowableBuffer 的实现。此外,还讨论了将 C++ 数据包装为 Awkward Arrays 以及在不复制的情况下将 Awkward Arrays 暴露给 C++ 的示例。
英文摘要:
There are undeniable benefits of binding Python and C++ to take advantage of the best features of both languages. This is especially relevant to the HEP and other scientific communities that have invested heavily in the C++ frameworks and are rapidly moving their data analyses to Python. Version 2 of Awkward Array, a Scikit-HEP Python library, introduces a set of header-only C++ libraries that do not depend on any application binary interface. Users can directly include these libraries in their compilation instead of linking against platform-specific libraries. This new development makes the integration of Awkward Arrays into other projects easier and more portable, as the implementation is easily separable from the rest of the Awkward Array codebase. The code is minimal; it does not include all of the code needed to use Awkward Arrays in Python, nor does it include references to Python or pybind11. The C++ users can use it to make arrays and then copy them to Python without any specialized data types - only raw buffers, strings, and integers. This C++ code also simplifies the process of just-in-time (JIT) compilation in ROOT. This implementation approach solves some of the drawbacks, like packaging projects where native dependencies can be challenging. In this paper, we demonstrate the technique to integrate C++ and Python using a header-only approach. We also describe the implementation of a new LayoutBuilder and a GrowableBuffer. Furthermore, examples of wrapping the C++ data into Awkward Arrays and exposing Awkward Arrays to C++ without copying them are discussed.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。