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

This version

3.0.4

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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pytensor-3.0.4-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.4-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.4-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pytensor-3.0.4-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.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: pytensor-3.0.4.tar.gz
  • Upload date:
  • Size: 5.0 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.4.tar.gz
Algorithm Hash digest
SHA256 9a6a117eb5f73d87d9248bd7266e5b274973660fad699090835c6b92b59f1df0
MD5 b0b327cc0b090ee31e834e407eb53a4d
BLAKE2b-256 9701c9acb3ce54429ca32607138e00acd08bbfc76e89001de70a4f0c00249aec

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.4-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.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8b22ae830d77477ada455324e21ecb7d1b054fe59b612902a967e9b9ca76350f
MD5 56ac62d9af848d9eb8bf2845244cea4c
BLAKE2b-256 86ab7d80c79be8375e8fc51a9e6e399600ab138e31ad506d5c2a428498c0f27e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.4-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.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ed9c697630054ec0e1846b81f325d140f44e5022b0ee2f52781a95c3575b6c79
MD5 9c7bba3da3916efc0a938375332bd044
BLAKE2b-256 b07e1adfd3b28836bdf656f84dbad5e70e9387a6705f39a2b9ce0420d0dce63a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e350ee594fd0ab5ebce95301026a7b9f363672f93b861aebdc52d84f4bb4347f
MD5 cb406b1d4f469c6fe0beb9e2d167d3e6
BLAKE2b-256 ccaa8ef7f1bf08e5d6744049c2a00d7ba619527ab441f64324c8bbcf6b5597db

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.4-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.4-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.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a02f63bb8883c1f8b7adca65bb39d5d05124b3ec5cbbfe042d8c58b7dc6facc5
MD5 0f9dcb3149ad498ec810d810dff0b5b0
BLAKE2b-256 60e198391dcc5a61829c24ca2e044ab0da054104630481d3ec54ef5c70f95167

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1af5637a7dc248a49cd0cfb0ce09831f4bd90292255321d7104d598becda3ca4
MD5 25d450865a9015872a9a3ca9d48b86ab
BLAKE2b-256 c1868f88c09c1f9071387046cfa175fb9ea0a53fc8ff484c3eb3fdecdedf7cf4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.4-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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6d835880db5441693b94ee98daed0639f7d14c3fb4a2099fc51bd53b4ff9fcb4
MD5 6a5680ae51c1c359c905420e6d8a4fe4
BLAKE2b-256 95b24c1625108b82689701e8ea673b3c6160350342998012913453c92914aa01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f3cca6b38771f2e4ba2e82a893c471ecb7cd4d4d92cc6a2d6c0d33c47346aa8
MD5 7e184f4b4b8e3bfc9297fce9cd69df9a
BLAKE2b-256 1d9c8e2974150044fd6c6db30e2f67084087e95a73b2f667d7f5447a69f36536

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.4-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.4-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.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4f27a06442a070ae1002a8ac34f26984f55aa22f190ea497efe94238da653762
MD5 c6adf4e41c84f158ab29b679ca829c47
BLAKE2b-256 4a6c21c0796bc327d62e3e989bf9300f57f0ab0360727ec9074dbc7d19d5e6b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 469bfe5063c4509cca54416007b2cbf179c6e23ca15f0ffe7ef0c03aa221786a
MD5 b669b67536bf29f8a175399b6c8e71d8
BLAKE2b-256 b6c70e82458f093bcc9fc786c844e3b5e009312d6b3557424ba94a2e89689359

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.4-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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 06177d880a6fe71b54b63e67486bc1ba7b56b81d52e39c59f6bead35193e0a60
MD5 bb4fe7e51b00bd2edc764303b34aaf0d
BLAKE2b-256 b652741c6e5b8ecd093c6cffb89468b1e71ebb0d61fc33db996613661c9e3ee3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2dc180abe49b5d100a8945b2a45373eb884db59f63c5d60d08694338005eb61e
MD5 0d9ec6bf5b39992b51491e804fdecdd2
BLAKE2b-256 3a4de1d81bcb94f87ce9753cb6815f75abc53c4dc7daac6ae81ff72124619b4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.4-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.4-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.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fe9e10b374940a403e0ed7261489d1618d8930aef1628de668eb6656f927710d
MD5 8dbdf5578d536ac460aa16b3253277f4
BLAKE2b-256 d21b5488032f55239da9c45530e83e386e8f0d9caa5728eec43eae10d1177924

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0632fe895691ae1a98f9129d4c3be738afba06e52bbbb11182aa1015ec4c8c3c
MD5 499ad39a80196e9327a0742c877f2a6f
BLAKE2b-256 461e08066c3d92c8ea77707b60e58ccee682ca6fdb2aefdd0ea9090f492e5e7b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 49ec81d5a89dfee16a03a42fd74ad3b65f844e1ee4d04f295ce60f041678ea59
MD5 352f66856a3d4005ef1c22b7e594632a
BLAKE2b-256 91bb15bd08fc92e8da4374729044e70bedd398a3f8beb2afd0c4e510ddd9948a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 11d9e68fcd2db907e69944443183f4f3b7ce2bda726d02aae031b74b4f649b1d
MD5 ede8af954213362a9e2b04a5b94e919d
BLAKE2b-256 28b62911677b95d6ba4ae7dbc553788d84d172b9975f697ad3fe55b1b0e50ac8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.4-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.4-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.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd0b69dd4f4c3390f01ba7c943a721ea5d28bda851819acf55312200d2450ca3
MD5 40e441856f4f79dedc8d0d5102d8de85
BLAKE2b-256 46e861fbf03a5bb992780cb8c922d9bd1e2f155c48c068caa97092ba34cbe879

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d5ca1bcdbd1327975b7d3a801e6ae7c1949f4553d9554ee3a4dc62195c8e8db
MD5 f5232f728f5332b46e1a0acfae7df1af
BLAKE2b-256 c8b32ab357c2249abcacc5435bedba326d8db8c9fc2eda93761427331a282184

See more details on using hashes here.

Provenance

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