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)
# Elemwise{add,no_inplace} [id A] ''
#  |InplaceDimShuffle{x} [id B] ''
#  | |Elemwise{true_div,no_inplace} [id C] ''
#  |   |a [id D]
#  |   |a [id D]
#  |dot [id E] ''
#    |Elemwise{add,no_inplace} [id F] ''
#    | |M [id G]
#    | |InplaceDimShuffle{x,x} [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)
# Elemwise{Add}[(0, 1)] [id A] ''   5
#  |TensorConstant{(1,) of 1.0} [id B]
#  |CGemv{inplace} [id C] ''   4
#    |AllocEmpty{dtype='float64'} [id D] ''   3
#    | |Shape_i{0} [id E] ''   2
#    |   |M [id F]
#    |TensorConstant{1.0} [id G]
#    |Elemwise{add,no_inplace} [id H] ''   1
#    | |M [id F]
#    | |InplaceDimShuffle{x,x} [id I] ''   0
#    |   |a [id J]
#    |v [id K]
#    |TensorConstant{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.12.1.tar.gz (3.5 MB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.12.1-cp311-cp311-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.12.1-cp311-cp311-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.12.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.12.1-cp311-cp311-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

pytensor-2.12.1-cp310-cp310-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pytensor-2.12.1-cp310-cp310-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pytensor-2.12.1-cp310-cp310-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.12.1-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

pytensor-2.12.1-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.12.1-cp39-cp39-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pytensor-2.12.1-cp39-cp39-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pytensor-2.12.1-cp38-cp38-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

pytensor-2.12.1-cp38-cp38-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pytensor-2.12.1-cp38-cp38-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pytensor-2.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pytensor-2.12.1-cp38-cp38-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file pytensor-2.12.1.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.12.1.tar.gz
Algorithm Hash digest
SHA256 fc031f0103f70e50abed3846ae5d771838a0408085bcf55d3d100874ec115364
MD5 f3738b19313414023db452c19fe52700
BLAKE2b-256 582b238b9d68afc77a073e3a2f0e9783abd028afdb744c6a9603b17ce5b3ac25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 37b92e91a0c86e637113ad6738cf90d56729bf7f44db12961b82f1cf4c91c990
MD5 36ac4492170627d649034fabc25811d8
BLAKE2b-256 c1d5085f906322952d6be807aab50f8695febfca3d401e36649c9fab2031c5b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5a61ec91ffd4a7a5368581dd50382e047d1c579d4decba7305e0232a23bfa6a9
MD5 9e51334f0676cc582776f34e2b0588d8
BLAKE2b-256 7c50f6973693f850cba9fd6e9402020db5a44348cb423d8aaf85524c0f394000

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 8b800695aed0cf5509229341cee90f3328da483bb97d742a8f2e3a7553c09817
MD5 e6e1e961e07f0398b89bd39c46b93563
BLAKE2b-256 fce7a777092a5d91f5c29b22d0bc9f547d1dfda3f1b9fa8c52069816d85c66d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d30ae6e58a03ed6d5a95812325d90fe4fbe487b9ac864e30aa96095bba1d2998
MD5 cb5499c681b63bae259aed682db7f9ad
BLAKE2b-256 359df41dbb85e2ee8a6661b2d0382aac755f567a52e5a4f9d965aee2da6ceb9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 57f6c0b9f0c4bfb821e0cc0328a28a0ea0663842a21b5165b9edc46a84b712c3
MD5 186a9ffe7d370bdcccd00b1fbd9bedb9
BLAKE2b-256 0034118ce649e4733e320eaa82a54205be472458a99dbeaf0e76336954d0c538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0b2dabca378a59dd6118431f0b6007779c67ebf2567f28b4fb4d5ebac8e6614e
MD5 9c3d3216ca47035ca8d84c8d87b256a0
BLAKE2b-256 c688eab05e469e2bcff3b5308b7f1ee4123d79d2500cfcfdd59a513b6d4ce3b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bfae669e2068bf1fb7c5a2f04aacdd8ad56604e75f056dc05f2df1db13450469
MD5 3621269e409f50cf6d993f466a54e7f5
BLAKE2b-256 74ac99a37a3521ddbdb82fa254ce6f3cfe082de208f5a4de9656a7f11a27add8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9c1e6bcab2eff57f8024142481c45c4341e011119f8ff40b33a7dd58bfeb3990
MD5 2abea26786c00af814a8aac336fd908d
BLAKE2b-256 37035238432d3f72bf15388b16bd99aa59985db30bdbc2382137603f8b6b69c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 389c121c6bf7ba843c45d46f59e633b7f6f9692767e68a63dad3111566c79a6e
MD5 7b173f99b2dc8afacbbdde9950dce7cf
BLAKE2b-256 9c3b07f454418eb3b0b30ebf0928d7788c239cda8d18d5c13da8f9f1bbaebd0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b78458508d04ce46ff40541e61e612f23922e6ad1cd31f30c93900771647f7af
MD5 331933f28321a1f50948c39ada60a3d7
BLAKE2b-256 286300d9de903ff65bfb8c92006cfe55d08f8ff404436facdb1c5561f6d71984

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.12.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pytensor-2.12.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b98cae11b88bb6eb1764f3fed110b1bfa6e9cd9b35c866589889c12fb4d64602
MD5 3feb609de95a17e8b170677322bc76eb
BLAKE2b-256 4e6ddf6dd320a5bd1b25ab00455566980bdb4e4371714377e56e2316e557a00c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 81cd080f79818b3387a51421db26cf831791980cb1633099f85a1a36f01bd0f2
MD5 c5e5528507238c27c30aff95549861cb
BLAKE2b-256 461933308c3ae6078a3894808c8a207e00b87a5ea71320896b5d81986bd16049

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 eecc3b009a69a1fbc4d910e109c1d85802f3b73c594fc59b15e835ac892b804a
MD5 576b71bef0345846469470e080703fc5
BLAKE2b-256 2405470ad5fd93faa746d0869e9a114d340a34c1948d93deb475c51a99dc43d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2e5e896239eb3dcff7112a768fc9d7ad455be1c9c9f448d5c58afcd5ec6cbe8
MD5 c57e04c83e8888df22003378a324a90b
BLAKE2b-256 673e971c9aebd894db75a5570fb53e29169d5f4aa2bf0c62a499b0141a8c0c62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e319f6be8b71d1126bdee05299c256d6e2de7090321c0c9551cbee4731ec70bb
MD5 8ec6e9d60f9f63783efd35d769b27ff4
BLAKE2b-256 131e64424f336acc18dc3a25b1ee3f8a52a0858bcee15d60c80712c13002dee2

