Skip to main content

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

Project description

PyTensor logo

Tests Status Coverage

PyTensor is a fork of Aesara – a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.

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

  • Based on one of the most widely-used Python tensor libraries: Theano

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytensor-2.12.3.tar.gz (3.5 MB view details)

Uploaded Source

Built Distributions

pytensor-2.12.3-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

pytensor-2.12.3-cp311-cp311-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.12.3-cp311-cp311-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.12.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.12.3-cp311-cp311-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.12.3-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

pytensor-2.12.3-cp310-cp310-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.12.3-cp310-cp310-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.12.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.12.3-cp310-cp310-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.12.3-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.12.3-cp39-cp39-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pytensor-2.12.3-cp39-cp39-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.12.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.12.3-cp39-cp39-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pytensor-2.12.3-cp38-cp38-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

pytensor-2.12.3-cp38-cp38-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pytensor-2.12.3-cp38-cp38-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pytensor-2.12.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pytensor-2.12.3-cp38-cp38-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file pytensor-2.12.3.tar.gz.

File metadata

  • Download URL: pytensor-2.12.3.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pytensor-2.12.3.tar.gz
Algorithm Hash digest
SHA256 fa82d29ef0594e0a2751eaad40882dcd6af51333c28be0d79c1d0de9f3a81a86
MD5 157f7f17713f6a18aaffb1a1af10f2df
BLAKE2b-256 65395c22d844cc22d1a99fb2cf8b6be12581f8370b58b0572e3abec34f3415db

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cad11e19164bb5728df40b66ae1fe9d2ad0b2e47d37d07ded6f1e1e1de3fb953
MD5 ff224352b81748eed4d05e619f85511c
BLAKE2b-256 540e01e193d9085032af028781eb772724389ccd3c368684180685a1e1085b45

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4c09eeb4bc14e2e023b72a7ddc21a417d089271f1f57c3dd4f7dce1ee84530d9
MD5 f57ba37f81fbee2545b8c6f774f0491f
BLAKE2b-256 df4258ecd7c7828e3c20bed29d64fa4d1a61bf33f9a904e59c922afeb2a5ef94

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 08a5f41814936243fcbd21fe8e18c787c567be21c7d684fc21a8826e96373a55
MD5 b21093a2f49ab841240d75567adc5057
BLAKE2b-256 75e776832ce7a3d801b21c3c113244963bcf3047abe378b57e8575ad43967091

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc91d5c880a6c3a835184a65602b10cd72237f7cc3a306b4d139420211ea187f
MD5 cd72dd20b828d44244245d11e4a5e985
BLAKE2b-256 37506c08842cf59817737bcda3e61f6fac67da023603c2535050725f55466e39

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 75151f3cdae910a096cea7ee4d86f6f2ea9948ab2fee25a31753bbadff331eb4
MD5 76112cdbed80365525dc761e1eb9aff3
BLAKE2b-256 66c87410a4e6222fe266f9a9140258f2d640398859d532f8edac687fb60910ad

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3171c2e962e735342a19a86ef1dcb1aac543fcfab150347e726c94cd6ce02b24
MD5 55159ab6b029451d992b2ad49a4eeb52
BLAKE2b-256 556ebb9958d8dc2743ae0e84c3e541150aa7e0287ad3325ae4f80992794ab10b

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1cb717b9a76940249df58a2cd521ca2bbdc340efecdbacb540c628796530a05b
MD5 063d79c534172364b681ebb2b0dd194e
BLAKE2b-256 4c49c7813187ed6ef48c14a8ff872965f23cb06e8082d2a93112aeea990bf95a

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 1036caf00d42510b3516b56b7132d2325960b6b294342cb9a2cbe3d4492c2a2e
MD5 c5575c09288c46c3469bf667bd6f6fe8
BLAKE2b-256 9e823988ad9159feed5ffd5794735ffc97d7544099cc0f295fb9df9b6e7f0fe7

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb5fd6c750d8247ec05869022ca37e52e59437ef871d7e8e7ed1c5df058699ea
MD5 275e870a7a7188dba1ae5ac00591955f
BLAKE2b-256 9ab3768019554fd26bba05b03f135da892de0a9c1be21666f2bc80ae2e315594

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 927821bab3617739013950fba0bf9d458a7075576360786ccc7e5a8b7d54f481
MD5 f1684cc2d6244f9b4b9e7dce796709e5
BLAKE2b-256 5599d219be9389bebcfcbf996b84ff52e0994d0b67f904aeef90c6dfbab689a1

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.12.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pytensor-2.12.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0e18f4926c85bfcf85a4815fa390cb65257b589221a47dd64bfe996cdea8f867
MD5 90d55ab2a6efda94a87b99b5bae75db6
BLAKE2b-256 351c4b08fb4bfb221cfbef5d9ec763bfce5f249b992474a7e144ea0ba99069f4

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 7f27bd14ff8a5ea6b4f24d92851ab37bfba03baa319a72a031cae7dc650f4d5c
MD5 6f69e1a13c2e6005427fe9a73458ba08
BLAKE2b-256 318b7d5b172d4f416030461b5f894bb3e24fd8eb3770cba704566da599355681

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 ba37c0d8b674c4e34a096c7c7dfaa46a0705023d8afc39ddfe1537ed69ef21ff
MD5 31868b7361f1c84acbe1fe0a7f5bf85e
BLAKE2b-256 f683dac25da4b5f0e530c7adf54604c32e210be93d05f953bab72565c5b43238

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc6848fd95befc49ff30174978ff3d8c2c22ef93c25ed61d31491769c2a67126
MD5 03f11fde3466e6ec37199168948f0f70
BLAKE2b-256 253f4ec70d593bb2f86d2a10aa9b54483c79b884a68d2709ce46719e3ab9cdde

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 46c48e48c9809b760c5535d6e91e96d365ddf909367afb74c29f541a5e681042
MD5 ffd15e93e63603cf4fffaa6b5dce8e59
BLAKE2b-256 4175d46a7b8ca6da9d39a8b1a1fb56b621804c2f822f0cafc7ca920ce277bc36

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.12.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pytensor-2.12.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4ca575080dd76c39bcba563410e73d23aa96f45f07f171adb71cade130aa8df5
MD5 045633ac5c155d6bd5de42eadf9686c1
BLAKE2b-256 5993506e3918dbf7fb806b76ffa06575b1b2caa9ba2ec4e986576b4f9561427f

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 30008db34a1dbd8a81a2cd6133995f7a275cf0691f9f322009263a5b170b086f
MD5 829dc007da5fcfef2de0b87afad5f023
BLAKE2b-256 9765227a57271f39be787f2a7cdd2522b9e35c8218deb8c4f2ec3eb169e2f3f0

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp38-cp38-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp38-cp38-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 83a2fd36aa87900dc18d27cbb4499dfb3c7117da0a2d1d0472f0ec03e308bbe7
MD5 bb8aabcef88f1b40ec4cbe4429a8925b
BLAKE2b-256 dd1bffa015a0e433381737baca41b00d708306a8ec5b2a4efd46bfcc1c3b3c61

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47ddde19efd76ea68f9f3a851cf2eaa0808ca939d7c565561ac931080e177062
MD5 04cc62937f9bf0b547b5f7f0d2ec4aed
BLAKE2b-256 1e90cc735a19a46120930388b482b7d93adf088c40443479703132fc22bca2cb

See more details on using hashes here.

File details

Details for the file pytensor-2.12.3-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 67ea093c9b81a55f191629ffc026f3484d5ee07894d020c006f7eda099b84b4d
MD5 04533d2b82122cfb4b77b361b65c375c
BLAKE2b-256 02ea46a37fbf456569186801007e72e32b46ba9808062e0b7e4be68c9ec7f84a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page