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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.12.2-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.2-cp311-cp311-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 Windows x86-64

pytensor-2.12.2-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.2-cp310-cp310-musllinux_1_1_i686.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.12.2-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.2-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.2-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.12.2-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.2-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.2-cp38-cp38-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

pytensor-2.12.2-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.2-cp38-cp38-musllinux_1_1_i686.whl (1.7 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pytensor-2.12.2-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.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.12.2.tar.gz
Algorithm Hash digest
SHA256 ee4f1a4aefda269a5a399b7bc90da75b263cf019ba881f30cc5881e5886e9230
MD5 e6a2754e0fb0677112d136ef49c0e8b9
BLAKE2b-256 96121e41119327401edaeae39edaddc654be234668d212d8c692079d6f530bab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6e01690088417d888a2edf523e0960b705fc1033e1e93f17c882dd1220338e40
MD5 4c018e2696f949c4801fad793325df8d
BLAKE2b-256 11c79443f5fd3c3eab41b2cd74049e2118851632059250b572309ce67c87e4c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 907f946cb80b46a3a5679486d29ee1d95a7cdd4ffc3b577877f2b8161b423543
MD5 c730e4b9497b308fe7fc0ecbff2a19f9
BLAKE2b-256 25eec03d653d313fee83e7328c050c37a29fc2ff0151357ac560035521bb9d50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 97272bf63bf39e24ab0d11b7138528c757330d30bc2aff71e111c4870dafc11a
MD5 637e549920bc0f86cc1d10a5488b1dc9
BLAKE2b-256 5ab994b303305c311124ec733e78910523720d7a3b15c6afae41a4772039d6c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94abcd92e4dfe21de3e2bf77f1376acc27e354d8308d92c996f536eaa7bc33c8
MD5 f130413ea6e0068f5ecd9b5d78d0a6d9
BLAKE2b-256 86ddcf82e453e9eaf18fdedbd82f5a355c2fa4435128f3234db6a28e717efbaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6b29d322b4b2f105b2a8f759f1fca396c5efc40b858b6a8a90f712fcb8e2c3a5
MD5 1547e7ae99ad40518386017d5de4cbe8
BLAKE2b-256 77b57fdc7372bdfb1faf4b54725b31bdbc55c6f0fa620c793e6fae4cb73f9172

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8151de332e55856bd8743e5f7b842525c923780da3d5b098874a8dd230d0d88b
MD5 f55c34d41335f76d1220e99c959fb032
BLAKE2b-256 e12e791a3510901cfb4a6268557f36c5b9ce121bc440d65e80eeeaae1ad9faa1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2f732c22aaf53f53cd2f71310fef3acb88387fe07193557f25bf016afd7f0280
MD5 ae26e23c4991b354a174e0a19c60d413
BLAKE2b-256 b686e8b4d8223fd40d0d0e8030e31f4f15cc898aa1377dc9b8ba91acbbbf98cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 ac9197f46c8796243811bca71b14e06ecea3357de150fbd8f6bdfbb9939c7e3f
MD5 70a73e9fd710e589167453d319f24b54
BLAKE2b-256 3c0c1ad47dec55a45ca62ffe33209b9deb6ef9f18e1feea6a46fad27e0b018f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8ba98f57091a7f00015a4ef034daca923167ca35458ede079304014bd431bf0
MD5 0684da542a45b418eede824bfb45a0bb
BLAKE2b-256 461454d93d17aed5a9d200c6d4cdbcf30e34efef7dbfa893c13292b9c2d248c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c6d2bd25640487e9016e259330d3047cc07bc9faec5f6c2186db616b6736ecd
MD5 22d6b6a93c8f639cf7b855dd55292e79
BLAKE2b-256 0e81e0dd21ea91be721bf9b692e3db2ccdc354c5639bfa58edb8311bc4e8b92e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.12.2-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.4

File hashes

Hashes for pytensor-2.12.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9754108d6468c545a3dbc98c65f9d5cc161465b17b50e71562c983c7b455fb6d
MD5 cfa8d182d15556340319fcb3801e0680
BLAKE2b-256 64e87e766e8539a59e036faae7e03089fdca710c40d60bb201ed1cc35400007d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6226a085bb650fb4f5210001388096e7b4974759236fbfaa9d9bcf8ca7eb8db7
MD5 d6e5bca861153451888d0d0924dbf177
BLAKE2b-256 da7d01eebe7320ca6004af063faa2c60484432f08d1d3484e9e7f22964d4a2fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d9a9d2fc1f0e44bfbdb287ea3d015cb64f226786c79da1da26f40f2ccae12216
MD5 59eb867d940002a3aed9e33ba126dd48
BLAKE2b-256 f3988e12e51ee94015fdcd2bd7dca18775aac11cc0225579a64009374a023d0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f6b2e3f1b72663a91a29a313e8853eac766d17083ef83e2256361b04281fa19
MD5 e3e95e740309508c71af1e0127d1aa1e
BLAKE2b-256 5993e6ee016f958bea973653ea2e962549c0adc8a6171b9e6cde927abc5ea695

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 be9ccb200e4476f1ef87ba92232078bde81e93752c3fae8c93c44de2d0a12887
MD5 9fcea9950ad12aef3bd97a20fec8258d
BLAKE2b-256 4f52bf6a6b5eef7e99c554d54079cdf21bca3e935416a5c9c31ac005720fe5d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.12.2-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.4

File hashes

Hashes for pytensor-2.12.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1e64c485a8f70286fecca726b8c9b6ec2f60c4e7359e58606eea1b1605505658
MD5 d6eb847ef53b883a11ac2c86d0c17e4b
BLAKE2b-256 6ad245c54f7398fb2d9699279f2c568bc659b204bb8f951e9a72fe25606271a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f00c4540ae5d2f46c59c25e1f433902653d40eadea4a4962d5606af4fcbabef3
MD5 f8a5963636621fd73ebf635a13118ca2
BLAKE2b-256 061c664a4538c06cf138a042dc9564503406b079631e78e8e814bd4f4c46d749

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp38-cp38-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d2a3ec233e9a2ebb8accd11216c6ba3c0b207e26f2ef3cdf77012ada98062995
MD5 1a72dc66ae9263a44a008cd1aae62503
BLAKE2b-256 b00a76ea0c2d1569afd7d5d30971848fde92a17ba529fb561ba4c221cb231175

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 021d0a4b9718e66980db9466fe6fb07c3c018fab6f0c1fe961d92fe9fb397177
MD5 91443bbb9b310ce843b55a1f90c45cc5
BLAKE2b-256 20803bb375b58cd58b46c41f5eda6042d1b180d4a99ce1bd4c6156251112b230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ba791a1b5531913384514b2fef9a463ac1779748f2075106d39e9699e9c9915d
MD5 16ad9fb1d192ffa85801b92ccdfce974
BLAKE2b-256 14784e4595abe19929e9adfe5d0d16db238f90f3fb88b2b59c92200e99648789

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