使用sympy在GPU上进行符号矩阵乘法?

时间:2021-03-24 12:50:33

标签: python sympy

我有一个包含大约 300 行和列的矩阵 M。每个条目包含一个符号表达式,总共有大约 40 个符号。执行类似 M*M 的操作可能需要很长时间(数小时)。有没有办法使用 sympy 或更一般地在 python 中在 gpu 上进行这种符号矩阵乘法?

1 个答案:

答案 0 :(得分:1)

你很幸运!我几分钟前刚刚升级。在 [G|T]PU 硬件上并行化 SymPy 表达式的最佳解决方案是(截至 2021 年年中)Aesara,一个维护良好的 the now-defunct Theano package foolishly discontinued in the mistaken belief that Tensorflow was better 分支。 剧透警报:不是。

由于 OP 遗憾地未能提供最小长度示例 (MLE) 供我们进行破坏,我们将仅复制一个几乎无用的示例来演示核心 API 概念:

# SymPy -> Aesara translater, bundled with SymPy.
from sympy.printing.aesaracode import aesara_function

# Arbitrary SymPy expression.
from sympy import sin
from sympy.abc import x
expr = sin(x)/x

# GPU-parallelized Aesara function compiled from that expression! Yup.
f = aesara_function([x], [expr])

一般来说,最优解是whatever SymPy's "Numeric Computation" documentation says it is。目前,这意味着 Aesara;由于 Python 中的数据科学的变化速度比眼镜王蛇咬住村民的手要快,因此当阅读本文时,一切可能已经发生了变化。从 the aforementioned documentation is surprisingly intelligible 开始,先去那里。这是优化 SymPy 的最佳着陆页。

相关问题