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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pytensor-2.14.1-cp311-cp311-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pytensor-2.14.1-cp311-cp311-musllinux_1_1_i686.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.14.1-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.14.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.14.1-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.14.1-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.14.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.14.1-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.14.1-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.14.1-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.14.1.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.14.1.tar.gz
Algorithm Hash digest
SHA256 4d20c3a19caa6f67d8cc2b8d97e063af2cb74d36f94d5de96d976a5a0e8beeb2
MD5 e235fa8c474c5d221f93a4df3946436f
BLAKE2b-256 1d3b3947d680a75fa46680b2bea859f7c1a460e9634971a85b2444b6f32709f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b731cb25211c37aa74990ca6d46f063f5b0fa0c5c4247900d9dba872cc749964
MD5 465d16db3a400fa1c666c3e4e1300ea1
BLAKE2b-256 86bea04feca331bfb64b6ca62c488e6b0c9370fe25ffd3283f36214b27f902f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c0a7c68d6c9844febd7a21239fd06f580278983e3803c247ebb31f1955b4b092
MD5 aeeb1e1746030a925be8cdb47f6f62ee
BLAKE2b-256 09bf8fb1881c3ed46978dcea7ad50865ac75840e9db5036ab70c09460d10dc9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 f4a8003803e3e3ea13ccc99768fe1803aba2199c696baed5275398a9b1609f22
MD5 46f0eb53a5665ffe681d3db03e7102dd
BLAKE2b-256 745a7305e4739e5ba2a5b896b41c009f626779f7fab12b215457b3d8b30deb9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2dfd449d73c6cd1ba40eaf1e8672e68eb312653c88b7d13a1520d48f0bb74e56
MD5 09ef4624d228e2889b07766577ff9643
BLAKE2b-256 c00d1ec88240818a824cb3f6c2a1d1c96eec8b51bc604de8553fa3109a35b914

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4921099591131a94b56b929ea4040da8db2cc52123fff8dacbe202ea56336d98
MD5 e810c4a528a337eac9f661c39a1a658a
BLAKE2b-256 52f5748783e0c89ed0f101213f03497ff47686f34bdb2e128e6a4bc743a8aeb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 10404a032305be1bfe24ed340c099a6fb7c3fd4bc30eca86fb195b67c689ef40
MD5 a8e0b2c7e97d2766398364dd14a34c9b
BLAKE2b-256 4a724e9dc53e40b16acc3a62ee08577593d6f2788fa8dd5a6911fd0e37899064

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e9f4ec71f9c3d5b1aa9263a43dc2477b99536458f13a805af9401bca4cac0ba5
MD5 218b68fe583d2701feca6fb5b99d9dc4
BLAKE2b-256 787f4cfa1cc60b24de22dd7dc6c915eb6ace251045d35b8a480cdf168abb387b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9e8c160cca47d6d9f9a9a99eedd24210a1f7232f347d0007a23d46e9f6074d98
MD5 71dd920a172b3de3e8d37316a47cde10
BLAKE2b-256 6e43ae07da8b2b46e4565db250c0d52b7163254525ca1ff2b957825672217ed4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f6dc9084dbe548b9abbeb4ddbab12588ae7bd11f73db2f71df75108462c0b47
MD5 9212b4e6f4c4d4423998c8370e6ebd5f
BLAKE2b-256 6098633277d48edbd1664333374d62329fca113701403267c84a8662a56e80d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8a6de6a894f92d801016685db46041a6105a783017743fece75d80520eb0a6a7
MD5 8bc493d5db4cb1b777c57fb06e14b3a8
BLAKE2b-256 66c287d94478dfae01a8b29cc72733a007a53962f05165da9be613d957536990

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.14.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5d4042a8315b95a965d4166f0291be8e9f5bb218c1c6d03143a77a48803289dc
MD5 f9af6d3580ee93789dc7344a18f22901
BLAKE2b-256 14acb769f400c18b00561af65096176319d82c31f34ffbc0b75eaa789c03673b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 93902cbec2bca6dd689e9378c0846161747ae6f43f90cbf9d7fd551c21efe06b
MD5 67ce94a5f04292b9d7042803e32ec188
BLAKE2b-256 0e8afaf48f85dca393e117837d5225a1aea0272b4c4165678e31f69db240f561

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 4da4d30b51da591057ec4edd66b419aee14f0bcfae4f64bbdd697cba486d7107
MD5 1a5101bad05393a5760bcb71dc8c84cb
BLAKE2b-256 058fb87946c4dc08c53aa70e1dfc617a219d38edcbd65fb050bddd6fa0f3bc2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9001cdc56ee0314285aaa001a9113fb1f23925d849d7db0f963bbadac233e7ff
MD5 334dbae5a6bed56df3238fda8c9e197c
BLAKE2b-256 641dc8d0f69dd86dd12dc260e2e57c68dc723b08b6b2ecd5ce90a7731d76de4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.14.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c4e2ae7b74df5117d15c96659d73b746ed2c113ffc5187a80309d52e8583d7df
MD5 0de3b2badf10322147a190087129701b
BLAKE2b-256 6fa2600ac420239bca10684e2145b74649913862ce09948289da45d9d8e40981

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