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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.14.0-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.0-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.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.14.0-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.0-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.0-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.14.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: pytensor-2.14.0.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.0.tar.gz
Algorithm Hash digest
SHA256 70e3570d7e63dcc8ac2defc424f6cbd63ca289ea433a96ce24cb3bb981a6b3c7
MD5 be4464c23d8aa5e634721bd1197f01ce
BLAKE2b-256 ae851a6fb78518573c4392fa6ddf7c735e6173afbb672ed031f33da3389a0297

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c912e686343463b2fd5c5a3a9b210d64f38af55aca7d960d0318e36eab4cbf27
MD5 d11aa29df46e48ef83a18599a18f5fe4
BLAKE2b-256 22b518b617a11565a4f7d8bec7b0bb268915ddee2240bc510b37fdefc373ac87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fa56397c647f68f28308c8d0577adc9b7f78b9e642c2297c013805afdfb94640
MD5 8d5c5e6641866a5d530813f1343a72a1
BLAKE2b-256 3e5d1dd5518000dbda3ced32fde469d27f6d68e84bc741f7b1ad9dbbec248ec7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9853e05b1603c18ad9f4f19f038870f33fe7a805d459a68c8a084139f494a5de
MD5 d62b557684cbf5d108c53d67dfee6070
BLAKE2b-256 1c48dac391d8befa1bffebfb2944f7717789ed5833b96e28620a73476d3e26a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2458083d0392e7e06725ddccba8b971eb8e18b99a5b40e44ab62afbe488faf30
MD5 5de17cf73104a9d9dbcd27679d978649
BLAKE2b-256 eb4cc6ed3015c3dd198fbabc619ec51ed9da92ee10e11c4167cbcafe000724da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 398ad414c11151563f30aa62795d5190f4eb6883f0a262423962b23709186552
MD5 1b4629078b06d10a1289e2a538fb2741
BLAKE2b-256 f973961334336a21584868ed0470c43837d123fb3f96b956ad4d732925465cee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 80118001d5e1e35cbf29f1805583dd3ef97bd31c463d372a51c7f48cc9a3d3cf
MD5 8dbb52effaaa008cd10054cbf0d0001b
BLAKE2b-256 128f08d5ebe3fbc6b9207ef3ca8a5b6eedba952c623c86effc921400278fdd4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 59709e63be748f07f000f8d81e8a5990e89c798d17dd16e95024492ad892270c
MD5 fa55e25f733149181d8bf13aaebd0a3f
BLAKE2b-256 24fab6d8055b04b7e0427f2c13dc3700a0add7bf79a0ee15edc603f410641f3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 c92f3c6d194671094932b36a229570db1209b1b05a9ebea6dc0a50128abe5dbe
MD5 5c63dfdb6ae3e3318d467a5ce8aee10b
BLAKE2b-256 7131fa239e57623cf9b55d7909c5b331dad73d0b4dfa48c5361c3263c1f036ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06790531f01ec810691d34eee5272f5817a79ee5fd8542d96950063fee969d44
MD5 ba9efafee4bfbff98fc7a503a8624cf0
BLAKE2b-256 dbbe38283868702526ea646c226257b477fb72a811ab586730d94ab574c54920

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fb4adda2519b6048acfaa3c27748af027a57dc0833e4d4bcd5106456a71eb83b
MD5 3e86a7a887cde9d9ed589dd23567b1ce
BLAKE2b-256 e2591bc701b68c8925fa7246b9d16e4a697340113fd6343790fbc8a1af94b339

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.14.0-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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fbd1deb24782b7156e03c608c397ee05e576fa04693fb4321c47e35e6e0796e8
MD5 e24003a44911e40125b53ef512b6813f
BLAKE2b-256 d88b152481d43ed0e9f9eee3f454132df1e39ecd78c3aad844afcf69c5f8630a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 58a8ea7dad6a1048b71cb063e95e4bdc95f3b1a58bfcecb09e7f42a8eb755d2f
MD5 4faafc7e3650e463b53f68b6c3f2c234
BLAKE2b-256 fc20064f77318a2ca09cc74d5d37b76d2a559c2d027ee89f7ef08124701c3e8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 bf5bb4343c0fc6fe04c6cc0990cfe94a60fd4409087f7649bdfb927b014dd258
MD5 9d5a796f1166b2bcf2bc388c2a9335fa
BLAKE2b-256 97789e8a97a90101a6b4f1f00c99ad4f6680c029b5383eeac8588c41c036d5eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b9ecfca375603cad320c89a27aa2dc527184d8cdba54cfb6f974cfd7cc9505e
MD5 81ddc58709cb3d46c40e8a04f587d825
BLAKE2b-256 fd9deae5fe6a6f0d3f896edaf12b1f7cae5c8dff5ace6d1c989347edf597154c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2ed5543e1d60a032c876970baa379e099f3f327e4ec66feba351b6d336219ce3
MD5 966d472ee6ca096fce91292520b7eda2
BLAKE2b-256 af1bbdb19930a1c6d91811ec94380455395db2db5f0983cec4a9f49910691b52

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