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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pytensor-3.0.1-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-3.0.1-cp314-cp314-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytensor-3.0.1-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-3.0.1-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pytensor-3.0.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: pytensor-3.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b67cb91d2673531f4d44ef9bdb11b74a2fbf5aed4d02e4d3e2fca41c41e0e49c
MD5 611a519e9d21ee916019c1a0c7ac14b8
BLAKE2b-256 909761d79159294ed66b992732bafeb4e2aaec60e09e6ec1bb833a1dcb996cb8

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.1-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-3.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 14493182996e231269d15ccea24839f011ab4afc9c8070ef18a029eee54017eb
MD5 37dad1763ee69a9eb9b19dee6a0e14ca
BLAKE2b-256 d8b1de5fc1afd2ce13959f9088c55d72031c4cab60d4944a1432a2bf456f71a6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.1-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-3.0.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 640ddb2fd3862610f732cb022c6bddf0f44ff556f5f8c2a2102879155c968c58
MD5 e48af072afb9e3de1b842d87ec44f599
BLAKE2b-256 31c7f5c618542083d2d2d63ec0bf9560b0f8111a29162fde90593b2b884de82f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3df17f232d283a982acf601fe7e56a17382198bdbfd75dfea2a4417a4a037494
MD5 4589a16c227aaeaabe83eb45f1521f57
BLAKE2b-256 09f2ad8186600a4eb10147a925054b41512fe472bb22d5b1b0d3c1eab56853e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.1-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.1-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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ae4d50bcdab3424f03796e8ae6b05f9aa33584fd4a01c30bf3e9742b5949e617
MD5 6f120598e91d88975338c418a0056d62
BLAKE2b-256 cfa0e8e536e22887b25cba1b14aa9aab72c13290555bd00592308f1407b21156

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f10b31ced29393c45c53cc3464e136096b4b580015e4e56c23aeb0aef1098862
MD5 b2a9cb9f865478f14af0f392ebeec132
BLAKE2b-256 777d9c295881464d125be970ee793cd7e4b5ecd8067d3a10c81ac0ac7938e3ea

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.1-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-3.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 129045c929f55a94585d53c777f9b337c3a98989ae3d2995cfe147c70d1b6a55
MD5 c2c2f9afc5cd6698bd15f1527bb03b76
BLAKE2b-256 eeefe391f05ec2fec7a92b57fb465cf50ebc4746ab672ecdb57e42d8f72977c6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8cd22197b18c2e0fb64b3d591a7ec3d471a80440d55e46e4232afca4f7d6e44c
MD5 d9c89b6e3d96718b7b85abaa5e3580b8
BLAKE2b-256 bd337483e3c26ed00375be331d283245e11b69991c44d5e07e523142280aeb29

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.1-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.1-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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7186ede1544dbf4d31af34cb8caae550815228c54e4450883484d843bbe12acc
MD5 e50e7df45c6c780bb3bad23c35723f51
BLAKE2b-256 a48b968ea011c6281360977b10139991321381e81bad7fd8f55fb446cc5b9e3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 248f312f88388d9143c4f25e01ff3d0b000755e508158d0763e14fa602108d4e
MD5 fd86815e0910b59759bec3c52231aa51
BLAKE2b-256 5f3a024d5289a4484a47176e620b91f163ef83bd0f0441d699a5908e09d9df7b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.1-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-3.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d090526d2c30edc6fb106426b480383af351b03743c09bd8afd623c0f455b643
MD5 4273d89debd6341246a27551e82555c6
BLAKE2b-256 8e5e5027812d32c26d90dc234c1401a5a4007e101486b338010323487249d24b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1248f437306e997d248c2d7bbf7d1387150fa884490bebedbc4a54123030044d
MD5 f2614c5962211e4076c8b94ab3cc98e6
BLAKE2b-256 a2e0323646852e16b486baea00ba8ed15fbe301f5a01ff7eb309d589b2c9cabb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.1-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.1-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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 903b1c2ccbb3155e445d601682b6293cc8346febb64e670c65c74e744df49091
MD5 95ae3cf340e28461b8382d12ccfab9f0
BLAKE2b-256 e1ab5a7cb7c3085b022ce667121fdf8d25f2193dc14cadbfa92d64fd02805288

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1beab5e6e0cbb5d4b6fde23fad4bd68effa062c4febe4dd35d01cc7eddcd8df5
MD5 cef205e4e393a64cbdb176b1630384ab
BLAKE2b-256 e066e162d5f1e59708d9c6a8e026736831a9ca6c9abb5cec87d8a1052fc66349

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.1-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-3.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 73d1db2683be4c54be84ec56ee00c2c56c7a102491bbaaeafbbb0958e77a7858
MD5 f36f89cc31d837b1e9135c010f160bad
BLAKE2b-256 8570b4f7db85c9c0cc42be5a81b101f9b6f8f585fe2864d0104a79d314a0c9d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dbfa9889778a8b3e7352f79976a28a51c1ba5ec9a5525997c352ed7b9cd6e435
MD5 358fec3433a2503b0562d04232317306
BLAKE2b-256 eb5a644b05c48471215b69f52d8dff1bb6f1cf48d377ab8ee1f8cb1cab75e9cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.1-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.1-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.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cbdf402c03dee696f6c7ffe313b2443bf37498fe6b7722efc05ed25d9a775fd2
MD5 a3363c4c58d18958d29ed8af0ac256a5
BLAKE2b-256 8babb95044ccc3de036da69416565054dcbb0d8975db7a28939d7918427e51a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2afdee929b889a97d87136d718f002ad3682b69fd63a284fc6e946d2f6e2c2bf
MD5 fd8f44f636b73c07016d9cd56ba2ba68
BLAKE2b-256 55bcf6e459b757e39dfbfe0558a2b2f49dc0a335bb07ba30ce456821dc77ed68

See more details on using hashes here.

Provenance

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