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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

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

File metadata

  • Download URL: pytensor-2.16.2.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.2.tar.gz
Algorithm Hash digest
SHA256 36c1c8e4a2b483beb8ff7b2c8577a65310ef33dc2efd7aa9b4ab78a3f79cd001
MD5 01272fb2eae8144fd3138e0eaae26514
BLAKE2b-256 52014b459eaa40723af696cf32534daa625235de68ab771f336c4eed1cc64490

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d9622a18088dd7e26e9cf1c2e23646ada356bade20c491daf1d8aed81e24bb7d
MD5 34995dfa4bd1abe5378d29e8bda7b676
BLAKE2b-256 3bd4658fdfd14b07e9a9c50bdcfec96f008572cbccd94372a7f623036de268eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 52184162770bfc2bd5540f3d481c9c8b4b2d55e27db619ec339cb7ea920b5d17
MD5 f145f471fbe9f9aeabf814484b241efb
BLAKE2b-256 766dc4a75df4fdb8274d7df71777fb50260365a1ac89c2bfd1506611a48239d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 0db5ff6c0d7d2ba87665d691ef87c5c4a8f4f1fcba8a88e4bbadfbf511b13d0a
MD5 7105aa1a55300a1e73f62ba6411a04f2
BLAKE2b-256 b79d8cdee5066b378985fda2b5a4e2eb5bc7396d0352526eee455539b3650061

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 968176f75a87f34e62adcfc54b6d0000b82808b998bcf83c5db544e0bc58641b
MD5 fb4dfd3e57acdeb4e8051b8245ceecca
BLAKE2b-256 38a132ea7d211b35a367a7670e9322253e4e5b2985c88f105aaf279a4e040729

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 14e7839c3ef8a69a1d63e613ac41d64b5d0d574d189b9cd927df454026f649de
MD5 4330b51967d412218ef900e4f68771b5
BLAKE2b-256 3f7cd58aab3b4bb0b5fed4197da7caee4e37d269591c353d74bba32503f4d1e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4d2d76d250684084cd5d69afdae57058b7b2a25b30b29815f5fd4941fe7e3c04
MD5 933963a2950e3ac4f800f1f483a758f7
BLAKE2b-256 067d0b3edde9991413d7034929f3958714885ed5ed772b73de19c34e8abf37e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4e149b779f80ac0403ab87310f5800fceb297faa8e9522d9079b0c71a426a926
MD5 d7e46f50d7b40dbf5b2790996a29cbfc
BLAKE2b-256 06698ec17200c6276e9efb1de44e1e413e0ac9e8332a6ca1b4b92fa5992ed29f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 d07b2403364599e8f30e7060a8c2d28d23d2639b700a7a25eb147d39bd150587
MD5 0f0fd28b8c97184636fc75309eae597b
BLAKE2b-256 1c635dc280027f0f10e4add15ea5537f2d19d2600495a141eafb73aa74a7ce39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c10d46037e464cfea8fa07a6fdac23bed5eefa48dea7dda79f04aed9a9ce819
MD5 0d5568d080eb34d6730a7eafe142fd9a
BLAKE2b-256 6fb042b3759394f07ffd933e724e85a54b72e13e4b17cc35e17acb5b2523ebbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4a3cfa858cb97f09d6cfda33ef607e7e8a358d377ca0f1a0cbe4d9445ea5fab9
MD5 b2f58768dc7986e0920377b7a92402e4
BLAKE2b-256 37eb0ac8f92eb5d6a770a8a13b1578a11049795443df1d79574d390a2d3a1e49

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.16.2-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.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 31eb890f180e548b343f28fa39dcdd7822214f68a24731388a061b06d6a58888
MD5 9a838d9e0afb0ed016af92d1f98036f8
BLAKE2b-256 f97109ab34b978c90f95923586b38d9e4aa2b0ad6ae699409792b3b17b2a28e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 089a600f646bb24e60267a72c41b6624c2c2d158f88526a3b9a1789084662e5e
MD5 e12f13e148e4a181acd9d72ccfb6cb98
BLAKE2b-256 7cb3dcf0eb0d87a695214b3e6d3e3086f3696854d4ac3dcdb8a74f0656dc1766

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e423113ddf2723e364047c0009e7d007f8b287145cd28de47fac002f2b75b084
MD5 f6a6488e1fb2f870c438b85179b55981
BLAKE2b-256 eadf112decd5c678e0a353517f190d40337afc5f600438c1f0c7575e4771137d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 edfe33b9cc60768fc9df80991a637c384eb0b258d3117ddd685e9198bd4d8580
MD5 ef6c0255a6e5e52f21e53cb8dd144e2d
BLAKE2b-256 a1e0901aef6a47a0d0cc66c7f0efb64dfb7bfc14798e75f65d58f6aca7165fc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.16.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8f557c762192393ab81302de69cb81001f9ae705e4318f3a63ba395dca0af537
MD5 3db85106538b107e7f9a8378fc50e5e6
BLAKE2b-256 8e8c246e0a66fe8d5f01ab6887f6e72da703717b0aeeeb855a319227097ebf30

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