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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.18.5-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.18.5-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.18.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.18.5-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.18.5-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 macOS 10.9+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.5-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.18.5-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.18.5.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.18.5.tar.gz
Algorithm Hash digest
SHA256 a4ef3b799eea98cdbc616c35a3a9ac7aed2b16e55570f091a400f0ff9cd0a12d
MD5 ff540311cccea8d2d5ef476c47f1a398
BLAKE2b-256 cd14f2303be8f8a661b4af4da586dd4ee286dd7c3e3f730a598c6bd5756bd2db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ff9d9130347eb54402b36c52b29e63f3c8d1823be7efa932298fe4085a6e1701
MD5 a4e3629775c5447cdbea2deb88e6ecb6
BLAKE2b-256 b958323599c576d2a28f0c0e597a0629e017db1931c1de6cf198c8e404993139

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4ec2a341f784fc4206fa56ba380ef423b99d5dbe4242333b938ec45edd8a253e
MD5 25391eb47fb27ea844596a006d6b671e
BLAKE2b-256 c96fe1d23c30e07675221fcd57124611c10d05d7992f08608fc5261c8948102e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9d9aefe7a93f3d42beb21e32b352f68cf0061460f30ecab0db4fceb3b10dfac3
MD5 1159d11877ef08af170617ed1f9f97c4
BLAKE2b-256 360394798776f8d5c04345cfc7e28ed0a6150501720fd2281e6a5a059c82af7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5fbf7d053a1be8ab1993541d775b72fffd0fcae59cb4de07b503bae25fa4eeb8
MD5 1646450fbd483a30365168b20fd9af30
BLAKE2b-256 14550acb333f2d35a0eaccc4d1f2c1a8d780bebc5ed4149f68f28a9da3687fa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c3f771d3b0c84b77bcde34a09d57bc8451491a0272e04c0c1fdfe3bcc0a1e01a
MD5 31efc5cfef2bbc9be070d4639b9242ef
BLAKE2b-256 c18bd315f72af37dad5e90bc772b0837b486ceb5d6592988f5b2b788128c21ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e2a89bebf8aa520ec6eb408c57312d1d3765838bb6d350d29cc758421cb6e02e
MD5 5122d337400fff421164a9d077993f46
BLAKE2b-256 ee3f3278e1719bb65f252016bf28b51cb09082d421377b3650b13c509564996c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e695ff338daa9979e729b6aac4167eafb2f528acb5bc556086b282479e916b7e
MD5 54bdc4d0e2b219bf56e0c6dc74facaa7
BLAKE2b-256 1627336d9f4c5cfbffa8b79aac96d8c144636a9d54b8d7a4c96d16dc828d79f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 ab2786bea9452d8050aaa7904f50ede5d7c21aabb69a817bbf7622b043ccf502
MD5 94ff1c278e40a0a196c84c6c3f5a2433
BLAKE2b-256 a08761525e41084d1d9814e6eccb80f9aacefcc2595c15c4e33f0a170e1fb60c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac6acdc1f310cc1592350ae1227188abcace51840b31370be2d731a7a1164452
MD5 4e9da58e2debbfd1a27eaee757100496
BLAKE2b-256 2079fc77bbfb6000b1f7bfe72f32883f32354bda4da75a139db79a4a136d06fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7830bcd53e45df7530c26d23652d2c927fd0cc687cfe7aa6e4491aea7d6abbc2
MD5 0118a2bfb6a53520e585966551171e5d
BLAKE2b-256 5bf09765a8e4eff5e534b4cbbabb6c73a901773878022a71aa076940bb1103c5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.18.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a17e9bac2304be5ac75c84069a928a8a9eb59366f7342a3ba8a6ca28ffe040d4
MD5 7ffa46726912cc2103757aa02f0c3d58
BLAKE2b-256 2b18d71c9f2b5d61b1b726bbdf602c10e707c69169d8cf2398d9b707cc8a5837

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9a267c5d4891fed3305da3354d1fe85f78ed6489127a2754b7899c7a974b5990
MD5 550bdc376f6a2348316e2cecb325a4d1
BLAKE2b-256 17074fe462b09893141aa56f7633e62fed276fd536899bf82e9e1706e6ad1e38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d9a3457745a335945ae7febc800d09e36e84f024537ea64bd048e4ade56d0858
MD5 4957955a12c11c792d0fe39757c20170
BLAKE2b-256 9bb6a9bd5b0f1381d19fe93d99893a40e7902aeac8dbe28c60c196c8f1880661

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af93f45df1398c47b7bb3c95d90bc2dbac6274069b0f8eca8d8fa6548211a079
MD5 a2135a7801e991ee2af9b7a1439d8c46
BLAKE2b-256 68e3768b91d5c6f6c9d17beab377ff906e6eec0c289e791b2d4492196a05ab96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 286f6ca56d7bb9d6d97742e2078a003ceb29b9fd034943c11c16ec00fbe59ec1
MD5 ab9b60a92df2e41ba2b72256884098d2
BLAKE2b-256 4f1656836d9e53e67cdb96b905934c1b06a039c3943fa7be6fafb5de4caa45f3

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