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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

File metadata

  • Download URL: pytensor-3.0.7.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.7.tar.gz
Algorithm Hash digest
SHA256 858df82fa44e5401c9e913e5acaa5e0044f1515db0290755a139e58e28f22b9e
MD5 bdb8c06f1484653cb60e75d0a1343816
BLAKE2b-256 5ec7ce061b8006c9518005488f9c25966f9bbea6068ceac0f669abc0e4f8f0a4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.7-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.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1f34367fcbf260c64f3756fce6531cba990b3794b5e5b8b8a7543e6cb43008f3
MD5 591bf17b751962b0717587efd2336d98
BLAKE2b-256 c8b62dc0d309fe9c309d4edfd5ee2a5456b2216077e9fd548a7d66acfed6de00

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.7-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.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 5bfbcc361e32776c019f07b7e38722b3a5a360622dada4b3567c22d78adcec13
MD5 093598241dfc80014bad0e830e323d8d
BLAKE2b-256 2bdb3ae89bed19cf752f037bf017f2dce0e178c77b5b49dfec83a1d06ec70bfe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5fa4eaa333e8b8feeffd47670ebff9a6639f05ef1c285b7481f6700aff933f1b
MD5 9378a4e0557e9444ba0a25480c9ca8b6
BLAKE2b-256 291988e2165ac883a7f1cf6f97e5a0405768de01b5d61fd140c13626f7727f50

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.7-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.7-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.7-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 89b9cb307fffc31e9cbf2be840884441d29a40bffbeae73ffc2c8752c64ce06b
MD5 b3231a36086e33471d9345598fdd85c0
BLAKE2b-256 604064ca972f98d7b81501573882514fa46694a3009131b49a481197ca12fe30

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b48dda3a9213fefb8a59da9967a306235a39235addd78c2e5a68130b48442a3
MD5 d5ac56ed46f9920e7c171e9157e8693d
BLAKE2b-256 22b03b2da9a17db7d38c7f9b527c76db0143005db40e40084bd3249f623c21a2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.7-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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8c2d3a4584e25123dbc6e0959bf3be18a23810b5ae3bdfbc8f2f77f91bd4dd16
MD5 ab1386de6a868b207a826b93245347b7
BLAKE2b-256 8eae7add143f07bbe6cba74d28081fcb95aa7d93f75ab8406b37628eb221a86a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1c8da496748f622e287926eb9107cf4deedc9b79a63cb1ae7f2d366f4992a3e1
MD5 f85e6b3f1989b64e15a3506c23e4e931
BLAKE2b-256 550c29e81fa57e81aac69d3a32744480e266707ef33eedb6fd6cddfd05bb28cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.7-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.7-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.7-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d68d0f294f1d172b979947ea9dc6471baeb6922c971658560de3e1eebe487ef
MD5 62a0d67b41e240364ee8612457e4ce00
BLAKE2b-256 5593fdc33a1cc0936b2f7e75176cf684f8a10a69854e33cc12b6f96f78a18188

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 919ff0130194fcba6c8a2d5f6f733b2cb10e0bc153661b26fcef8123fa6d6410
MD5 a00588a668ae5e70554d452bbe7acf2a
BLAKE2b-256 7af620267b1da97ed3faf9d98002794aae142fedef6a332ae7cf0af73a3bc560

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ae0ddade397dcb67212e5be42e9fb9aca1097da6f8faa26e9fb27e4f7442e868
MD5 f6c7922cc4b9de09de30b77dd8e8a30e
BLAKE2b-256 de425c4a5a11e8173f447f53ac7a29a2c0c64ffda0d67ff952204f4e19fe147c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2732fba00d60e85252e496a7ed11ddcf29153694c95cd65cb8236415c8c6e1d5
MD5 fb6155cfcfcadfc2c2a7a941cbb4a509
BLAKE2b-256 51b4cfcba12527766fa9cc0c4b71f6c64adef48675c8f3a0e40f284bc36ad6e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.7-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.7-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.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 929355f229c9f32696f1071a7c0acafcab0b3cccab45748e5f44519ae30a0310
MD5 dc681c96a15d14e5cda65ed12890a439
BLAKE2b-256 58a53b7e5171b4662b86475579b130d36129cd709ce42c729ded08b7148b6f94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2606cb54fa3442325f99f3515c84f83b342fed0da2152e91ad20fa9bafbe7206
MD5 5503f44a581b5b3c679f535b51a230ec
BLAKE2b-256 41208c57d5cc7e3e2ec3d8f4e8c33fe587a07d18754d57a02f75822ca5703bbd

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 228f0e7a2da4482cec5b7e9018249617affa02aace1b4982c79d29362759a662
MD5 a356eb70086cee9821b915cc425e3970
BLAKE2b-256 b6a315d35ca4c02dacd17cebd7f0703f3ffcdb6b79978525684df67be90a3266

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 99c39714cfd63c8a2cfd525f8d714b179fda741202f58cfd4bfeb4111afafde9
MD5 f7bc93f5ba044063bb0aabc1420a2744
BLAKE2b-256 4d091fbb89254111bde6121b532be070772bd0311de310bf8d303384c7fd253a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.7-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.7-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.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b65505a9d36d4e6d7edf22702f3424d46a133bf9acd20ecb7547045e020a2f55
MD5 7b05207207e6fa1d844030ff8cbeea8c
BLAKE2b-256 6126e997cb283a935dbe013b0b3958a9286fc6be82810a6b9d4b6193b58a04e4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae0e65919de6377a26d6c42a2f4bf331812bd9cbaf61f12d02b036d7b92bd8e7
MD5 16e61cf570d9897d4a947d30e5f35233
BLAKE2b-256 80db30f1575fcd0254f3cb038d544ecd3bb36f2cccaffeb809d7522c04dc1a98

See more details on using hashes here.

Provenance

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