See more details on using hashes here.

File details

Details for the file pytensor-2.12.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pytensor-2.12.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pytensor-2.12.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1a0b581a9467b6f4208c788de02aee2f08194574aedce97ea93ce542d91d627e
MD5 61848530cd8159ac2f760389ebecfa0e
BLAKE2b-256 72e0854c55dc0b6d19829778cfaff3cfbcc74fe483444cba8314bd5c9023f69f

See more details on using hashes here.

File details

Details for the file pytensor-2.12.1-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4695ed053d7ca257cbf1342a432c790dd70d2b922052c49af07beacf35ae3105
MD5 ab8bad4885dddcc6b81cc6c80efe1690
BLAKE2b-256 49b8d150b60c3d397a613be0ed97e59e6f820c82b10fa8bbce00dc09157e5502

See more details on using hashes here.

File details

Details for the file pytensor-2.12.1-cp38-cp38-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for pytensor-2.12.1-cp38-cp38-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e19ac9c5e36533bc32926f5c4b8b3549aaa583bb91444d50d3a9be9ef8de8da9
MD5 48b8615828fecafe9958afc76f3d347d
BLAKE2b-256 a294f3d9b98d85c4cefa2bcfd9de07fe354b141338c0c62b93034b49a631de9f

See more details on using hashes here.

File details

Details for the file pytensor-2.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f606135a4f2226d10182e228e88e31091ac5b2dd64d7a8c2c2dab07795a3f8b
MD5 8d104f7c1a23402b33e47f0f2124dea0
BLAKE2b-256 6e764060f796adfdf05ae55ad1c0e1edf14187de8d80b6ba732017adca9c272b

See more details on using hashes here.

File details

Details for the file pytensor-2.12.1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pytensor-2.12.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2a96eeefd273d112acdcf0922d50dcf91c298da506c1205023e606fab3f8cdef
MD5 e447810b3c34b30bb1a00ead10105248
BLAKE2b-256 7b1ba829c774e1ac5eb551be4866298b1e82e6e539935cf1809cb70ce351d772

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