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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

File metadata

  • Download URL: pytensor-3.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 027ddb6af0a10f1231611d9242843f241bb939c4c927d63f942112dcbdf7bf52
MD5 79137717b2c3b131a477418dae2871c7
BLAKE2b-256 d939ab374bf3de7c8c00be7ca760a6959b2f5d12ec4134bd981954ba5168eea1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.2-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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 22a6d681c3927a3683035eabe1a64a9dff7992bb3398c9f5b5906b73eae19df2
MD5 6fc7fd6856a6ff372b917ac3e5e6ec9e
BLAKE2b-256 4f01984bbec38c4b89b6767892eed5c316869d8c31d506102d9490efde91e433

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.2-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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4088f66784a64bc946ff2423651212fa4c2ebd28177418a2c5f57ecf9c8896d0
MD5 fde6b0b8b6014af24be903a0d73361b9
BLAKE2b-256 773044d1fcfe3825e76f92a32acd8e4e6439356ff90bc260f85b9433f79c7126

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b3c74c95b1b3e15cb27e03f2d573b7fe6de7b87403d4833d156789a177fa82e7
MD5 39e6cdd1d23cbde9dd4351311a111dab
BLAKE2b-256 41df6ff73d2f07d7d12baf39558b13ec22811fcbfab05e08187604becba4a0ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.2-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.2-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.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2beb7d84a76581e72836cd9554ae609573db92f024d8bb5b32f3a85e4f145841
MD5 4249671e537a548ea16d28434f45e461
BLAKE2b-256 bb1fff47d949dcba8fb8990300af1cd649bcf0df6648a546431e38cf8dd190f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ad3cfd4c74b823a3448a0aa9b3476a5daec5497311f9abbc4ffb51c3e61d4fa
MD5 9170eef46fb17ef791aacc805de36d5d
BLAKE2b-256 99678a66a841eb80b880586849701d1c6eaacbc6f44844eaf956771b04bea25f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f2b59e85ce9683024e7e56c8522677d376e7f968be3694a92cf573282a532c5c
MD5 c0c49570d473b4eafb8aec29c3cceea7
BLAKE2b-256 58664581420820261e9211ee69737a7578c3b24a33430ff24b17003651db36a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d64595ec7a4a7eb7f15ac81a8f251b4c50ae002dc5e1bf715600f34494edc5c4
MD5 86f70e6ee443a6ad3686419ff1b51b19
BLAKE2b-256 e72db3c2b004b01fb9617118bfc89baf0601ea4845703f661a4e14eea32e57a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.2-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.2-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.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 100f285e676e86a34062e1e79ee59bc3011a515991d85c9d013215cc8b133d07
MD5 5766b5b7537fbdfdb001a57bf1fd79c1
BLAKE2b-256 f8bfd4b36b8ecc1ddda02027e4ce36171bacaf8a1ac4ec565ee93c6a392f86ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1e247c3ebd971b6ce3d25770c7f005c7dd76ae22ed09fee69f61fdc8f670c68e
MD5 9086865fa47f4fe58f8b1f9120a7ea8b
BLAKE2b-256 92085e76b5b8ccd8277641056b137444c192022af99f172f8b5e11729cad390d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2d03374f5068f95e6f59e9ecc2296257d01d041cdf3f945142a1489d78f09157
MD5 759bccf3b580692df89a14cd7f750485
BLAKE2b-256 c06710d61ec9db0ad8515835dfd835d72aefa2f6ed0d7dfbc04dfc178fc09f9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a77d8c4c1bce46056f599c52b4d421250296c44d192ee83337f1a2dce46aea3a
MD5 6c3206af7f2e6a076083a9e9af3c5d31
BLAKE2b-256 5dddd45e0c7da8411af364e7e6a99ec6641e24a566b678edf8dedad863a2405c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.2-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.2-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.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e890b4c0103f36549660a364fe777b6e8fa76b3f0dd9a555ce24f2895c1ee09e
MD5 99782128bf6c95c571a9182763967718
BLAKE2b-256 8fb41c1c927a587ac9a18b84f6ce0aac165a85adbe7288b3c2334f3d3c151d3f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76fe71d2e4205326a84aa096431168f570a7d7ce5b2d68dc73357e5edcd735ba
MD5 f5f5a6487d6b81321b5eb2a059dd66e5
BLAKE2b-256 05556c63f72bd1addf549031b3d2dc8375d4f4f8e53ec2b3c7cc39c137d3c24e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a753ad0407cc2b0152e297b6152343bb07c20415815ff5099f4b752c5fee289b
MD5 322962b34319cbf4b5f2effcc40717d1
BLAKE2b-256 1090a12ee50dd7287b39bc33da89f94c306cb09c9ad707439761d6ac70a554aa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bcdf0417983660968b1be1340d91de618c54e0367386709b58e2a0197bfe966c
MD5 2655e6ae87d8d648818b93b64a3b2d22
BLAKE2b-256 8022112369aca25e3c57cab149dedb8d04f0befc493123ff12a3c6829ebdecf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.2-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.2-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.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2702391ce739b71ec86a7f2dc15adbdf09cdb674ab0c40e589f8a1b12bd4f162
MD5 3d8b2ec04b8d07d5e30c48dda7a33ca9
BLAKE2b-256 fa94c03d4546d5782913989ffc737a4816efc8bcbebc43192d8083e833e430be

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df419f5367cc791f06ba0297af2889be00f1e1298ce917ca1ff440ce74dd9c94
MD5 465a7b55e8abd05b38c2afb6ea3d653a
BLAKE2b-256 f48c5296156cec683fdf7ecd348d1272f99143bbabaac737efe1b0bbe28a0b26

See more details on using hashes here.

Provenance

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