Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

PyTensor is a fork of Aesara – a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.

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

  • Based on one of the most widely-used Python tensor libraries: Theano

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytensor-2.17.0.tar.gz (3.5 MB view details)

Uploaded Source

Built Distributions

pytensor-2.17.0-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.17.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.17.0-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.17.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.17.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.17.0-cp310-cp310-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.17.0-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.17.0-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.17.0-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.17.0-cp39-cp39-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pytensor-2.17.0-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.17.0-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file pytensor-2.17.0.tar.gz.

File metadata

  • Download URL: pytensor-2.17.0.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pytensor-2.17.0.tar.gz
Algorithm Hash digest
SHA256 5d97904813ace98d48583fecf99fe47925c16e0e2ec951cd9ef91372b483555a
MD5 f5b50598421b1408d700da118232eb9d
BLAKE2b-256 f36ffabb830619322e680d6fc39b10eca41ff02a140d5644ef1919728f31e9d4

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a4a34cf0ce51b73d89f63e97c6fe0439d5900cdfacbe3bd2359397fae6f639a9
MD5 6bf972460dd714e29dda6e1354d80918
BLAKE2b-256 33bb2455f77d13bb5ac0691b61b0c22f42d5ca62033446f869fbabc80b66e1c5

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 24f42c6b676417547b0536f62fdb17485f9360584cf67ae2849380ab7f009ba3
MD5 ec30f316e2ed8d3f764375e8c5d0bad5
BLAKE2b-256 9ed1d0428d3e171a335ed13623c0eae8b6fb7ab96225b31aca449eb6f4d7ccd0

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 8eeafd0c40f7a176cf5c450f2deb3910f30f86adcf1e35c8c94ab2d59991cd66
MD5 486403edfc960bc8a59250fed215eb1d
BLAKE2b-256 74953b49bb2c70c2f2b78bfb4cd871ebb5a13f00b70df007567f12a76b8f729c

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b90d330823b889731771b2cc4781a3aff0b345cbb3e3e520da0590cd49ed7b79
MD5 56ae52428d8df0b758bf015bb371c839
BLAKE2b-256 af4532f234ac893a82baf22948f90d79c6c6d9ef67a5edb1b86f272b199b4aa8

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f121b7b725b92e2c749ecf99fff1abb61f630a6265f7ba8d87100c9d4cc36845
MD5 b981b299b7417e7247164ef86f52e740
BLAKE2b-256 0fd38ff24397c8d125af897762af33cb6480206d0830641cfde06b8766436060

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 99df9627b000a6bb416bd0d741445cc6b2310580b9e9af25d6580cbe18930849
MD5 4593eba49f40a0dd6ad8ef0d5ae0ad32
BLAKE2b-256 5d6133b044c3dbb9c024ad83931a2cb360f1a2c4c169dabe32f8336c91562295

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4e7904a0c3b74842a4badfec54c5a578da044f3368b27262f8557273530cead5
MD5 003251bc8e7e1546b1c0f765710a6434
BLAKE2b-256 cbdc5f446f0fa6c4616bb7212ca544a03a12f952737cd4173840b76486bd1e0c

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 054edc8e95b19edc5fe59f0195ccc094fbfb9044bd17e3d28586915412fc9f12
MD5 1c03b702207dcefca64987a1295bd142
BLAKE2b-256 5c434c28975d6aba24812467a09d8edd501643dddcb5137655daa9b13fa3482b

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 acb34841e08f4797c2f03b0f70fac8276777da2497d734ddef9577dc1d6a125e
MD5 79509a77dfa2a8b7d44d039d6eabac75
BLAKE2b-256 d0a05fd9485da8b486f7d59ed34c18b1340b50461e3d54769da68248dfa4ce7f

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0789ca79c67693977a3efd787f74c9204dae730c2c886a71fe2005a737c0962c
MD5 f25274d26672e981830b3bd85349ce13
BLAKE2b-256 59a5e46a3f767ea368baec2822d1a92d213b411788d76053c6b82001467fe468

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.17.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.5

File hashes

Hashes for pytensor-2.17.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 383d668954ec2b053b9d89b2791ba2201e75b0e484a9d0268d934c0fb56e3058
MD5 2d5f4215aa410ad5ab3a72034bed9339
BLAKE2b-256 af5be9c15778bed6632c66d714b9b655671ed4a8a66b401616c01e79fcfaf89e

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ff4cf682c3f2dc23299e55e516f984ca530fd0f2dd31d1ec0801813b3afa3853
MD5 98d1bcc5f9e6dbc95f70be6f4d3951af
BLAKE2b-256 8952ad8da4bded5835c5ef4cfe9c803ee94636f4982b32a443d4d0db47648a7c

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d8282366d56537967018fd0b53a81be32698329cd0e9667505b1b27eb0412ad6
MD5 ba4738850ddc1b0d23bb32fb3028e369
BLAKE2b-256 19498c8175772d446a4672117422b969ebce17813fabd53495100c32e1d3fce3

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e472397bd841a541b4f2d6612ea0adfde86bfec80ce64fc331b2f76e958026b
MD5 1ed634576c23efd3e6b8e980cc33f1d5
BLAKE2b-256 301f47be3acf6a7a2363929ee502bd46110328e84be57d6b2b798dfe79af847b

See more details on using hashes here.

File details

Details for the file pytensor-2.17.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.17.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6d81cfcd5933b8dc972303ecfcabffaee7ab41194e677e59a35fc69aad294d25
MD5 47f19481783531fb7dd3f975a672042c
BLAKE2b-256 d4b9e0469f926faa901fbc9c93823cf70d7e964256aaa2f2fe78ce38d5059b13

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page