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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.17.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.17.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.17.3-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.17.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.17.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.17.3-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.17.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.17.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.17.3.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.17.3.tar.gz
Algorithm Hash digest
SHA256 e697fdca3f41bb4c4e4696ef8a7e5b4fe992db0a643d2b161e5f0458ae23ab46
MD5 1eb2e71d82f1e86703338f3de7b4153b
BLAKE2b-256 650824aa2e46c2150d3c69eefadcde6b70723ada9bad3ba77cbd140aa49ce134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7ee098606b56aa3bbb75281caa8f2c3beb662a23cd86043b314bb3b2bf2f326a
MD5 6f63fd0d6b57785d3174176a613feded
BLAKE2b-256 b9dc02310fa79e41fd76870e80905612b6fcebc4d3e9ba1f7f510b2d29d5a998

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4c5459056287e5468ac48173beb0779a56d47548233497fe1949261bfb9d39c1
MD5 1563849324a8d3de3ce8442a46b807ac
BLAKE2b-256 5696719432bb450bff124ed2d567149d51370c424009a79b7c730ff891094834

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 fb4b2d9793652f8859f71435a7a409d3b53d7b183ba0c2c2534bdf6fbb463fe3
MD5 91bf9ac13f17553784b2b73505c2b641
BLAKE2b-256 22aacdbc0a97a1dd0274b308ecfe3210056abfaa46a481548c346e7a21568df0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94deedf8baf0c84981f0d324b8118ec7b0423ca8213145f26728a2733cabcdfb
MD5 162d45357e550b8bce6de820e9a618bb
BLAKE2b-256 7484ac6d09bd83dd2a2d1ecf1b972564e840a847608d61bf14837665b0a11583

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9339d205f4d8d6bf14955cb4a3eb3a242f2f9d20b355f7d8556e82c12935534d
MD5 a518b674b844c48d6506a39445e5cdd8
BLAKE2b-256 33e4e7234d87c60419f8c1da7f754500147c681c97ab8549286270de4fde27bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 436fd5b967e9ca26b298534179a980ef2c8a3e32daa23fa7995df86446383508
MD5 16b36666dbaa730b48b139dcace01c71
BLAKE2b-256 dd80d8f35f9e9e37b612f3248e9af3675a6a3118215911823e93094a1869a2f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 64ed96268b15d227e5ede9d42e4b0f5571ed89f1a6fb1a11ee7f4dd0c428926f
MD5 4cc736c5755abaaa6c65651f61d18898
BLAKE2b-256 7362e515adf884999bf593869d22d82102127dac9b12886924e449d299d19507

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 a9f39142c09516f7bad692560dd2aa323f09b72f868e8a3f75a28ef6b573d8db
MD5 200015e3dcf4cfb91cfd6b905b009061
BLAKE2b-256 7d9041e716fc5ffaeff434a4aa08c352c18faadb652d5baba2d84d4b161e191a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45ad78ed1ed2e0cbf6ebfdd7108ec406081c27dc2b64384c19c5163147b9dbbe
MD5 e9ddf4862bf49004f16b7e3879b4dc1f
BLAKE2b-256 240ec381eb81ffed06930ee6b5bba718e47d563d712cfc09ea4dd053d7e494ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5ec22d7f85b949134129f528e225869e958f1e1c82ee1fea415d5dbcedd222c5
MD5 e22ad0fe09474a8471ea1ef1d0e7fb0a
BLAKE2b-256 e9a1838853bfaaf5741528593e296e4fbf8069ea731e49e314bccc2040200ba6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.17.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5f6d9141f2e8897c6f6fc52f29ffc0777603dafd35b26fa8a74959796d7556fc
MD5 333f184265b392d713644fa807b55c7a
BLAKE2b-256 7120c7b6eb6d72ec585a3e7b7c63b2f7a53a24358e7c83b373f1d200dc4477e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fc09cf56642bb9fc771390dec1235ad4887e8e758d618a577732181780a92bed
MD5 9a1882447dfcf6a89b870c386f1caf50
BLAKE2b-256 e2aced5753c3d05cbe069b44114b526e8211cd1e3170759b2dd4b648638b04f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 7039ff000c6c19a108925be2d432ac7187982fb88cea6a1acbd6a946d75c0bef
MD5 c80f475647579537f6085cca208cecf4
BLAKE2b-256 32d676d4be732f11e597afa3b9e6e085100a874bf6e4242de51729f99a1c371d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf99668c203d6b8b51661a1a4a785ad6e7d7c864c61c37cff90c854d962fa850
MD5 dbd932fcdc17cacf9bdb94fb3dd357bc
BLAKE2b-256 963305201c0c60878082ad5cd9052900536dc6bf5b8b8822771e33890b15f14d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f6dfa4786da8cbb51460f602c16d278339d981e4f1cb7ef8373ad3b2d69b8f58
MD5 d5ccb6579c5ff60df9eef88e06e2731d
BLAKE2b-256 597c31ec4f1e816fc6a57f6a530ffed073da9329f52b426b4850a6176fd38653

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