优化编译器,用于在CPU和GPU上评估数学表达式。
项目描述
PyTensor 是一个 Python 库,允许用户定义、优化和高效评估涉及多维数组的数学表达式。它为 PyMC 提供计算后端。
功能
入门
import pytensor
from pytensor import tensor as pt
# Declare two symbolic floating-point scalars
a = pt.dscalar("a")
b = pt.dscalar("b")
# Create a simple example expression
c = a + b
# Convert the expression into a callable object that takes `(a, b)`
# values as input and computes the value of `c`.
f_c = pytensor.function([a, b], c)
assert f_c(1.5, 2.5) == 4.0
# Compute the gradient of the example expression with respect to `a`
dc = pytensor.grad(c, a)
f_dc = pytensor.function([a, b], dc)
assert f_dc(1.5, 2.5) == 1.0
# Compiling functions with `pytensor.function` also optimizes
# expression graphs by removing unnecessary operations and
# replacing computations with more efficient ones.
v = pt.vector("v")
M = pt.matrix("M")
d = a/a + (M + a).dot(v)
pytensor.dprint(d)
# Add [id A]
# ├─ ExpandDims{axis=0} [id B]
# │ └─ True_div [id C]
# │ ├─ a [id D]
# │ └─ a [id D]
# └─ dot [id E]
# ├─ Add [id F]
# │ ├─ M [id G]
# │ └─ ExpandDims{axes=[0, 1]} [id H]
# │ └─ a [id D]
# └─ v [id I]
f_d = pytensor.function([a, v, M], d)
# `a/a` -> `1` and the dot product is replaced with a BLAS function
# (i.e. CGemv)
pytensor.dprint(f_d)
# Add [id A] 5
# ├─ [1.] [id B]
# └─ CGemv{inplace} [id C] 4
# ├─ AllocEmpty{dtype='float64'} [id D] 3
# │ └─ Shape_i{0} [id E] 2
# │ └─ M [id F]
# ├─ 1.0 [id G]
# ├─ Add [id H] 1
# │ ├─ M [id F]
# │ └─ ExpandDims{axes=[0, 1]} [id I] 0
# │ └─ a [id J]
# ├─ v [id K]
# └─ 0.0 [id L]
请参阅 PyTensor 文档 以获取深入教程。
安装
您可以使用 pip 从 PyPI 安装 PyTensor 的最新版本
pip install pytensor
或通过 conda-forge
conda install -c conda-forge pytensor
可以从 GitHub 安装 PyTensor 的当前开发分支,也使用 pip
pip install git+https://github.com/pymc-devs/pytensor
背景
贡献
我们欢迎错误报告、修复和改进文档。
有关贡献的更多信息,请参阅 贡献指南。
开始贡献的好方法是通过查看 这里 的问题。
项目详情
关闭
pytensor-2.25.5.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f8b9f7d637104b2fc7fdd9c50219cc639744b718572c034b7cb8fe8f5051da92 |
|
MD5 | 7b712f4ebdbc6ef2209bf6096b740887 |
|
BLAKE2b-256 | bba54ef19e1a589cb0dfc863af1afa1e9a54d6bc30579504893ec4682f44520e |
关闭
pytensor-2.25.5-py2.py3-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 92271932118e4d9e6528eeba1cdd0e9e8f2d05d8493eb394da2cd8cf09c8836e |
|
MD5 | 92e801c7eef921b3f6b724dfb3e077bd |
|
BLAKE2b-256 | f511032d9c2bb9bfa1b6d933c17a6fd063e075c533cca271d8c9b2055f94b981 |
关闭
pytensor-2.25.5-cp312-cp312-win_amd64.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5edaa549903a8be02e6dcf56110d5cf523b6249460c455138e36686928a6c5a7 |
|
MD5 | ed952ab8284de52757d80ffadae9c16d |
|
BLAKE2b-256 | 0bffd949332ce887e634de0c26c47486166bb1a56597c3bf477b2e7d61be2767 |
关闭
pytensor-2.25.5-cp312-cp312-musllinux_1_2_x86_64.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 16344b21bd70eb689c7db7ab91eec556012c08e9ad8a7cbeb42812d53f89a64e |
|
MD5 | a908f003957287378d5572eb63123b4b |
|
BLAKE2b-256 | 8e22e68d36ff93a15d1d5d458765503a2937155b08f53c5bf198e6b2fc458f5c |
关闭
pytensor-2.25.5-cp312-cp312-musllinux_1_2_i686.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0c973a8a682854eb47378db33cfb5bc63ba5a868b5749fe79b2846e6795ff46d |
|
MD5 | 79b90c95064f5ec8e61763faa41f5ef3 |
|
BLAKE2b-256 | 1b63be49fbdb9ad4c43485f637ced24c2df9a0f58da4c765bbfe177748004742 |
关闭
pytensor-2.25.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9c99f2aed904178c59fac57f5a760b547f7c1c14c20d31e41721fbebf9e47cf1 |
|
MD5 | f01757a4a0d69747b857f0e75121e404 |
|
BLAKE2b-256 | 060792f6e94c1ec6eea9e3acebc7c2767a7bbf1d4ebd320e4326aeb04c2eea9e |
关闭
哈希值 for pytensor-2.25.5-cp312-cp312-macosx_10_13_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f15cf74eff5e53854f9e74ac4991ae850e48641ccbb211200d214c599b76d691 |
|
MD5 | 48ddca2b76dc6f5f5794478a05830d3a |
|
BLAKE2b-256 | 7799f8f4a75e3287c48409dad5aa96336d10d76e9b4c9ebf5193b7436473ab2b |
关闭
哈希值 for pytensor-2.25.5-cp311-cp311-musllinux_1_2_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 78686d9e26b26da2f0824f1f5a297f153b948a93c46e527d43d7337fe31e5afb |
|
MD5 | f47df49d67ba2271b35ed3a07df2db99 |
|
BLAKE2b-256 | 98b52ebe68a162f64daf4161ba0f74141adda0c3111ea04a8e4b6a27df9be2c9 |
关闭
哈希值 for pytensor-2.25.5-cp311-cp311-musllinux_1_2_i686.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 930429bdf5cee35868a06a9d075f2fb40b3471708a61bea62cfafd21aaa0811e |
|
MD5 | 2ba6a271544029ce61f508ae47c321c7 |
|
BLAKE2b-256 | 7b4914eed626a4803d55703714268586250a9c531461c1a2e5a6b89c74bc369d |
关闭
哈希值 for pytensor-2.25.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | eb7f6a370a99095850949798ee0ada38ace5132172fcbb4272398e687de5b417 |
|
MD5 | 3e378ad67e3093c8108b13e601ebbc36 |
|
BLAKE2b-256 | 76284b5cd6067cab5d8180383d13533f6e8e3c1d8e8df8f3cce940d8aa9868b3 |
关闭
哈希值 for pytensor-2.25.5-cp311-cp311-macosx_10_9_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a97e769900718fea3a0efd2a4c452775786ca3bd7966c6510e89a1356e516d55 |
|
MD5 | 9b40cbd81956cdc0838e26d4b32917a9 |
|
BLAKE2b-256 | 7a133377794660abf0ca720c3f51b12f9785a40ef8fdf94d61e38056cc8421da |
关闭
哈希值 for pytensor-2.25.5-cp310-cp310-musllinux_1_2_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 343000f352c12ec36f5307d5c9ff7d8aba6dfa651be8c26b824d75cbad29d776 |
|
MD5 | d082dac210c327663a7ecead6d9f7530 |
|
BLAKE2b-256 | bf7289a271a956a68540fb0860d13c64289333b9d342ce3a9cfc66b2000c4550 |
关闭
哈希值 for pytensor-2.25.5-cp310-cp310-musllinux_1_2_i686.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 51ea5083ec4760e6cfda48422d1b69e88d1b68e0f9a4aca41b0a89a4f38a1da7 |
|
MD5 | 7ab7fcb5bb33e67b3bf7dfb8be4cf29b |
|
BLAKE2b-256 | 1d4e530426b9f42ae9fe7b20c4d9fed668693323fedb7b9a89cf14ae15bd51d4 |
关闭
哈希值 for pytensor-2.25.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 29754160a84ade77b63e1690aad8306da3b8f6f8e35c8ac5d36d1b19066b5f8d |
|
MD5 | 9ec243a78ec2fd219f7b59c7b86173fa |
|
BLAKE2b-256 | 24211453be9b7b9db42347731a482a2608f61683c52996ae1ceafdc482af64db |
关闭
哈希值 for pytensor-2.25.5-cp310-cp310-macosx_10_9_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 23ffac5ce99089abe3b6e1ae0c957f3af2a382209fb5894eb42acba0e01b96bf |
|
MD5 | a91273997b2a8b1325a2bc32628256c4 |
|
BLAKE2b-256 | 05c25ea704f628c8998e80759d8c95645742739f06f405b6ff03efadc7f43719 |