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.37.0.tar.gz (4.8 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.37.0-py2.py3-none-any.whl (1.4 MB view details)

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pytensor-2.37.0-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.37.0-cp314-cp314-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pytensor-2.37.0-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.37.0-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytensor-2.37.0-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.37.0-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pytensor-2.37.0-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.37.0-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.37.0.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.37.0.tar.gz
Algorithm Hash digest
SHA256 881ae920d082aa3651fb83016c76e4e2588ba643f0506ceea556d8332ab0362c
MD5 128612e485905397d5afefc5c98d8578
BLAKE2b-256 a05dda27918dce805d27bf1c0c963da46fc11b1decf54f4a0e2799fecfd479f4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.37.0-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.37.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7beb782f0579d57adaeecc7396f184c2c254e46e2ce7cb6bcbda1979792e5a0d
MD5 92e616a9564bfd6727c9ba3dc5c065fc
BLAKE2b-256 556c5718d4a63a81a0eec361ca57a63b6087bb92d525a0f16e4e55c0ee4aa63a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.37.0-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.37.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 65d8aa6639f8dd746e96660fa1f3e775f1c4f4766100e63d85489ebe253049b2
MD5 d6a87893cab4409d6e557b8854888d4d
BLAKE2b-256 6bfe6a62d8a5cf11fd9c2416bcbfaa477944637fa3f1278a499d0c715d723a6f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 88ff250954acbd62c4475dba0a5e5b3a1dccddcdcb5938719e574169358fec8f
MD5 7a6ac8f8b5f91eb189d7281a05d8ce2b
BLAKE2b-256 a64e4cfdf2fb37ca1e2d1b507a71c538e1b9c1397ac327c3c1ef1e84d058a94b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12b29f50d666c1391269778e651ba4c64a0cd5a1a3ce5552a8917e0bfc127aaf
MD5 82b9c8a3b414f54b1ea2cfafc434dedb
BLAKE2b-256 cf78d466b918300a23f9d76bbee8b9328c27aa040de682412791ec70110418f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c018a069f93ec1f679ffe63323996b7392f0d8b582858b4a44da4cf5ab2c79fd
MD5 167413758a1542ef1b6ac00160872371
BLAKE2b-256 beb0acbc8f73e6dee0b3675ea08f88e7127dd90fa6b1ff27eecbf48587b51321

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.37.0-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.37.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6fbd94b2fd1ae30a817130802ec9d62ab20dd5ff6a859ed9f04407dfe116d915
MD5 e8b39551b3c56c281662c07da90e8313
BLAKE2b-256 4bd1c143ed924201ccfe0e73ce4fa1d26107c6caa040e12420c1adda66cc4ac6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 88734f96f77f2edd697f48fb017ce4cdd5fd5e4050761aa0dd8d14584e2a2e52
MD5 e798d9768dee087424a34c2d1d3dc61f
BLAKE2b-256 2131ced5aafc641cd2f9a594e27ddb2e9b77669f4d6acaba8fb916091611993f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bebfc9460ded277cdcd2614edd2a5540817806c2fd7dce2a8d44e771c630f9e1
MD5 46d9aea29e2c5a9ce68d88249ac63136
BLAKE2b-256 bd6ee60a6cd34df668c6ae821979e02f80e68f9094d3c9f7aa1f1408c2fb27ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 780fab66c4545ee8c08c14b457253d8494577c70b16117fe89190f941a750cbc
MD5 38cfda864a5741a0cfddf1e351e5b7c6
BLAKE2b-256 0d5b3c1989ed4efc214a23d41f74793e89281c7f30276407556294814435d2e3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.37.0-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.37.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b93734bf4f23401d63db9dd3cfed56423687e504e5c277ac65b0ceab8e3bac97
MD5 a74920a1f0102f6a18d5a67135430b65
BLAKE2b-256 2e526d9b006582c20e216a186c1a554c4ac93fb3284626ce188e1b258769eee2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0d4060dbfff3392d5bc53d6337a8d9000250e03b445785fbb3ea06572a5f21e3
MD5 19d33b6e02ddd6b10ef3a3b2ddfc2b0c
BLAKE2b-256 e9cd69e209ab0c6625cea168b68f6d9bfb87868682980dc83c154ab69908e078

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6438d5f36478e2e24023c245340ad5de4cfcf6dfa739332dfd0c9ac8f2679686
MD5 117e26552480fa72a1c23c8d8b5c7117
BLAKE2b-256 01bc67359f472b6d991421e14fb6911897892bccac8d3f828eb4e5d87d02b1c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 560892cde2277cedbfd0c59f16df31ed457013cb294aabe2d1e6eec1ec3dd55b
MD5 f91568f5e40bb0bd7ee0720b0bf26a69
BLAKE2b-256 2a4ad023bdef2c0e3db276ce3d4b410b3aa990f8dba120b1c3d2d8a94b538aab

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.37.0-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.37.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3d3c2dd1e408938856301161821b739cc8c34262b78abab814696b1420524bff
MD5 b6b4285656da1e362513b62bc1a7b6b6
BLAKE2b-256 798fd211a3cb6af4ce37f74cdf1b71dd94f92ff9e75894a05ba2169c31403505

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f5c5824490161b44b1e52d70ce3b8ed5d1b0ea0e05a32ef52cc98971ef08092
MD5 a57acf183a9bdd86d61a6a9d96ecb53a
BLAKE2b-256 6d21b3aa4fd00af7610c4a62b12b366a991bbfde1183d89bfcb333c28a142c9f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac2fa4f81dd2d1f72afdf7700e0f6ba82ab5b88d874509ca4ebf252ae341c3d2
MD5 23963dc52e69c4f69a312e8a75b91e5d
BLAKE2b-256 0b7ac39ccc08ed5f0fe365db821fc3cd6251a196e4ef9db3fd9a29e1e5d8f52a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.37.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca27b9a601b84029873a5e2f7084a4d088d209f543f8117018c5d176ea6978cb
MD5 6bf479f8f08f4b70a76b4dd6433a3340
BLAKE2b-256 6014d10bd7aaaf2e5e856500700607a6a55dac4e38555971333e5309adc937f9

See more details on using hashes here.

Provenance

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