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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.16.3-cp311-cp311-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.16.3-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.16.3-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

pytensor-2.16.3-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.16.3-cp310-cp310-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.16.3-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.16.3-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

pytensor-2.16.3-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.16.3-cp39-cp39-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

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

File metadata

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

File hashes

Hashes for pytensor-2.16.3.tar.gz
Algorithm Hash digest
SHA256 42796011e12d0cc17eace7b158368abb8ffd8df2df33195829efe4784d7db646
MD5 2f29f6b69261b3557673e5e96e0c6cd0
BLAKE2b-256 435402fba7a2558722a5d5bfd098a8972fb6e6f239bc945dae52b4dd98585b05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 56b9cbb642518e70ddef21ee1f952a5c475ee4ae7f7ccc4e9112051d205af066
MD5 53519682c286959283c0658705003d52
BLAKE2b-256 8dad4a2d68e459c1bf6e6e61bf801d43624f1e4a35e5e61f83b033fb0bd15fe6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0030bc265259b978d213a0f208ddfe977f0b48a0df41002926b2b6d8a857245d
MD5 be51264f297899b9ea27861364c15feb
BLAKE2b-256 2308190664eb6643f9d6a22b6e94d77edee1581bd59a90741b758d7831561ad0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 5c7823afd3408d40626dd3ed097edf544b963bb218e09f03b67dcdf352e932c2
MD5 0df786ec9e5ce958c99d34d4fd4ba726
BLAKE2b-256 2a64023c33bbaa008e5b024952d2ac6fe2ddf512042a94bf95e1bce749314408

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae0fcc6a8c441fa975b2f8682e575075800021d31e0e383d70b34d69c11949a4
MD5 6b05e1303357523035511d57c9990fbe
BLAKE2b-256 60baf45842d2b3b76689a1c55928cbdde66c0a2df2e19f90b2134c3f7f43c0fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2a205c7e32566687fde0e3e771a387a1f6f8be668b7c400642642368b6a055fd
MD5 6e9b1973e140ed17dae53eb61dfc9d13
BLAKE2b-256 1bb0d2ed5a0b7c45b02d758ddac77a3b35ab23c05ee20520ce752ff0311ada3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0bf456ccb576c08dd7e28d82cbf5bf92de7f2ea914d0d8c111867096c48b60ed
MD5 92362ee0e27669fc6b6fd504810558a8
BLAKE2b-256 7d67be639fb132f4eb11527bedc64f2b5a623e6e1dfd10d75b5bb9f2902dc6f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f85402f527cebd46645a591f856b451c9c307ae305f9454169e8a6b8ab762d02
MD5 a00bd5627ecd2d1e1ba0d42a5cc27587
BLAKE2b-256 2adba65d5e7f92ffe2943ebff3812ed5b671b22e2310ad625f9b68c55ab72f32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9bc85bab64af52f6f1dc67df51ca8722263320c37013393edf902b118a104bfe
MD5 f85bcc4076ab425c630dec19c0bd79c6
BLAKE2b-256 a97b6cddd6df366c8d023f9064c4c87657f5be79dbc3eb3e210c4b91f71a6fab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2adf83177b0ff8d60d08cd40d27a0e3c6e74046b1f2c66ad49340f56b2ad62bc
MD5 f099f7c5c20b08adb0dbeb0d0877d99f
BLAKE2b-256 96359b4d78f626fb8e28b16fff2443a7ef4884da46dbe35b8cfb15da647b55dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c8a359f6c70d83b2553b40defa447e25bf636b3aa0e2abfb243717597d4dafbd
MD5 3c4936ad4852f1b08837b0a795cda623
BLAKE2b-256 022627cc67a4dabf29da2110eb335408577634a562d5c884990650e4d8cd6c6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.16.3-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.5

File hashes

Hashes for pytensor-2.16.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 bc70b97b449442db306f3f7a90a7467ade408eb6efe5ca846b933796895a59ac
MD5 10f6c5c4a84f6788e16f536b868ec87f
BLAKE2b-256 83862159561dbb8e7443f154537d5ffa03b3808f9d5fedba5a23e1c1093a3356

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5a14023249a37b4c2b0f72e2346408ea7cfd39da867c792ecbeb6640c110e840
MD5 a5b04faff3508d252cdf47e11505cdcc
BLAKE2b-256 9f79c66bed4130aa6f0aea40255533b6cbd1973bddf83fa12fe00f38d5ca82f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 b310753c18d0c3e02a610c6c783baf8c2d12934413fad332820096a0a99722f1
MD5 c192f55da5ac141f21cfe690d9b60c9e
BLAKE2b-256 65e362c03af8e3ec4bbab34b45c81c3ec14897567a15b649e12efed12a140dca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f3b6d9cd62beb89400420baa7950c457f4738b6e496363abb5ed0388e567c57
MD5 3e35bba9fb5755da25890c5bbd1d0744
BLAKE2b-256 03142f5ed41a995b4ea0764474e250091716d93452d244313c7c1bf6b7a62264

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a338bd43933b6f9402d5e9fa687e29baf4efa5beb8da472101027e5753e7ba43
MD5 a170f705df56412ac80c124a412c1206
BLAKE2b-256 64997c72c275310f6df0b9cc34a7a1b6fcd7ba4f1adf755c009be9cafb43d2bd

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