Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.
Project description
PyTensor is a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays. It provides the computational backend for PyMC.
Features
A hackable, pure-Python codebase
Extensible graph framework suitable for rapid development of custom operators and symbolic optimizations
Implements an extensible graph transpilation framework that currently provides compilation via C, JAX, and Numba
Contrary to PyTorch and TensorFlow, PyTensor maintains a static graph which can be modified in-place to allow for advanced optimizations
Getting started
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]
See the PyTensor documentation for in-depth tutorials.
Installation
The latest release of PyTensor can be installed from PyPI using pip:
pip install pytensor
Or via conda-forge:
conda install -c conda-forge pytensor
The current development branch of PyTensor can be installed from GitHub, also using pip:
pip install git+https://github.com/pymc-devs/pytensor
Background
Contributing
We welcome bug reports and fixes and improvements to the documentation.
For more information on contributing, please see the contributing guide.
A good place to start contributing is by looking through the issues here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pytensor-2.26.3.tar.gz
.
File metadata
- Download URL: pytensor-2.26.3.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 703cfdba1d66b84a1739f50abdd7c18d25f788a85f2d07ed9b5bc66c929fb2fb |
|
MD5 | e661bc75acd06f8c56ce7d9fd95a0fff |
|
BLAKE2b-256 | 371c4592f1bbaf8de8e230128f4f47d0241b9bd2c7df6fecb0bcb22a152a86ff |
File details
Details for the file pytensor-2.26.3-py2.py3-none-any.whl
.
File metadata
- Download URL: pytensor-2.26.3-py2.py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 447ce88dd75a71dbb7158f9ccec0ffc7dc8fdb379f334ebf870003c977e4346f |
|
MD5 | 05b7afeb78ad9c21ae742722af28e3f8 |
|
BLAKE2b-256 | 04deaba6d7aa25ef3bfe4cb525addd4e2caf62dbb1300f5e9c5717d793b09f07 |
File details
Details for the file pytensor-2.26.3-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cce401c6020991767a2fde1d9dc7dda30a8289fc002552bc604e53623c92b8e0 |
|
MD5 | 9ecd5a511f8bca6e0b24d4238e7cd04e |
|
BLAKE2b-256 | 016a41f4a4640e1230788d4da0ea68c6e936a0c37448c319ddac934beb9e8eb7 |
File details
Details for the file pytensor-2.26.3-cp312-cp312-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c124fb425bd5867c6b206cb0b8d458ab1f983b180a63581abf9d07369b90e792 |
|
MD5 | fc36db350a41ef34971fe034f7f81573 |
|
BLAKE2b-256 | d7db6fc02bc770f7a17b52abdc7da8dc9536860943897c33d34b4394087568a2 |
File details
Details for the file pytensor-2.26.3-cp312-cp312-musllinux_1_2_i686.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp312-cp312-musllinux_1_2_i686.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 131141f7acbbe80bfa48895269ffcf4d572a0e01ebee81ef6b4f6f1042d88a59 |
|
MD5 | 22ea3ca09e20c482b977006c27b8b530 |
|
BLAKE2b-256 | 980e43fc2adf178aa6d9ad21a7bdc452e8fd7a762327f0d7785f8483b8e65f66 |
File details
Details for the file pytensor-2.26.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4954fbe7b45077063166c83e100d36ad461df283c2222d0d15dc523ac312609 |
|
MD5 | bb455e48098c0b477778f6a0d7c44362 |
|
BLAKE2b-256 | d7bc51aecd9d5585c95ad221cf3f3f56a861471c194670a8482d09ea4422cf8e |
File details
Details for the file pytensor-2.26.3-cp312-cp312-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b6b327cd8e39440b6c090d6c7ff85192f3db99f753b76cb5483fbf3212304c |
|
MD5 | 6b06561dbb293dd2e9bd2f30c6a5ff63 |
|
BLAKE2b-256 | 77c216feccdb623c6a455a408b0b342bf4a3d1e8345295292b47f772142d3111 |
File details
Details for the file pytensor-2.26.3-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae418d65b752a8bac50c0a401a052854ff85c509a51c70d7c6539299a75c1ba3 |
|
MD5 | 9e92ca6f3b313ff4c601e86f627eee13 |
|
BLAKE2b-256 | 25c5b6a3ba6a1a176e542b094a84b10e7641cbcf481cd40ce937567b101dafe2 |
File details
Details for the file pytensor-2.26.3-cp311-cp311-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06362f848cb576e378fd2ff00caf79365aa44c0fe2473d68be1de78013925518 |
|
MD5 | ef80ce7504955eb519dbf641cc28c074 |
|
BLAKE2b-256 | decf1ba2cd213f4b570d8f1895a93719cdf2e066e13df9ea693802f82ba0acbe |
File details
Details for the file pytensor-2.26.3-cp311-cp311-musllinux_1_2_i686.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp311-cp311-musllinux_1_2_i686.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b6985fb9cca966231d654d4396b293f1e33dd78a4bbb274af9f18e19defd5c3 |
|
MD5 | 6afab2be79e80aca702400b4e4d33111 |
|
BLAKE2b-256 | aac5aaf2401db230e3ba5ab2be54ad52bc031d70f31c5896ddc548465138d9f9 |
File details
Details for the file pytensor-2.26.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab08350715554bb53be83d3be75283bb8890caf72e97b122b4fae76244950d3f |
|
MD5 | 080bfe18ea763c2178e34f294601cd33 |
|
BLAKE2b-256 | 859dc910f764ab3f7cf543753d75f98f0877564d9fc47167ab0c0bfa3143d718 |
File details
Details for the file pytensor-2.26.3-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e41d3b68d6dfabb75c99cd6cb579c9fb9c95f02c40fb5561f39fa7a4b8f6fc6 |
|
MD5 | e88aba64a062ac76d7769fdda0c558bd |
|
BLAKE2b-256 | abf3375dce24cc58fe8cc3d896403ddb6bacc3f693933bda0447111d5cd10d37 |
File details
Details for the file pytensor-2.26.3-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c63279b86001029a38e82facc3b1d4a8b24723c1fd7263e3590886f3b2c2923 |
|
MD5 | 4c01feef98f84b28181a863de924ee92 |
|
BLAKE2b-256 | 555a7d5226a0b292f433900b4f343c7174e6082dd2da737b30fc82d7b5da4f73 |
File details
Details for the file pytensor-2.26.3-cp310-cp310-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp310-cp310-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acc6e799fba9cbf7e544c17e33c976d4e7230c87a322cc69c35b710ef720087b |
|
MD5 | 9d9dec30c35b6964bef3dd3075395d08 |
|
BLAKE2b-256 | b0283e09933c3d563185731c777f86f03ffd3512b32dda589b0d0897de49c5a7 |
File details
Details for the file pytensor-2.26.3-cp310-cp310-musllinux_1_2_i686.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp310-cp310-musllinux_1_2_i686.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f95bc45f2f2644866b4e603d85edbdc984e609d52877e6ca9381caaa641a1b03 |
|
MD5 | 5c98d9950cb5ecf197e28cf742c9308d |
|
BLAKE2b-256 | 9fd268ea4c2be6df3ea3aa040c7069a680687a9124954ca23a02d49ac9fa53f7 |
File details
Details for the file pytensor-2.26.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89da00c829a6107f275894f75219d48c18916e48a0946b77d8a1bebd4fe995b6 |
|
MD5 | a4dd456fa5f771328df7efc8af31be5b |
|
BLAKE2b-256 | ee1e7e14edf7f47e698bb6a7339e4fab77a4385d2b9fcf95e3dc7246a9261ba1 |
File details
Details for the file pytensor-2.26.3-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pytensor-2.26.3-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcce400cb435309c00af2dba8eaa8825f651eb4e39571966c141bb616ff17b5b |
|
MD5 | 350e17a164a2c0828358536279313bb8 |
|
BLAKE2b-256 | 14adb0828d50668fa7b4f7ae1355a05d9b961a693ae34ff73ad21c1dc3394e54 |