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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.18.6-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.6-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.6-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.6-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.6-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.6.tar.gz.

File metadata

  • Download URL: pytensor-2.18.6.tar.gz
  • Upload date:
  • Size: 3.6 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.6.tar.gz
Algorithm Hash digest
SHA256 f70562cbd416cc12604bb2fcbd2324aa32123146f90cd34e4d221330ff4ffedd
MD5 7ef97ea2091b9ac35317ff37cbf324d1
BLAKE2b-256 67ad0f2c46adf67e6528c37c51c1adf7dc15cbb47d9a4788f89477b2298c720c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 384dc90813ed39697804d2e9972eb35a2b6e3296f8e9664ff209739a9f678b55
MD5 7b9b8a0c08c2d47c03f4f0e8c95e4c54
BLAKE2b-256 21c39a12c750ab32556028dc01aa676fae564cb66474d4bc621bd9ddbc412ca5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6473a1b11fae79cb79f279bccc6bab3467b7fb6f44bbefada381e83d12df9b5a
MD5 9fde5460a823e4eb2e67f4c0bd11501f
BLAKE2b-256 896b0ee18a5f0b2c07729b5e1388871c47d53c1ab1decfcccc3321b6664de01d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e6a37f9daaa926cf6f0a5164c861f3c17f6e49efdfe958794a04163a39989b31
MD5 3f2248caae143740ec47ebd0e023eb39
BLAKE2b-256 af17c02086cd3c5b97e22c81fe21e4ce0dac3427293b4c3cb7982ccd889b52db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55b1a8f1ffcfb131e2494a2c81f6c7aa5bc0ed8693bdb63f7d6ea6e4cc64a271
MD5 7beb835836867808267e846e6a98ce41
BLAKE2b-256 58d44431a529ac09aa900df44cf801eaf043f3724e03299f173f44edbff77490

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8a0f1530b48f613851b04d1b29702231edf194c8c6fe015b241131d56d33d570
MD5 cdc4bae474a51da13e3bf2e49792b96b
BLAKE2b-256 ecc2bea6718d49ceb9e5fbcc3c6f8c7ad3d27b4bea927d66ff8f705c164737d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 522a6c937da58e6224dacf6ded12977c7358b3f2cc992407cb90d0b809a07fc2
MD5 cfec590bbf98b65de9b4d1f18846b0ee
BLAKE2b-256 96652792e1d15cca5617d3cc88e34a573f5329a5da61f2e075f0c12c642d72f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 85144ded4dc65ae9292d2ade4abafc252e9918785e42418e0d9c9ad05ef70897
MD5 24447735546cba9d496aaff13eabc1ed
BLAKE2b-256 09c0866094e4d199f567e6d9498156c8b710630ba08cb23ed6fe1c1e3fb78c10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 469a2962ea273920c51fcfbd3b1911ddc3c2592a2f1de775b673c99e0bf8a9f4
MD5 dc32693c6dc43afa7d674c154b0cac7d
BLAKE2b-256 4f37956345160175956e2db5922790bf769cdb690d679409ff8d11f27fb93ce8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e6e7676753a71be91ead379a6f3af2442322eb188f078800330bef552fdac2b
MD5 00ef4254df514db8e732f86ffaee6f9e
BLAKE2b-256 c9c6f6c9db475fdb1ddf8a1d621cf5fee5445eaab826bfab8193df52dbe3cfd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 528301c5f9b51b72540bac1d24f3e9fe5a872bb96a07da1844f1bc99d74ba338
MD5 d386908cf633278a9befecb6dacd089b
BLAKE2b-256 86e636bfb3f8555cd85f5fa81c0b690475b3e1492671f7d02cce08fcf68b1b09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.18.6-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.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 de3fe6c3f8a110f212aaa65949cdb55b16a0bb81463b0f69b6ffb5b9332baedb
MD5 be19a04d26285215ea750334fe36c9a9
BLAKE2b-256 68212cb243b8c2434772defa1b76a52ab3332495da5b9fb4b6d86401c983cf40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c7a9a3c723da22bd17081c4d379611c44e4fec71713231420e190adc04233eb3
MD5 46223f98e2920664858534fbee4058ac
BLAKE2b-256 4fd26e5b8209cc985d736f8e9a6296d344a020943125fe799a0b31c8e73481a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 b084e8280b751ce36e7c580190d5d12c92658ad5e243ae7d04a84c08fe17ccd9
MD5 5492d5337f98edd4199739d6766cdff2
BLAKE2b-256 0dd308e1fb11c312b6af6b5e15f29eb60ccb60d4e6c9f2a87df315e2c037c4e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 712afe2261744365d5ed7dafb9a20dcfec391730d8689eb6b763dbb18b229808
MD5 8edc1e261ea0dccf7bcbb6c17d48cfb2
BLAKE2b-256 d3c9d0b1812d4031facfd740ce651f22a68245a333d1aaf7fd3a55be54850c73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 02f6cd303e68848cbce3292029afde99759515d86958618b8391a72dddd766fb
MD5 20a08d28d91278cdf1fd0f6a422f1ede
BLAKE2b-256 efeafca7c1a8df6996465989391bb5a02afbdae9a795051e9379c1b09135139c

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