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.19.0.tar.gz
.
File metadata
- Download URL: pytensor-2.19.0.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e070528d12bee85f7fe68ce63b57a253c88d3e155a7415d9805c5b999dfa72b |
|
MD5 | b6af17c676b15efa979a8cad9ab7e0a8 |
|
BLAKE2b-256 | b5c54e7a028b1779853870236f76dc060f791be2eb8718438b3d1faf9ee84d8a |
File details
Details for the file pytensor-2.19.0-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.19.0-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/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f6d17233d6fb4f8d2b0106521eabe62c8cf467d9ee5d32e0ba65a0c976b619e |
|
MD5 | 0e96b06e71a4209a47bed7ca62a73730 |
|
BLAKE2b-256 | c519f2184027054a2742a3cdafffeccd361ac4c6115a00bca7ad4b9a15244701 |
File details
Details for the file pytensor-2.19.0-cp312-cp312-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e5d4464b3f19b2453beb75fa765a221fc0d3b055d1b4f2ff6b664d9c872736a |
|
MD5 | cdbcc8f76f38e892fd6478e08ebb9b26 |
|
BLAKE2b-256 | 6527acdfe49e0fe9e292e9790c3ccb3f327e0949b21438b86b2ddfbfd43c4fb0 |
File details
Details for the file pytensor-2.19.0-cp312-cp312-musllinux_1_1_i686.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp312-cp312-musllinux_1_1_i686.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a5245cb12b668eb417b5f54e63e04784ca39a58f1ccbe250cd3fda035939743 |
|
MD5 | e043c4bc45a812a52f2920b281684e61 |
|
BLAKE2b-256 | 0a8ef5516fb44e68fcd6817ad7848353f1fc85de7abc73ea512869ffbe095ac7 |
File details
Details for the file pytensor-2.19.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-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/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7015d6375407df7fdb83cb862ba0ff519311bb5107a53b480251ce8bebfb92fc |
|
MD5 | 3d489cdf136f52c7d3bbb4df02373ae1 |
|
BLAKE2b-256 | 1f31301c57d4d505aeee604f53c7759438a43e48e426714a7f7556a17064b6f8 |
File details
Details for the file pytensor-2.19.0-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba8946b79dc810958b65a060ce2c9abbdb94f677b2633d0d0ba7111b334cfb1 |
|
MD5 | ab4967011219ff5f6710b6170fb31ca7 |
|
BLAKE2b-256 | 36dfbd1f672554f61014dc3d604afa899807e650b91ce97edc7ccc498bf456a1 |
File details
Details for the file pytensor-2.19.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.19.0-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/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a20028c34ffb4ee62a6379cbbad5006cf76703207a9beddd4d2c9c0e1a00b19 |
|
MD5 | cbfa79a2fa1fde46e14d558a352e9eca |
|
BLAKE2b-256 | 92701cd36bee1ec0b9926fea4dbcb42581786e797b1eec620cfb30badd57a5e7 |
File details
Details for the file pytensor-2.19.0-cp311-cp311-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8601aa3dcc08ae99182a1f6ae2754453c47a5cf84e149ca81459d734204cff98 |
|
MD5 | 460d2209e3e5ed9c2dad0c510d9eed91 |
|
BLAKE2b-256 | 8dbef4fd32cdbd07dfb14ef9a1df0b9229636e3095cbc05bec6697f574cec2d0 |
File details
Details for the file pytensor-2.19.0-cp311-cp311-musllinux_1_1_i686.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp311-cp311-musllinux_1_1_i686.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.11, musllinux: musl 1.1+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97d8c95f35dfc6299e1d080d35dd1bded38efab01270819d3030e1ec633b2126 |
|
MD5 | cbe1fd6cebefb2e944423a26e3592ecb |
|
BLAKE2b-256 | c8d9812475f5eb40eba6caa6b1ab476a241556aa414a60df6751212f306b3c31 |
File details
Details for the file pytensor-2.19.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-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/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e79ee6dfc44f6162cfc11aa1bf4c4f6d5b40d2b4b70e3f871b70d230c6cc30b |
|
MD5 | cbc02f8bb7960259aff88bc9a16cf4d8 |
|
BLAKE2b-256 | ea80da6beec08a7fd4be0d434787446add191b9b0aeb2c7d4f6cf629d9681be6 |
File details
Details for the file pytensor-2.19.0-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-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/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb22a1c90598976fe283c9ccdba4ff18b490faee31b2e3f4cf288ac8e7244fd |
|
MD5 | 29f3c989b13c92cbc04dfcb27ede5712 |
|
BLAKE2b-256 | 8230ef7c73a4d1adf3cde6d00453acb2639d5b92d45cba6f557b0af08a418060 |
File details
Details for the file pytensor-2.19.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6564255b1182c557f13eef8d71c5c37032d58b3b922799e809a14913f3b32de1 |
|
MD5 | ea4723a4c52d07ce32b2c23dd8ae59c9 |
|
BLAKE2b-256 | 19b12a60a1e979ebda7269236e949abd24d9f3d63955a71e7164d0782d6acd5b |
File details
Details for the file pytensor-2.19.0-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a24a014f2fb1c3a3e3f796065a27607397eb99d7dd9b026022f932753615b1d0 |
|
MD5 | 95944852fccf3b3236d5f6ce08f3e72b |
|
BLAKE2b-256 | ff4d06265dd394eedafa50763253ba17a93773ad574a21a605244e19094e2414 |
File details
Details for the file pytensor-2.19.0-cp310-cp310-musllinux_1_1_i686.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp310-cp310-musllinux_1_1_i686.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6d6d8204991e0887b28feaf18fa530e5bed3ddbd2142a4f9d87e0ff267fe1ef |
|
MD5 | 538f78057728def779ea31b8079b53d3 |
|
BLAKE2b-256 | 419feb8eca7a491d2a85ae91bcac4fa75cbbc1326fa484b98be6464d7b63bba6 |
File details
Details for the file pytensor-2.19.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d62e162c8c63faff609e7b30740ef8df81b666d12095558c16990bc182313e0 |
|
MD5 | 18013c629eb83249ca5197b9c157e18e |
|
BLAKE2b-256 | af9fd9a762144081cdd5b2a14b5d4e81a9ed08367c43deb279b3d6db7c8116ae |
File details
Details for the file pytensor-2.19.0-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6a273f38e81d5a946e94696439b0f50850d8ae4846df43505ee6116853a3a85 |
|
MD5 | cba3569aead5c31913e200f67efd0c61 |
|
BLAKE2b-256 | 94d2afb32cf71b511e7e069e2840fa13f4ca5834b18ed30e9ef98b212ff4a827 |
File details
Details for the file pytensor-2.19.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efbd1eba8353109caefb8055f3afdc3ceffb04888fa4c7c1109fc65cc8a52c8a |
|
MD5 | bee64a0ba2740ab83a5b430969739be1 |
|
BLAKE2b-256 | 9ffb0226c312bd166a44d162fb9f2a06c7652d7a5d6c18e0a0a663148cdd599f |
File details
Details for the file pytensor-2.19.0-cp39-cp39-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp39-cp39-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 222ddde5f1eb4d6a870de7754da0f4743332ab542b0830b45c709980fcefa788 |
|
MD5 | b0cfa7ccf7c0cbd4888b542f551b24e6 |
|
BLAKE2b-256 | e43406357bb656fc82dea082e375afab07250738ba5a1644b3fc24256d9b4f53 |
File details
Details for the file pytensor-2.19.0-cp39-cp39-musllinux_1_1_i686.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp39-cp39-musllinux_1_1_i686.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.9, musllinux: musl 1.1+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49cb9940f3d174a9be4d739fbcd4ddbccc68b13814a68d8636a5fbdd724f37a1 |
|
MD5 | ce5513aaef7d7f2665da7382215cc659 |
|
BLAKE2b-256 | ad0721fdaea7818c2571d72ea1bace7a601f8d651f6d070ec9e46ee6ffacfef1 |
File details
Details for the file pytensor-2.19.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8f38669a704f8be043a929dbc0a260192454f8b19cdcedfe04403522c7837e6 |
|
MD5 | fdd476a2b9c5f29ddb17fcc6f8a70e39 |
|
BLAKE2b-256 | d1c5765023a5a2246ef2a37cf17491a775cde06f1aeada697ca41f91fa6da593 |
File details
Details for the file pytensor-2.19.0-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pytensor-2.19.0-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ff6f9b8853f3792669c7c9bdf80350d27b1c770cd235ccfb34c3743c9dca778 |
|
MD5 | 8f76e4f7bc727c0760a4703d22b76adb |
|
BLAKE2b-256 | 767d8472fa70841d2b33dbbf56d98703b8f348ac8519124e419d14b138161947 |