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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pytensor-3.0.6-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.6-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.6-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.6.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-3.0.6.tar.gz
Algorithm Hash digest
SHA256 5ee295c4c06590ceae4103dc8e3a82e42ad3e219cab0ce95984ff1015b160bdb
MD5 81a58d6ff04edb592674418699f51fb4
BLAKE2b-256 7d957bf94e121e4ccef98923b08a93b2a999e4dedcb5bbe26fc89d055869a06e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.6-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.13

File hashes

Hashes for pytensor-3.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1bc690aa525ede70fef37ee01bd7c4c386dcaefd8e462b1d4522c6e7f00ce091
MD5 845411e591b1525c045c5a66ae6354b4
BLAKE2b-256 93d959202b971bb55cd0004705d090f69fed9928ac3c7c0047af1d02eb249e14

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.6-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.13

File hashes

Hashes for pytensor-3.0.6-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d94977e3770cf84e74a34559ed533e97754958c052c45a262d4d72d601a2b384
MD5 8511bcffeb860362022cec90ac10ca03
BLAKE2b-256 4e3b4f30c3f9d7f65c76c1a28a1684d58e5124dab5c339d581287ba6d8111311

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3ebb3cf2180d42a9666fcec0f5928fe2405965560c176e7aa4a094d28d730b39
MD5 f34494cb45eef46dc52d4d61fd7b82d3
BLAKE2b-256 e1cd93e4198ff9af6d72b3abddc320320956a9285e154864e750035ea2d0575a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.6-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.6-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.6-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d7393c72d75d5b6836a6cc0d6e27849c14b1be9ac81dc70c1eedae9a38739523
MD5 8df13265924c327d917ee1a7fe1e87ec
BLAKE2b-256 604025a36a1281562f068d98da9bea044140bd251e1781fc7f7a0f628f31292d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33558fa9ad8aa590b9b0eeedc9937cfe3c4f3ecce64b37d34c1ac18b0860d6e2
MD5 83c97d90d455e9092b1bd7d986d815f8
BLAKE2b-256 903193b348254037b2aea66b3e70ac734f7910469b76519c6f47fe1537b19d92

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.6-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.13

File hashes

Hashes for pytensor-3.0.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 95a5b666335f02fbd6313d53a87a270a8a25ae0238444de242181e1588c7ed16
MD5 e98e494b2911c0e9295c22c4fb5b6fc4
BLAKE2b-256 1d2a305419667ae941540ec7ac1ea6e28202efd314c46368adab3ba2e02f7903

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b83fe2609f885c1c63a5f1104428d100243c7d8afa6d224ad3d740d6815a6603
MD5 c0ce148af6b866cfdc6a3ba0376db67d
BLAKE2b-256 29418b2bb585d6cd4e12e04d1aff8a731054ed0ff1389c64321acd552bbe03a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.6-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.6-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.6-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e1563fbb31897d2ba36ad3da18a36a8bc8fb61ea49581572b9ab10d9dfab6979
MD5 9075f952aa7fa877c1860ef595591f28
BLAKE2b-256 7b5a52483c8421753569229d755a6a1fb58c9eb1cbefc39c7d49a92470da48ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 153069025bec0f2df31e3761634258de20f80fb6bc6bb337f5b313265efb21c4
MD5 531972b2a3f55a5ab782b35eb1a9f4a0
BLAKE2b-256 f9b127a279475f69e74cda576d998b2cbb6a880e1a60e2a936eccde8adb158f7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.6-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.13

File hashes

Hashes for pytensor-3.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 874d2500b0ff20c295af95853399afa1a9767129bdaffd79f37de5b08f554a5c
MD5 86dc778a8d67a002397ce872dd8e5f66
BLAKE2b-256 6d0035e8bc20a3e56bc79b1f5697c5394c63631d3a709290425b1bfeeb7f25e8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d95478022ce3d62018f4da3612d76a4748416eec9c59880e2f078eb2329b23d9
MD5 a59a84f9b8c550b1a684cdabe4aea583
BLAKE2b-256 7f143512ca0e9bf5e6d9dedc194dfb3703e01afcee1a914c93f824163da83f42

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.6-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.6-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.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8091ceb88c7e02b5dd9f30df3c4c3a49bdf4518198a4122832c17ea2f06b6811
MD5 8bf394823f3f273215cb978a0645278f
BLAKE2b-256 c03a25a64eaff035eb3f054a195f31248afd4e2c5ea594a99649e88e26adf9a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a98660840b46c609aa831d9aafb69015c61e3820efc653ea985d6195a449b90d
MD5 5e8261ec317c7d588d91860c34212ee7
BLAKE2b-256 3d1e88af967ccacf7d0d13bf1e522a1efe470324459bcee0a86ac9e9b48846b1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.6-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.13

File hashes

Hashes for pytensor-3.0.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 00eeb216881843467f3e820f168a369a82c29cf3122080fd4299512c3c5344c0
MD5 5e9987d0c2a3d2be72fea857ed8c1679
BLAKE2b-256 d803390aabace40919354a573b550a889beac5b21f6a8171c9da8b08657dff07

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b2ee3fc709a2130d6cf8a2ea5b9a18d7eddd9c4bfe63cdf595b107486ec49ad5
MD5 a60b243c7fbe8c0054854764d7f5010c
BLAKE2b-256 61ee036c1b8d87a47a67b609ebe04129969da673c6f026deda250ef2e6d289bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.6-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.6-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.6-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c907978f556549c6289598d56ad220a0a3c8411823d4968c77ea86adb6c69114
MD5 1fe071d303329d57a1fa3badbccb2a49
BLAKE2b-256 e13c2b832eae48b8a25e6a867f8dd5ffbc4c064c5bc57f8fb9a20600d6a13d66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84e6647f8d7b36bd163a689db5fc8fb63312de1c91d65160428152c93d8f8c8b
MD5 430c22654d1efc5c48ed3e3e964f2444
BLAKE2b-256 eaf3eff61996ef402fd398ff5c2852b3736eab00145d7b9476aef5a7a1a04715

See more details on using hashes here.

Provenance

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