Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

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

PyTensor is a fork of Aesara, which is a fork of Theano.

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

pytensor-2.38.2.tar.gz (4.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pytensor-2.38.2-py2.py3-none-any.whl (1.4 MB view details)

Uploaded Python 2Python 3

pytensor-2.38.2-cp314-cp314-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.14Windows x86-64

pytensor-2.38.2-cp314-cp314-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pytensor-2.38.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-2.38.2-cp314-cp314-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pytensor-2.38.2-cp313-cp313-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.13Windows x86-64

pytensor-2.38.2-cp313-cp313-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pytensor-2.38.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-2.38.2-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pytensor-2.38.2-cp312-cp312-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.12Windows x86-64

pytensor-2.38.2-cp312-cp312-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytensor-2.38.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-2.38.2-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pytensor-2.38.2-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

pytensor-2.38.2-cp311-cp311-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pytensor-2.38.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytensor-2.38.2-cp311-cp311-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pytensor-2.38.2.tar.gz
  • Upload date:
  • Size: 4.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-2.38.2.tar.gz
Algorithm Hash digest
SHA256 c804e665e69e830e31344133fea5793d2fd75c662ee1359d01589875c0cce105
MD5 528bf56db556b5f8be09e20f26e36aa8
BLAKE2b-256 1c89e7b91f7366e36dbf937d4e53fa949b7f93627812e833526e0e426becbacb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2.tar.gz:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pytensor-2.38.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-2.38.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ae994b6e96d0d536e38c175a9b68df39fce4685a71dc8bb40acfbb779e755a34
MD5 bcbc6be23204f69f39361756b3c4af9f
BLAKE2b-256 4c124b91d7ec085f35f6e0afbf57c9d4a13a45d48d9bef37ed6123d147255ecf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-py2.py3-none-any.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.38.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-2.38.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9c4b4af108e9f9c4b664be0d10da0e5dfeb213bd2b83b94c6378d39a9f23915f
MD5 4326b3fde401c28719b5c0c089b72c77
BLAKE2b-256 4304215b8860b2409737cacca387644617dd0bb333a60d5bb77c3d7e0aa3e89c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp314-cp314-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ed8898ecae457ad621bc6610f13de37f83565a61782aa6c4c5e289d9c0310ab3
MD5 7d9fcd125eb9c632864702ec59dee969
BLAKE2b-256 fb4a8bf706ac30c026e01971e4cc6ef712677a635c33ce581514781658b1d975

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp314-cp314-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 994b051ec298789a9133cad29aa36092e0c2a3a564f64a2f05211c54d759b619
MD5 7b589bd027e7617d0869bdb7dd548b27
BLAKE2b-256 7e829667de1da8f38ad8556a62847330b07e2f2a06664c35ef3ca9b60b55896c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 071609e3a10b91d8aa11a4124f323836381fb8b92a4d424862b07f94a1d63b5c
MD5 93ed2759a516ef446edfbaf14cbe38f1
BLAKE2b-256 aaa7eea67f7b112053755fbdc071e8aeb27184e1ac651d031ef9f75eabb43fe8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.38.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-2.38.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3174e506c105a260c041c00e019e5ef2b2561a0fe1e51ddcefb6bc8f7baf7c17
MD5 93c9d7014f4ad1f14306ec5515c50337
BLAKE2b-256 974afb34aefd1a144708fe454004deab4393c45f94f5d2ba7bbe2610994d7699

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp313-cp313-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bd0e71d7e543df920a297601a1dc01441711b311d9e6cfb3c5cd1a5a10ab87a3
MD5 1e2a8c848fdf9ee865573e6bde2730f7
BLAKE2b-256 4f52e4a39c0377c435d4532bce95cb2ba8e161ee383b51e425bd08cadc780d79

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 03cb6307d29ce4a1755d82b6ccaa6739a070bd2a29223a12cbf4906b7ceefb94
MD5 62d2347115a5bf019b053f48154b576e
BLAKE2b-256 92e003a949eebcac4ff320263514ae65f939ed10f98c5523a878223f6cb3b18b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6857cc173df3b9362e8730db6e0ff4552feff9c86f86be98a92794a50305fda0
MD5 6419ac77590dd4319cf7b9808cf68c21
BLAKE2b-256 078a9d1a8e4c70b48ea07bc0f66004afc406612748e98c036b6c428814277baa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.38.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-2.38.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2393c7a0a8782fd447415971303111f485400390d15b356a62332efe36f9ba3a
MD5 21ed205d97f42c2a1ac63429b721789f
BLAKE2b-256 cd1e04ead3ab7ad4fdfcc48bafb38e4f0e4b175516c8b5c82526f536f79cc6d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp312-cp312-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e84086b77e0ed2577b8aa95ed2e398d25f2773cace9b30185b8ecac26d135529
MD5 661cee2ed2445efd2669d8cc3f2a57c1
BLAKE2b-256 6ccff4194459d4dd8952dcc01352a63b21b277b94200e1d12ac026e078598cf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b95d3f31c90f5269636fea0539b406c68e9d7af8d2cca25c973d13d7628c7a7a
MD5 ca982da67263856d2014e62f58cd11ff
BLAKE2b-256 19ce2269f04fc08579fc3133507ddc1a85c6121bb031b592085f85767eeb0c24

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 78227922e8e282b4af8cc98d496fbca2aead90da80221ed937f809e3e22a7d8e
MD5 20726c4037d751beab4337084d055d8d
BLAKE2b-256 0cc0caaecaddedb0919cdde1d943da877378d8e7ca6efe4d1ba721e6ba9b4901

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pytensor-2.38.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytensor-2.38.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c06f596acd7659471def911ee6a1e35013357e18c276777b1eb98bff316f310c
MD5 a8736e915edd516bec70f29c77cec4fe
BLAKE2b-256 11172c00b0cfcfa066f70b9d905a88a8de24f409310f51d205c3bb4163316b64

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp311-cp311-win_amd64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a7d2251ba1bd22649092af1d1661c339b3d2fcb938be663b3b60f2435a8addd9
MD5 e72b0be8587ddd3e5eecf4a8f5d0a6ea
BLAKE2b-256 8bed1ac83d3c4993414859929a24cfbb4ebf00e5c61fc10fbc4ac1d6262092e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 34eb065cf0ff2ed5845adedf9fe64ea67500dfb09aac211ec0ae0a6680651840
MD5 bd46d58e8d0420ea9e8f2493b1e2251f
BLAKE2b-256 6dc5be1088c0cfa06e972be51d83e8058ef87a98cbc87faf86502e395df0854e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytensor-2.38.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-2.38.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ea3f63c9f5eeecbe44be0305fa031b4c7352f0278dade695f22fa1c3703fcebf
MD5 752dac946258ac2d6277cab68ff67c7a
BLAKE2b-256 594ac148b5d7df8bc3c3b4cb521ae955a2f312b3f75a931f25c52b34b8f32728

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: pypi.yml on pymc-devs/pytensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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