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

Uploaded Source

Built Distributions

pytensor-2.15.0-py2.py3-none-any.whl (2.4 kB view details)

Uploaded Python 2 Python 3

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.15.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.15.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.15.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.15.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.15.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.15.0-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.15.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.15.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.15.0.tar.gz.

File metadata

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

File hashes

Hashes for pytensor-2.15.0.tar.gz
Algorithm Hash digest
SHA256 80ad1686407eb8c29bad4913aa15504edebc30be9d7e0a24b453a13c457146c6
MD5 b3cfa2a9e593f5d019409bdf7dddfde8
BLAKE2b-256 68c3db32a1943743e59e9577de9b914bfaa725af08c2c99736fa5463d82517a5

See more details on using hashes here.

File details

Details for the file pytensor-2.15.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pytensor-2.15.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pytensor-2.15.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e8302904b302b400df213fd7fb7c8455f4801e43f26936d7e7c5b8f68ac538b7
MD5 308b88a6a7b565340c4c7e8b772d6986
BLAKE2b-256 d24c6b4504c5502d0013cd891760db5dd4ad7d891fa274ef7bdf479e49c97f6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ea0a6e8513159ffec1473c8f8119a47fcdfb503f2ea89f03be3c01d2190d30be
MD5 cac19859871faff424e913811a8f3e16
BLAKE2b-256 1abf3fed4c9653d13f53c548c217e8b058540eb8e664e0671858e1685b80d64c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1447a72a316689f7eb79356e640bae1fd2cf91d8a7e0eda835d9bdfce00872c1
MD5 8b0e068032b77d0ad63c5e8c7100b2ea
BLAKE2b-256 9ee0a88117aec115faea431d6f429860fc89bf90ab8828d478fc63d0bd2e64e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 2062046dc562863415cd381538e3d23416d9766fedd08f8f32236215e03089f6
MD5 84cba9f8c599a39b6cb10ba77dca6fe3
BLAKE2b-256 9cfa09223601ab27171946a30f422c99c0d019169a79336a0f342481d9110462

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e412fe082e4ccfdc58336a07d0f7f1fae5c98dc16dc82271d871e78615883915
MD5 231459f940fa9652b82ba6cf73cb4a2e
BLAKE2b-256 aa5325a53746869ef4a711ecb5c255a6ca31d353accffd9d6e45fbd38af05a2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aac152ef42f461f1d72d5c3e1ba43e973e5e517ee21b5a27d179d2bcbc825253
MD5 57ef7720105bc80353c049a64481a8bb
BLAKE2b-256 7bc09a1bf4eafeccbcfcd9a2c21b21e9b626fbe918690b1f905eed0ebef7a5f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 15480df70c66a36f159603aa3e2822a3c23df2e25e815777631f3260a9a19496
MD5 831356880c7dc6b3270abbc29be5cfc5
BLAKE2b-256 4ebdc7d8a0630166a2ee7302dcd98e5631ee4d262b2c1d5bbffbbdbfe63af735

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a14bd309ff6ff3bc2e8ce5aac2fe9c9082812214658566b3e843ab0ae4ee0115
MD5 8d7df48a2660ad03f04b2e52af2786ad
BLAKE2b-256 4280104ad9d1ef9ff58ff6d8a740f00b93834a0205191308878d3d1ac04d409b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 30c6539dbcc4006345830a4405479ca7fb8a148778d48097efce01eedf70d4b8
MD5 4d542bde74725c08cd526c32ca1f4afd
BLAKE2b-256 945f6d6259ab6c20dd6761641f857dd415004c39c199f769e61146bee0ea4fde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93c91022d9551763c3648beb630beb7be8f39dc95000f2f1669aca64c7143b19
MD5 92d726d35b0bdda0fb1845f91dccfe97
BLAKE2b-256 5921f0e5dafeb59a9f0aac1c1a9fb9104e34cd0f8b97475029ac2424456c49e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2cdefa89a8c33ed8fcd2a46aef14c36e5b0893351699546faaf05a590e4275cf
MD5 7820010beab25c9ad3ec2b3b1bef2da1
BLAKE2b-256 a2a9ef797bcc53a22117dc8cfa1c7fb9a2338d6b1366b9e3f845c13a1c531f71

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytensor-2.15.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 628ece6cf1aa416190212aae08bbb4140fe7a8584d493f127065ad13d0791759
MD5 390d34ef35af073465761f44a68252a3
BLAKE2b-256 1088b37ca095a28eec6816a0d95b9a5faeb417042484c21b32e8768ea105b4a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5bec3fb1f0d6b88b97eb871f685dc61ad4c580ab2b111168ca7d70e9d875847b
MD5 fd1914e4f41348272d320c9c85b1794d
BLAKE2b-256 dc7395aa74a59c7f174f9c4c32fd179ae7de36dbafb490d71a4580d0ea64be10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 7d8f90a85a18b374ba51f01d0f0cd924e409abafc0d3dd42f0d0e72772b4b502
MD5 054136e5f88e174935e7882ff76db382
BLAKE2b-256 2e1d512653036da960cd86650c4ac202134a70f982beb6c54be51743f2bc1fc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b145862a126677f94f464a7f621dceefa369adcf20492311cc10f368772f543
MD5 bb4b7d08cc36953e3ad982de92c2d155
BLAKE2b-256 209f40d0025341aedc461290c9e8852d2517c7313df268de19c42347416b8681

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.15.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 157138a2888a04202d37e758e46d061bbd2fca312167b0076ebe58a50414f500
MD5 89144788233afe7f96f98ab68109ac28
BLAKE2b-256 6fc635a0bfb886da90697bd95a39c295ae7339b045b92973b4e8317b8a88db76

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