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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

pytensor-2.36.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.36.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.36.3-cp314-cp314-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pytensor-2.36.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.36.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.36.3-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pytensor-2.36.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.36.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.36.3-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pytensor-2.36.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.36.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.36.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.36.3.tar.gz.

File metadata

  • Download URL: pytensor-2.36.3.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.36.3.tar.gz
Algorithm Hash digest
SHA256 be81e3703e8fd7d3cb689d1b64d2ad2386ebecce9a1526febef08f979dc6093c
MD5 233dc582454e39407bb05f94b950c566
BLAKE2b-256 fcb45d32d2e43af0a3f5e864d6bf690c1ac3fec4ee66d48cf3624b2d4fd63d17

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.36.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.36.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c0f021ff99bccb21a3a30bcf341fca195928a0aef2abdf3a447b91c4bd2ad3b6
MD5 d4f0dabd4545d4b9e12b7e0bdc723123
BLAKE2b-256 c0c2748b4393eb6568add9dacdb9d0bd8c03ade0b57d3e530335a91ffb68f5d4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.36.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.36.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b5504de2dc50c379c492cc57d6f7c5a27f53da2f6404e5536f4fed0d57bcec22
MD5 0e7ef110cfe31363f175ebab3ecbe47a
BLAKE2b-256 cce45c4b4e5ae5d8961dfbb73503cd330f68923bbe65f0804f242d9641996fee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2b40b024acb87ef934e3022c4563caf002f3edb78922ce782ff93d22ef605f7f
MD5 fd07dd5540d70df15003c6cce99273fb
BLAKE2b-256 d5b2c5411ec4ebe681463a4bc95073f6dbb18e4d4da2a35b78148978bbca14c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.36.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.36.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.36.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6bc00a0d5685a498b152527fa8ed839997b57d5d8a3896053671b82cc75a9fb2
MD5 c3f6f400da5d67063b92f31517297aad
BLAKE2b-256 e62ff0736bdc8682e77ef223eac08bb6eed9bc7b13e9b68e46efb5e345e8b3b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5c273908eacad1af1c990c68cfe32674059ae9d6307b05e02cf1a6ecd1fdaec
MD5 1347567ce8f30faac61c7afcb9d70352
BLAKE2b-256 3b4fda9d242c8e848bc50cfbd8efdce18196d1ab6e3f63cedf17cea11bd2a457

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.36.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.36.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1571608d65ee2a17b6600f39ef2435f16e8e9101d9d302931a522fe9665e6cc2
MD5 ea2218ff6a4215b911565993b6cffee7
BLAKE2b-256 08100d454c1ff282906c2f9da9812afbd9ebc25a606668f77461ce2aa4d606d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 48189745710dc6c05ede06c4d578e8acaa58e9110b01312e52cb307ca58be6bd
MD5 55227866ed160fe33b9dceb6640497cf
BLAKE2b-256 03a84627686f3b7fea74624fb5044740fc586c0bdfea30652090b4b09c4ebe8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.36.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.36.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.36.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7cacea42763cdd487a87e37cb0ab32e536f751afbe3dbb41a09cecf247fd455d
MD5 5acbfe5c4d52b80bf39be70a2d73c67b
BLAKE2b-256 89cbdb63f46e272c83ade0561b242ea9f2a8f55213b4bfbbf0705d7ef96d8527

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 81bfcb369bba5477f63b597ffc4e79a3d8595bdcc466f0009b64b9b859a7be74
MD5 8b6479bfa596878c571c2cd8fe964b85
BLAKE2b-256 8f81474e94b9b138fe67866d2bcf25779eb3a790c30ccb27d15c5ce7be45bcfb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.36.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.36.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c074af86bf60d77b8fcdba781379356c91e79adabdea491676f4e2ada05a1a92
MD5 95e78f8f3fb25fe073551a4ce7ee29dd
BLAKE2b-256 40351f1f0bd11c1a2c58415dfb7b1e92f1e2e7b7df5b870b2b2eb487948c71c7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0965714b77d41ff4a231ff190302d8eae87c1f972f233eb380aedaeca778b347
MD5 531c9b651b41066540df35b347efe0c2
BLAKE2b-256 2a954f3ed0cea003193ef784f34f9dbb51d02b9dcc873167ed2a01fb6723aa2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.36.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.36.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.36.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 66d38d18fafa2f6877f58085bcb27dbda43d6e48e3ddb8c276ddbceb57f1cacf
MD5 28f952d0f115873cb4421bd6627b7a2a
BLAKE2b-256 02c0138ee1c757b6ad8656061788b320737ebc6ff610c1fadf1a705b33792c63

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20cfd6cbad243806482ece4b61f23e8ce7537f827cffb37d0cfe9b6ff4994215
MD5 0450834be2f7196ef8bc5ba64c58e07f
BLAKE2b-256 a4ac9edae8da07e9dabe228341284ec9262005f8e01d86d50944be05300bdda6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-2.36.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.36.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 00835ec8ae2e6fbbefd37e5e82b3010cf9c78f29a276e8487947649f696b615d
MD5 bf87ed61a5bf959af60b122223b8bb43
BLAKE2b-256 40c4f36cddbf0a2f697d9a1eef21f75a62d56dbb2259d38e48ae3c1ea843f0e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0b8623a65462f1b51fcc8a84284762595cac2d53919339c6a637704aa2544013
MD5 6e5ed53d5e878db1d7b2609fdd4c070b
BLAKE2b-256 b073aa2e3aebc154eec73ec6817f4daba8a0c2c8b2d413f54135769e233bfebb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-2.36.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.36.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.36.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 881d02d057e4e07f3eccb7b1d9f8ff1450e004569e555a7128fc867c7b892971
MD5 447f5bdcb609294ed39a164556ad252f
BLAKE2b-256 80eb5c93eac4c73404519ef05fd028bf43b115ea0ebffeec9deb229a337fc554

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-2.36.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 597a43c001884403a12b0819e27a9c37e0d4326e671eb64a1e1c25ef19cd849c
MD5 686faae88cbe4a8640fa4265cdf0de28
BLAKE2b-256 9e253bf125e057a9fa3a355f888476d7eb38297fffa7c591fa29c6b2ac72ff80

See more details on using hashes here.

Provenance

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