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

Uploaded Python 2Python 3

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

File metadata

  • Download URL: pytensor-3.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 341992e90ee6f8445ae047137a6c0c08e959da2743ee6669b3ffc04998abb5f9
MD5 96be38ae0ab678a053ed6a2b9e290482
BLAKE2b-256 e03beb2fd58ff39d9fe4caff1b76719804b97edb337f4e7d5c9b7404ecee83ca

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.5-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.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 95e189b3c597483a329e989edd6b5b2f1e6e50c40c694eb92a393c600168ef0e
MD5 97a81456bb911a131c6e8f6eea2a6192
BLAKE2b-256 86497c6567d23a8a71c4801f9cf4f925b8521eabd1e1527a68fae5e4a2606417

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.5-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.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c4d5c66b4f15d1bdcbc12128ffad9bf06f77ec539dedac14abe415a60970db78
MD5 b3812665f29868fbf03530255765a885
BLAKE2b-256 e11f705f39c4bdc5e4ced51e73ed8471f2ef1aa95a97052c571dbfc0080f7dc2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 68c80d500ab3e3eed86dcd70c8cdd603920934988252f3b85c5892c48ef40dae
MD5 e8a29d6289fbb86d5c1acd94a4e86ebb
BLAKE2b-256 372bfe7c1b3c82b47710d8801086e9958b4d33ba61c2b786832531dca7991934

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.5-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.5-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.5-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8112ed9b943640573fa80815bb17f3da715e244269391cb4b3b71903e2411a89
MD5 defe3f72d9093f4f3169f25337b26e41
BLAKE2b-256 4c2d89bc9a5d41969940f3a1845c0aaf6a4af4e141d2d3384a4b5cd12db3b8f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 070dd7301dfa12a30149a1fda09667191e8258f11fe261ea58f702305b83eee8
MD5 593db8b0037fb53e4552236f0403757f
BLAKE2b-256 320310f95c028d21d0bca6524fee42ad63206d74312dfc373c7ffd35df5dd9d3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.5-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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b291a4158374419a75ddb7e2d26042abe5da494bbf19de62597c05364e6127fa
MD5 c8ee68ddb8964650bf9545ec2e198a25
BLAKE2b-256 ddfb4801d3c1578cfebc94d7c59fcfcf7676b10362fb56a5f08eb551e0727d52

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 968347227d658df70e94ab747b33291a05d47b41157fe56880a478540729f989
MD5 8da22435952a96877f4093eab6cd8b64
BLAKE2b-256 b2233f0718b67d6978a95eac46b4d10a4e3c626bf0ae49e81579e3aa9b293a74

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.5-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.5-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.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0040ea089de1a123b718a46765afdf7756a680f6c33dea91944306e47fd1bff8
MD5 072d7f3ba6aab6307c5d930f7cb608bd
BLAKE2b-256 6a36252fb8a83f3ec7b54c112f1f4f97192d8287eec5f2aad76217c8cca67ad2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b65d5682974727522174fba5d67d21797ce85cc523e06f858b9cc068ccdbc267
MD5 f920398e661788c6c464d52b178b4a5d
BLAKE2b-256 69a1bc337c1ae83c500545fc365120df6b603c967ecb793de5a9370b54215492

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.5-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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8ee9b139dde74ed15b4a98cf67b072b0ae8a5b5b6ba52d1132b584766ebb815a
MD5 45313d89f79bc0fcc62f0edf5dd72710
BLAKE2b-256 372b623de7867c06a71500606b1230977b429f7d684756133a30d6817608ea91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d501da5a0fb0db66d35242de233b9d016695edfc068b8fd2c13bb28c446eeac2
MD5 77f8494f43d4a59132cb9cd75350f311
BLAKE2b-256 e96d766575677a2b0aed3c8f1c6518c3f0ff0768e8fadbb4f9c236c86e51ff27

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.5-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.5-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.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1e2de7b6132f0fcd7406a45aa0e877d4e766c1c5cf98d77bc1db0a93f9dfadc1
MD5 e759e8796aac4039af67e7295fdc2983
BLAKE2b-256 443e3e9b8ae7e6958e22c658707204df43bb7c82173a3b5e4068684b597f5a84

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48771f738464e786334ecf3456d81bf895781994e91ad001d08cae3df4b4ce36
MD5 2fb7004715b72049f25d086e51ed97c1
BLAKE2b-256 8d653f7729dcdb04177ccc10ea372e458f8bdbc0b0faef5bcbd5b2421e2aa675

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pytensor-3.0.5-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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7904df5c894a2d75b375b4856f2b726db11a91ce2453a82f59f6d5e6dac1690f
MD5 9dd3b6250865efb0a9c21fcd13c55e64
BLAKE2b-256 39fb0dd6be570ad02a20477645debb804a62ee30f7c9e3a3adda57acf26c5b7b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d86cc2ebaaa38c3e505cde9d14bd19dd81c59251db075620d34a3d73e301539a
MD5 4d6df0b91bfc025af70db4cffd341251
BLAKE2b-256 ff50e497d08c9cb075cef6e1fc1e33995eb9f85732b975f48d58473e67a80c14

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytensor-3.0.5-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.5-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.5-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 15be06bc9f4c8249311f39b4caf1ded371b5f5305395bd7c8a5f8734317a8f02
MD5 193aeea7cf7100c48b64dfb550392590
BLAKE2b-256 ccbdd977fbec37125b63fbc221963e70cada7a2a7aabe268bb8512a7d04219d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytensor-3.0.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bfdeef9a8a881b4d71f649ca416f499c20d8638f9db5cefd5fdc279059a5aaeb
MD5 9c9509e3384200389c1320c811f2eac9
BLAKE2b-256 e658ba2024979d1eb56f62f2e8d56103bfb24cbf781449fb6d7290fc09db89c7

See more details on using hashes here.

Provenance

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