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-3.0.3.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-3.0.3-py2.py3-none-any.whl (1.5 MB view details)

Uploaded Python 2Python 3

pytensor-3.0.3-cp314-cp314-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.14Windows x86-64

pytensor-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pytensor-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3 MB view details)

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

pytensor-3.0.3-cp314-cp314-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pytensor-3.0.3-cp313-cp313-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

pytensor-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pytensor-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3 MB view details)

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

pytensor-3.0.3-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pytensor-3.0.3-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

pytensor-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytensor-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3 MB view details)

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

pytensor-3.0.3-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pytensor-3.0.3-cp311-cp311-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

pytensor-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pytensor-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.1 MB view details)

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

pytensor-3.0.3-cp311-cp311-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pytensor-3.0.3.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-3.0.3.tar.gz
Algorithm Hash digest
SHA256 8f6fa875a0b5be2bd3239662d620ce9ef9b052b4bf9bfa26498fb0cdda5dcf18
MD5 766f114f6bf8bbd66071884550a70683
BLAKE2b-256 f20da6d2bd9604c714da6de191e364c11f61ab2ba4b2b98209794dc6c07a21d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3.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-3.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: pytensor-3.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.5 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-3.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2bb7f04d4396d8f97d2e759b36957b65c6bcb216c313cf5a79fb4469841d49b9
MD5 7656806683616cf996cbe866a0f76872
BLAKE2b-256 333e32fdc4a8597f3c115287bbaf96485e9ac5d57b6bebf14447e89b8967a066

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.0.3-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.8 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-3.0.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 acd6d7efd4a7b299e4fa859ab07476a05c3295d9cb98740c77d89054036ebe2b
MD5 e780863b3af3eb2e8172bacc59bd046b
BLAKE2b-256 e58468aa3598fa422027f8264fd4efa1a157bc7839ccb22f24d6def733d06cb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c035550b5e71c2beab4276420f14bb6a4daac56214d1bb14b5a1de2dff97f91d
MD5 40ea5a17861a2ac4fc20e553c10b626a
BLAKE2b-256 eededd4286723761289908e6160abba4702472e1e22b6ded5709c194d4d1ef5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e57b015c09ac639100034a9051ef2ddc5f7bc01a82382e6f95dd8a7f5b7f1cf
MD5 63fda6e3f856a445c4b763b7377129ae
BLAKE2b-256 6ed9ed3087c71e9ff790148bda5b07714c9b3be94e3afba66621348526560dbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92b9abb143b031a3b04fe8ca6ae78914dda9bfb6b9cd8f4d75dc522f882376ab
MD5 f2eafa25cdf90b01d6f57ec165acce73
BLAKE2b-256 793d16740e09a559a0e6ca947a075c87eb427d6a2a822790a6f8bd37653eda1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.0.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.8 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-3.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 daf2d406af4811f2d038b533fae29d26f58399481c483684695838c511987504
MD5 46fbeadab8b63f74364b1578d3ff09dc
BLAKE2b-256 cd750b4e7f78ce478e5f1b5a7b8d621833b307d679afb7bb54483755dd1f737e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8b6827cb594a1d9efaa862429db3cfa89ec6eee33f16eebb901627a229262d9b
MD5 5649a380dc482ed77c1bc17501004c41
BLAKE2b-256 c8509b0477fdcbb937da8d225ce1ce559fb3f73d570309d8494948c0cfb245ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fc628feedfd9a7de1a7ce860fba7b69fb8899c61a1d03873c98ecffb0b42d5d6
MD5 f328c1cc92d07bdeca991febc3666dc1
BLAKE2b-256 710491649209c9b11373b0ae27fbcc5e47527ec2775f79ad7827ce5930cc822f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 37076cd9561c8d90d57fc206439a252f6082edac3bc76f728285bed5259cc804
MD5 a71b4d4df342eef1b2c1b96836fd5afc
BLAKE2b-256 f7bf3376fcb349e50133d0b9303f6cff329c4293439174420981e48bc2740c15

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.8 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-3.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 86a793b9b83d9fbbfd66557bf9323aea08a92409527ecf65c06ac1b48ce5a321
MD5 6ecf12a8074faa5a382d7ef8ea1be4ca
BLAKE2b-256 2d3ce1e06c89e9e5471aa7d7a3be40e1ab6ae1f5a9ba6f12980924945944f818

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 36a9edd3c70533b3cb20efe1fe1a6a0c61373a39bf1f78e9d7b4fb1fe0eabf95
MD5 027c2addea5c3bfa382b1ff606830b3e
BLAKE2b-256 21598a55017b8872d760dbb13f52aa40d613787b01d94cd769f8518381563829

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b9273554371dc05a9f4b826956d36dc166cd230165d8b8e21a28ae2bb23f3a6
MD5 a9bae7760e1426c3c9d3b111c3a5eaf0
BLAKE2b-256 89f8d450a7b2b11bf543dbd95ac8910f608fb8e3f91e6a8431ac40193e8d0578

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f5e2ed79fedd6fc33e646b8af390d2a576767b1994d2a1c107078c9000fcfc5
MD5 9a6ceb97cfcd84bb63b8976390d23776
BLAKE2b-256 55c41684d15db4cd0396cd5fbf9a6c08b4bb5ae59f55817bd2ac5ec7052bf02e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pytensor-3.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.6 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-3.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ef57ec53855a4b9c29be9990e28d24a36a40a84239a5580ad8974b843d0c8574
MD5 92e21eb5067533df5a2f6c13ac38da80
BLAKE2b-256 feefd96b2305a2d3c9496a4a15da12a3430b338d1b816f2a61c62985706be8d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8894a674d7b5bb665794ce1287a26730fc1eb58c7bd8003a6875e5827de8eef4
MD5 85154e311e7e2e1558056ea14590255d
BLAKE2b-256 ec4b908b4f7f80886c97668568a056836591e131ddbb5276395ec01785e10653

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c56ce4ce052c5f62b42336c10e590512d27987d5abac99eda65c23eafaf50304
MD5 05edc42c9aa5cbcbe9b7ee6f1fdb61e7
BLAKE2b-256 3ba4998b603b2364bcf21c22468adc492f38c755c962a765dbfc497cb12c7048

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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-3.0.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytensor-3.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 812c9ead6fd4e28bd2ba40f66bbf70865ed95f185f447f22c0fa5c59a8751bc1
MD5 0c018f2e0cadf61ba0f3b3dcf35904a9
BLAKE2b-256 bcadd9044c262e675fd0da0220400593012424cfb9ad15d14c1138924f692964

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.3-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