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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.16.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.16.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.16.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.16.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.16.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.16.0-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.16.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.16.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.16.0.tar.gz.

File metadata

  • Download URL: pytensor-2.16.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.5

File hashes

Hashes for pytensor-2.16.0.tar.gz
Algorithm Hash digest
SHA256 576a2653a52b839d3b48b7bec563356e7b2839b8a4cb83d1821e0f382311ca6e
MD5 9073c43acef9c8088b47fff8f1541ebb
BLAKE2b-256 1d99d8eee6e67a32b821c98a0257e3942744278ebaee9c4c543a83ca8a36a553

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 53fe0df7ed893c51ffffd3197573ae3fe0b8c98e7a726dc16fbe652649af0213
MD5 0dac62a4f3a94d7e94c497108db16192
BLAKE2b-256 da2ab309d8d21128586a5a0076ab58dd97761210798001d8940f107e7756d955

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bf7029f3f97ea424c1978d75ed42e6c1ff2385e63bbd0fe12e51a91312137e8c
MD5 5dcf3397f81bc8083f15cece78eeae30
BLAKE2b-256 7b67034c1e8c03aaf1bf3295dd5e46e734daa3dc3c9f4cbe4a52fd608ca0b47e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 cedfdc28239a9985b3707d9e0980523ecfad3c27eb0990739f1d60daef0fa463
MD5 b1c9edf18e0c1926c5e93cd0547de80e
BLAKE2b-256 8e357444e3b539631d2a3fc2456d9287d5867466ed3b1463f57b4be6c9f79ab4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8758d7131fb8e771c01c072aa54a657968bacf12dbf39e86e7ab3ebb1c597318
MD5 23a40a2a6e859d5c9406aa955154dda8
BLAKE2b-256 ff8fcf19458ef1ba1abc689dbb47e8b0b2610e6d9facdebc915821574a420b98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 299a1323f8eae7f5fb7354354e060582e629c4997c869083c4f2f4ada9ff5dc5
MD5 30054933353398d21557d0aab740c52f
BLAKE2b-256 880518d87f48e6e31897d7f38544b51822b25cfe4d194430e4798dc5dbca9925

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 60cdadcc64e0802c071c0b62d5bb83788501b1f97bbdf9319398fc5b2fd4dd43
MD5 e14de097f74d0cbeeeb3ab44c8630429
BLAKE2b-256 d1d97285c80ec45b12886a41afb947de50edaa21d1e57ed1b2d799a352c778d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8923edb3b3e63b810bd3c4434926fc471bb92a95773f3256b3da12c8271fae9f
MD5 430047ef5ad87d628f344dfe62b3087d
BLAKE2b-256 c3e9ce53ff83fcfb85803cbf8b960c9804f3fd966113817f2350551b5aa4168a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 0aa9367c42c8d64af788e1c5c400aa85885e3ea3d0e53fb82ba6562d62b5738a
MD5 3eba87b23ec14af558886fe47d5c349a
BLAKE2b-256 87dc6e25f8f76a7ffbee93a137c1d6e3844743f893d6b3005b04cc30ca1d988b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21d0c255d0844276059463a197c6f4ad43f607ab69afff28915947f28b1c0f5b
MD5 662590761d31297e784ba61107706658
BLAKE2b-256 7b07918c3f56dca1dc49b4975a0f966cb0ea13a2a1022de6dd06f52b7667389d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ef5340d51207b8655f5225ef547e12acdddebed9879c62cc6f45b8a25b5221df
MD5 2be3c7eb8b4695d35a6ff9923dc9f518
BLAKE2b-256 45076e54acfa2e869e0975fee0c6f69fdc67840c5187414fa56c1f71ae1ac03a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.16.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.5

File hashes

Hashes for pytensor-2.16.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 520f50a59096357636433aaf4824b8a1e4ec6ef741fd41a17752886a072f707c
MD5 5782ef918bf083a76ee067c1442af7b8
BLAKE2b-256 c7143dcbf6e9966bd738102a539670b97ff7a7c9da05b3de2db7161b3c315578

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 416b511f8705bfec8428d6392780e95a031aa678d0a2e82d43a5f170d9259d47
MD5 3840db7cc055432fb47c3c5ac35aa403
BLAKE2b-256 ba63c71535e77ccf1e5b163080fba1f5bf3440e06cd943297923d6a085c02882

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 96697df00f1cbb437c88ef77575da88d910ae565a55ae1a191013d63284510ad
MD5 487577bfee7b8f40cd14f422c3b96e9b
BLAKE2b-256 3141ba243966f61852ca72ef83e484c604b46372db208678ea69a3c83d7f6614

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8dd80bccf92e7ec658c8bf883670c0615d7b8256f2e6488526fb8986c30b4c6
MD5 a888d836bca5208f9154f60399b10a3b
BLAKE2b-256 de944f00e6f39a41136dc54be322e9262d1ca6578991bfd44d3ce86f2965eab7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 03c55174654c9a73d6cae11c053c4e9e13c5f9f2d98faa17717603e4d26cc53f
MD5 f7c7b0f2af8ea75ae14e7d48a0c1084d
BLAKE2b-256 cd56d528ed27d041e9c7e859a731a5194d37746f4e349f4e8d8ab70d10071b41

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