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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pytensor-2.38.3-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.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: pytensor-2.38.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-2.38.3.tar.gz
Algorithm Hash digest
SHA256 6c959ca9eb46909a8a66e8648e2e90f9d80b4d288184401366d8fa44426e86d0
MD5 a4afc785698ca46f1e14e1484257d224
BLAKE2b-256 310bc71c1009cef4fff68a85480ab3f12d72354cc98f26540545612db0d836c5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.38.3-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.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5e51e84e82a4c7e14c47077fade2bffa97024388a2eb95167f4a33a125b4c83b
MD5 577e44428667bcf1d8b6ab20a4619f1b
BLAKE2b-256 ce132b4b61be1f38520818187e86d34c670cb21dd9dbe5e07fec3f514e519e90

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.38.3-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.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 baaa94bacacfe803c05def5ce6cd6cb19da5dc99d2c375b88c8faa8af2044bcd
MD5 3719889ebe7fc53ec54e02514b7db82b
BLAKE2b-256 ae6283032346254a8642512b7409c80ce3caecd0066cdf50f026d845122fb9e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fb483acb55773f346eef769709ab0f4d0dc2575cb8aebe78aef1f43b9e0be8aa
MD5 7a2974810c0f727f1e63a190db2f2b1a
BLAKE2b-256 dbfbf07aadfc36de5c9cd958ebd6c05fb8efae05149bf253065f7b760c4039ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.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-2.38.3-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.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d5ced5af2b93403f46d9439086184a714061e8931e4757f7d19a1c5ddf979530
MD5 770ba21ec99853d1ab3202ffa078a17f
BLAKE2b-256 62de1e46be4b3890afd38ead326def8cd136be58dea080fbe9d7794ee48b19e8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 226bfb9768fe1dab2412160fbdb2b6782b1e1830ee8c170ab8ae5a8062fe033a
MD5 89c0cfe9c4d4aa11d7ccf7f70abb9c6b
BLAKE2b-256 125adaa3adc446887084d0b414ad6afe181cc9b70e8561a78b4558066b482d87

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.38.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c075141a0f45e0cc5d5ac64b6af155082cc672cfe94f5f76bb077dff776d5e2e
MD5 c47263c6eb546780fa49abdcbe85493e
BLAKE2b-256 dce1c570169a35eb75de2ca55f183c897ca7da2500fac9a6d7d2ea01ad25df4e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 506efe79e1562c1aeeac2aeacbe2c55a301723f553b58c80a785f9872d78d1b4
MD5 bf5e7fa7e558cd44cb4a7f0881517a68
BLAKE2b-256 09db906689443c926db1d013668ff623ec58c3c0ac19b841653a7b8c97a2ebdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.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-2.38.3-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.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d11935b86d7d54196fbeec096cb2f908fb12deb798b27ce4fd411e68e3960c0
MD5 96c26989932ea15916bc5173c19ad185
BLAKE2b-256 508a71bed4aaa440b55feac62ba47811ad4dc36fd43a90047cda0d9af42af891

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 62f05c12581a7317de7afd36e0ce8c2c0ee538a88000144f75f6dde9c7a98c8c
MD5 7e9a4f88d82d0b422c9f2bbd886d3d54
BLAKE2b-256 48eb184ffcc39b47a0c233970a605915e901890541a4043ceeba4f9446c8db57

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.38.3-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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 68a0d63573f8a2c8086a2d22b0ef5f44e1d7d003aa799eac1bae35519255f3b7
MD5 845e59bd5deddc8ccc0ff09c895dab75
BLAKE2b-256 77bc2b34f121a8e71458457f0bfcea0efad7fcd950655fef7dbb36876b95a56a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8d5200a924bf3e1fdb3dec276aa9e275a882881b036b776506f19f435663e199
MD5 3344dc6d0494fd08adb96e2f3d0efaf0
BLAKE2b-256 6fd540692ea2d5154267aa2a5df626ed2f9a5789ab2ef67b5d1b89d018c5741e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.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-2.38.3-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.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd280ea3b813e29f5781b0eab50847d3646c8ca9c8919cb3afa072aa5d48aa8a
MD5 d434d5449a0ab63d33ed2f5851cb28a6
BLAKE2b-256 43cc710f4d3a603443a99a799af31e5e729a34859a6c1ace8da4c752e2a704a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35317edcebecea16370795345ab92da8b787a29e0387aa1d389f2abfe8cd0a7e
MD5 582a3df8090a48e03037cdcbb91e0780
BLAKE2b-256 0d9001c9b43098d6c7838a8a6f130f280ad58160bcf1a84d6de538912ec76cd2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.38.3-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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 68dc8a441428d2a70271bc211afe977df4e05c46f7679ca150d351897758329f
MD5 21043ebe0bb4b9adae04b4879fac7fd6
BLAKE2b-256 ff8e4a6b69249dd7381e33734c3f9f2459a923b0a96602bea9c83c61bc166085

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1a096b690921f25d4b04eb572290ea110e5f5467772b1ee81288db53d2bdcbf6
MD5 259137a55e73b560850c2e7fdc8b1b24
BLAKE2b-256 f505119b51f4bb422e870dd30680e57b45b160659c97600caa0478f7a070f844

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.38.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-2.38.3-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.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e65c6620741aa63c9559153aca81af59c45cc1b68313e8b2381620b1a4bd6bd6
MD5 f420b060fe26395021545faff5e7f6da
BLAKE2b-256 bf9ae957c6e70bffe331c586ea675876d4584a058cb7ec3e8610878f3b27d267

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.38.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c02c855d60903c12986f4ef7859d8fa302743cd34912bf8b4a040751ac6590f5
MD5 8e64a65580290ee3bce13821b6a83b77
BLAKE2b-256 c34f309b73aaa0ba442371d3e0660f002fe6dc25053f70a3aa143b5fda68e864

See more details on using hashes here.

Provenance

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