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.14.2.tar.gz (3.5 MB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.14.2-cp311-cp311-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.14.2-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.14.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11 macOS 10.9+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

pytensor-2.14.2-cp310-cp310-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.14.2-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.14.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.14.2-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.14.2-cp39-cp39-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pytensor-2.14.2-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.14.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.14.2-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.14.2.tar.gz
Algorithm Hash digest
SHA256 dbafae9ce4264e0e5d1e02b2214da3187ca51e99f43a1a2245e5c0d839cf3dfa
MD5 80c90e1e90ec0b16def742113a2acdba
BLAKE2b-256 022d53dad137c8a143ba733130d763e97c19d7a942c4bd55a72e8b90ad1b4c72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3298343190805fb8f17d8be9366f0a47ce94a6b647980afab8f7fac144b7c701
MD5 aded928f32fda7623eacd473c3e71476
BLAKE2b-256 a5df614de28b44d81a64c4040cdb473319096380120e77b32320ca87c2b9693c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 162a69c279169ba6f4a8b8d1762a2c76da8ca0237cdc627a02a587752b24381f
MD5 d7a4a7ea1d8daa98991ebf0f26527348
BLAKE2b-256 cdc8c251fbcc03ef17d8a45b845338b53fa549995dba84576580d55ea46cafad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 8047dc6a9f356f8c6e5256a517879655e04c962554d555204a224fe5d4a283dc
MD5 e7fdd62aab42c160d1adce6d235015b2
BLAKE2b-256 c9905506c49b546a8a53a25b941a91490c35b13530c151ccf7042abd2b9942c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 77dc11df11d063ca8f49267e29064ab4e24b51336635c732b46065d1f77b6876
MD5 e72b99e9441f50e82ce9d4c04e62e48e
BLAKE2b-256 bf3b8d40ed7955022fadfe2bad8ea2f2a7382478704f7c39b65ecc06fbabc8f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c1bfdc8f68c18b54fab29361f0b414f7f8625d18ce45e429eac01b08a0a0efce
MD5 189ed124f2a565f131ddcbab3752382d
BLAKE2b-256 faf24341436326de244a0bed3b50e36c9df41edbc83599a408340037832ec322

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3bc7b89fbe08b397f65f0788054e48225b664d81aaa9ac2950bd84b5f000215c
MD5 578e4b902104e1608aeeb5dbdb299875
BLAKE2b-256 5bbf26bdeafd336738ad973eabcf9918627262de4314c4f8ee934eb3496c3f4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0b5f70815b100467e3f9d27bc0e6727ba5aff0696422a311ae0ba4e05ff1830c
MD5 7b7705b8232d88c7dfeca64266639610
BLAKE2b-256 242686114b84a48e2238638ec4a61aa8a0bbd25e69db10a09173ab7b8b2b5fe3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5949e59efeea36b645dc946de55210472adaafbc4d2dbd713a60ebb2bd2ee592
MD5 bb1403e128c0a75f76835e8d58c89567
BLAKE2b-256 bd06bf88cefb6e6e17f6e3c438fc75ff851491892bcfd16f8c44c12e4e6dd5da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c945318cae0977c28a64ca528ab3ae3061ccc13b457e28267078a5376866dfae
MD5 ea1a3b1b883cf8c6194ac1968f5e55eb
BLAKE2b-256 d1dead95bc9180811183349f752e1eeb1ea1d8986e0ed5a7bdf565711418f353

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c6c9451872b06624d901f82a23472c222afff2bd375c982f667d9a4d29a7610f
MD5 10f8471f7bd5e14d749627d25af923f1
BLAKE2b-256 8328901e300ba7ddbc5ba6720ac0a3dba53b6ee77ba0c161688a025ad932af37

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.14.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3dfbf59d9370eb0077f6ca0a2947753536d3a92845f255e3b10243be990c1089
MD5 d15399247543e5ff75bc6e2e0472bad8
BLAKE2b-256 9b11bf31854bfda4b472c083764454f42be09434dc43e3527e0684f7915287aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 adb7971df6914c149904fd2b6b653c705a1f6770707cb9dfd94c64f85aa366a4
MD5 555ed55a8caf52bda8a0188417c978bf
BLAKE2b-256 c6641a1109c3f0c6504b1c7f0ee25b2474618c7a3a90390d6be873cccd253ca9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 bdfa6641773d0eb0a63801f8d23061e140c2ef849d72c59ae5b71b2afc42b38c
MD5 ba4bc4d8c2451e67cee8a0815955768b
BLAKE2b-256 657215003a9077dfaa3cb5843afa05f3fb18d508b1197fdf3ad4073c7186817c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b88893cb98eb729429f1429da8a81c13bcc2f5823eaef149f069a5a6721f4ad4
MD5 04d72f29e3d9b54191f507ceb2b5a1f9
BLAKE2b-256 6bf8e53fad8892fae710080713ff560f77673a2e7e411b41020c175e508578c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 10395be847d4ac5553118b19c753cc64f614c691ea47c7d91bb511997d26ceb2
MD5 4c15a7808fdd6c457d4823a2b6b5ceb9
BLAKE2b-256 cef110430d8b552d84510c2f098a83b662d867de245a2a3e56c43afb9a0e9312

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