用统一向量化思想简化张量操作,让代码更清晰易写。
It's All Just Vectorization: einx, a Universal Notation for Tensor Operations
- 以向量化为核心,将复杂操作分解为简单规则
- 支持所有张量运算,减少框架接口复杂度
- 适合想提升代码可读性的科研与工程开发者
张量操作是现代科学计算的核心。然而,主流张量框架采用的类似 NumPy 的记法往往难以阅读和编写,且容易产生形状错误,原因在于众多操作遵循不一致的规则。尽管 einsum 和 einops 等替代方案逐渐流行,但仅适用于少数操作,缺乏通用性。为此,我们重新审视向量化作为变换张量操作的函数,将其用于将低阶操作升维,或概念上将高阶操作分解为低阶操作及其向量化。基于向量化的普适性,我们提出 einx——一种通用张量操作记号。它采用类循环的声明式、点状表达,直观表示向量化过程。该记号将现有框架庞大的接口简化为少量基础操作,统一所有规则,使代码更清晰、易写。我们提供了嵌入 Python 的 einx 实现,可无缝集成现有张量框架:https://github.com/fferflo/einx
原文摘要 · Abstract (English)
Tensor operations represent a cornerstone of modern scientific computing. However, the Numpy-like notation adopted by predominant tensor frameworks is often difficult to read and write and prone to so-called shape errors, i.a., due to following inconsistent rules across a large, complex collection of operations. Alternatives like einsum and einops have gained popularity, but are inherently restricted to few operations and lack the generality required for a universal model of tensor programming. To derive a better paradigm, we revisit vectorization as a function for transforming tensor operations, and use it to both lift lower-order operations to higher-order operations, and conceptually decompose higher-order operations to lower-order operations and their vectorization. Building on the universal nature of vectorization, we introduce einx, a universal notation for tensor operations. It uses declarative, pointful expressions that are defined by analogy with loop notation and represent the vectorization of tensor operations. The notation reduces the large APIs of existing frameworks to a small set of elementary operations, applies consistent rules across all operations, and enables a clean, readable and writable representation in code. We provide an implementation of einx that is embedded in Python and integrates seamlessly with existing tensor frameworks: https://github.com/fferflo/einx
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。