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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pytensor-2.12.0-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.0-cp38-cp38-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pytensor-2.12.0.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.0.tar.gz
Algorithm Hash digest
SHA256 67a65f03daadae05d5e32c45e65050ce5cbc1fe5dc2c36c864f412a745e53284
MD5 0fac7d87b3f34e87274bae432d715074
BLAKE2b-256 cb567a4aea4fec03bd152adff407a79e6f3552c182c4c5ec02886b46d30da01e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0641a2cbed9213c68291018a2c417b59ab74e6d133405f867dbf3ef668b9967e
MD5 728850682633f7119d1e2ea11b748d88
BLAKE2b-256 8c7b86522df8c272b7d4459d9dfa73e4e404b7b533a7d968f3305c9989944e92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 34db5df02fdb20d868470128730b6be5d58624e0f72a2ca728da652c2cebb5be
MD5 2a44b949ed1ac8864bea7db9e98f9ebb
BLAKE2b-256 a932127e740274700fa90752b5015904a1a25d843c357c657a052d9d1a115fbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 7832123321539cfec5ae36865aa8c1cbe77d490820b6717fd04701999da0c088
MD5 75184f429a6e7928e65aa15ff00f1596
BLAKE2b-256 f6a012a69f4b144d952f585031d090d79d81797e0ff474ab4d9a18a0d2e19a29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac4ec14abcc217fb7fd88f496876983a05ebd87876fb7453bdbdf6c6605de45b
MD5 0286ceaeac44cbccc4156ee6fff878ef
BLAKE2b-256 81edfca92b721dd18e30a702a44a16eb288befb0d0026b0993b99621809d4097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 81f7f4618fc23f644e96dd3c5729dd514276325332d82de0b8dc2611d4d1ba13
MD5 aceaf7ccbf5cfe25a345ce5e87206d8c
BLAKE2b-256 74dcbbacda7463927d22ae546ffcc3355df265888ea3efcd24fb0fbe23686b9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b6c9283d8a503df650879e62fd6ea02dccc9e90290ec85d2e078c475319d2a17
MD5 b0199017e2dc667b3156cb2eb062da07
BLAKE2b-256 6f5b17a40dd44ae58076a0939e40c88626c8c865f1a9c27ca34e28e19c8e8947

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5b90f770c8c7bd85f5a152e80377d17104854af1946711a377df994ca4a494bb
MD5 2821261db2383ffbffe74e0cb0eda8d7
BLAKE2b-256 89521910bbb70165358f938036d9a0e75029fccf9f88daacdfc1e2f620f95082

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 f1cb2f510444a3d4e49924312e459e97ee2bc346f6e08b6d113f929e8e342892
MD5 8aa4af0d0d99a1bd8e46bb4c2b1c89b7
BLAKE2b-256 a628df84169264a088cb9098816653a359aa78bd69d70e9b3eb7449f357a22ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe32e193bc5f3be10139e1c45bef311090b58f6a1344e15fc765d6084db60350
MD5 678fd15fa2b003a49349c2d8b153c1c0
BLAKE2b-256 f6ff68a44aecf1bbb02c6eb3c9659566817b15982511f8fd5b3d9daccf685094

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 58b6b003eb83823c58fd44b6ae3984c156b55d9371d1c9c7262d3d8cbd7c30d9
MD5 eedb3b1258bafa769c86bf02202610ec
BLAKE2b-256 ec0176ade4baa9ccf942b8d333ecdfc4092b18d41e933cd6e3fd35abd88f09b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.12.0-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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b2cfe57b812bdc88e933825af147bcbcfaa20015fb376ea21255b3788f51818d
MD5 512bc6f1c2c710949faf4552c4cd85cd
BLAKE2b-256 0f1f494bea4894d2fa8fc414905603125fa149c2a9bc5f304c80557eed5350cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 03aa152d584eabd40788219e235cc2411d5c84863cecc6c7651126650a128209
MD5 ca234594eea675bbd2c1f9723e3aec00
BLAKE2b-256 2269678568a84992866ac5254c3d710da3d5f29972058b8919f1934eec604310

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 f91fc35fcc8a8743d65f40874cc676bbed6a7a15afc05eb89b88949af506aa50
MD5 fedbe99d4aa59bd80fa1060fd50aad89
BLAKE2b-256 9a3593cdcaee55ce9bf1f17f250afbf699a1630caad0e32ed0eead2087bae7c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78d6df5eda2d0e3a6185eb9545cf39dfd9627f66bf1d05805d9c09e7046872a0
MD5 b88899e919ce1d4c56f1c136d0c8ee97
BLAKE2b-256 05e4828f8d82fb5ef53e35a40984b865a5c8cf40a339c7e31a609f568142034d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4eaef6ca5207a8be8aee59e05270184459eeefd935e066f4bd0f99efac85aaf6
MD5 849068c9f8a264a015335d45ce9a896d
BLAKE2b-256 f67675132556b851e9eee04449e3ab45f0b08d10e2c7b442c41f6280d586a6e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.12.0-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.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 92e6e61d922f4a676e15bcc80c6fdfdafa2fe3306c834dca92562bc79e4f24b3
MD5 67a768e8018c2a693b4b445f1a584850
BLAKE2b-256 b5cf0ea4740b96c04dfd8681eed7c83eded035fc21fe05f17e8a1e70a6755abb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 21eacb11751be6d077b56af6394e91df0f95f42007819bb965df38e68f0b9331
MD5 ad83aa59a4af9f4ea350ece704a5c4a1
BLAKE2b-256 f15cc56e8288cc801d11f6f8e213d6dbab5db401490b15f5848f543341ffdd14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp38-cp38-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 6fc98c6025218bfaff939dd3fadd19f02ff7efc0e0de6422380bd41ffbf31aaa
MD5 c57e9195a7ebe1543fedac3481586de7
BLAKE2b-256 5d93fd5c399559f9ba86ad926cf8bea1d77e138bd63006a4b9ea0dae1e3ef0d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85d20264faafd98875cc2dde7930775ca2cdbd23fe58b8ba0fbc6ae69f419acf
MD5 0b6c2474e21702bc8b8add157210faa5
BLAKE2b-256 a0a0744fd64a5c6b50e157c762249676b78224d3fa8af41ffeb780cff0148ca6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.12.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0e12b70c8560ecf1329dbb2f605c5e38789b11e9b6a8e953549eb203bb4b86f1
MD5 9ce41e7c2ef67e17cf6d029634641585
BLAKE2b-256 6be8752b15da13498f7907797396f88b4b34182556de5fba5994b226736fd6a7

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