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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.17.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: pytensor-2.17.4.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.4.tar.gz
Algorithm Hash digest
SHA256 f69798d7cb7efd76b957277057be840195601f0caa63e9701448067a7a9601de
MD5 35041882932c0592d13451f1cb34d638
BLAKE2b-256 af2a5bedc2d8ec0edfa92486545038840291d2825afa2b50656483f14aeb612e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3cf066edabc9a46d489b9c54a789d0567157a6c86412829e0fc4e6f84a0544dc
MD5 c2266db91015df74b5fd40c0e2dcf667
BLAKE2b-256 760f53d81f8aa470abced6a079e6a6664d8aa965f1f42326a77d6f7cd645491d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2ddcd5ae3e579b17e76e7f7071cd7b0a10103789157faf1cc322c32bd323d57e
MD5 8a6cd983a828201cf90722fb7f3bf800
BLAKE2b-256 46c6a3dcb9f80bd21c14d91f9b92f1c9269c0975c47b836c08c3883365879bea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 38e8b19ed422c861a3fb6bb2c478aaad24381a4067ec2055c95410d97c8a4894
MD5 9966fa88ff9bfa1a3dc4c190e0de7adc
BLAKE2b-256 8690b621aafd618c371ac6a6229cabc64433c9dd1b7628f34fa903263914e991

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba2a2c3bcc410badb40fa21ae7e3e764a69b4dcc35e18b701fc72e264b4ae4fa
MD5 11cd4a5c575e0834f2e95643391aa017
BLAKE2b-256 8adbb2fa70026dcafd93c981b29135067c643784a4458d32298a34c3669f4070

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 325668644eb850cd6005287d71ef4001e1606ed69a238aef477fd172cb0bc428
MD5 6d7b0835255eae60ddd9249856fa4372
BLAKE2b-256 2174577df21da7a628a6d2a7256af01c528ba55ad848b09291509454212ca29f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c030825e75c2a212bc9d8b0d631786a9e143c88ee96189524852939a521d3013
MD5 9f56b518cd6869313cd6b48ca98cd86a
BLAKE2b-256 a2ea8ce3d23c874083a794c8452710848e73e646e1ae493a64c69e47f8572fc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3d6689ac408c9bc91d9854a59e4d09f018bed3463edfbfdeb3d892629ef22f01
MD5 de3f23cbd501586a4cf148137ef29b85
BLAKE2b-256 5d9030e54775f73d416146eafbe67e11d7efb0210766399e79f9533872cdeffc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 c25bc993147b7c5e20becd76df7d00b904075c50b1f815851c2bc082cdb44cfa
MD5 684593ed43c27dac678a81924a11ba6b
BLAKE2b-256 b9e373ffee497a33094c18f63f80768b3c6858426dd335cd7610f7370415ce73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e493b31e32c8ed1530ecafdac0453089e960394bfb53278ef0d784f4154cc09
MD5 debd28c481eced92332a35df0d49b08b
BLAKE2b-256 c5791c6c213e18a5a2fe3905d9ea95fb7a94125db54df14f488fb880031e20c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f66ad2f7a516fc70c38de02361f508debef45c5ca84d05e0b5844df1d3293fed
MD5 2a7adaa69d7f1ee1eb7e746036dff0cf
BLAKE2b-256 46693208dcaac2c861ce5b6c74c1b53a7efc49eda6596b4baad334c4a968604f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.17.4-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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c344e4593e2b29349ba4031de52d80f71321f52979cf83dc75dc1aec8caca687
MD5 2ad0b28640f98b4214da4fa6c9847b07
BLAKE2b-256 0f52800aa90079c6bfb6233cd2948b8db03e192a4d296d6a20ca6d37512c78a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8f254ae51edb0acaaa64c7576990bb15b5c95860fd6837d6bada1aa1e6f58d60
MD5 89fd0ad0ae32babe7ab9cce3fde78196
BLAKE2b-256 408948fbe01562ec90b72bd40d5fbfcb5fa517d8e989f5af0fc4ca5b3f688fde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 da0edaccb760901beb292c0a325dad3925d7f866e01095882577349180fd38f6
MD5 08adf1a09c6e1af76e257a4965ef107a
BLAKE2b-256 b64e29848b808f8954d2e2e827535b95306bb0b98c5ea535180d0e02c647093f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32b6c4efc846cc065e8832f1ec36f3f0069aec89cb5009251735420c99db8ce9
MD5 2afd8c4ea1e38d610d71ed8c775d45a7
BLAKE2b-256 525194b21089944b4dbf6bd897a7418f475150f0b154f159536a73622c422a59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.17.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8fe9f60fcc65c40da15a54f4a2e37217d117c3d47fcd951ad18a323925a6d4d1
MD5 4366a3e321501d694df719d3211a8b86
BLAKE2b-256 2ad6a4706aa9eba106f960f470e6ea466a367d2107f0420ed7e3368ea8306fc1

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