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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pytensor-2.18.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pytensor-2.18.1-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pytensor-2.18.1-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pytensor-2.18.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.18.1-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pytensor-2.18.1-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pytensor-2.18.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.18.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.18.1.tar.gz.

File metadata

  • Download URL: pytensor-2.18.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.6

File hashes

Hashes for pytensor-2.18.1.tar.gz
Algorithm Hash digest
SHA256 9681f035401b024c625fb97c494d2817b62af057ebd522de0daead1e627b4cf2
MD5 fc98cf23e9ef8167c3e2880ad4003462
BLAKE2b-256 d5226c2bf5d12a97704689e6869dd4fd6bdd1a914ec1c215b00e22a0df2bc7c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5341bedb20754b90b47df7bec58616fbc2ef93072ce2ece505e72070d4d26ebe
MD5 d52703fd07b80151baa2e777d28e6a81
BLAKE2b-256 845b057310a9445df7ee1850246288a2bda775c075b567a3a55bf6775024d31e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 01771057f6fc66a484351d9c6fc0117ebb58d5efebde5716b821be2fa4346ced
MD5 dc2e881670393d730aac6ac618dc59da
BLAKE2b-256 4aefa0110c00071788b787d1f8e3a1ed75e5dad8c0ed981a77583fb0e8494eed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 0e626686c5ffb250b793539e9f29f31dfccc88c0919bffcf9db1ed5848e7d966
MD5 b25731aa324627594cd50c01738399cd
BLAKE2b-256 674654cf1c8706f496ce51dbb351c94a60b4c99421b2422db368d9a16466a085

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54d6d2b6d40aa0fe96d29c509614d920c4de06bb2a532a92c3e1e68634435849
MD5 c6f3cdb1a8ac7aad9c2521ac1bbd9384
BLAKE2b-256 7d3288c0d09aa0106ebf85283d31e0e4c4d3f051271f3f67fe700694015961ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 35eb64abf8ddd276676533399dc5d01dc060a941dfdf75a4c50bc9d190f178fb
MD5 27087b0eb2f62923e6dd81a3060bd3e2
BLAKE2b-256 30e73c8c8c4fee1210e54fb873409fc3f5b199cda5a524fffb8d7547986639b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 40d62347c1eb53c06c5cfc6b31cbfd8b08251872a92e283ae9affa921ea3da23
MD5 57d14d6e7ca78da04debff2cd68333c4
BLAKE2b-256 da8f44d7b1f3e82bd95da00f4ca933bda1e75e91c443783e26fdff8cb11f59a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 7a41f43cec4a8838ea24833cc4c516eeca69184f3c51ffc2de0ee5c24aa18839
MD5 b7db8f6d2d36d056cd240cda0c522917
BLAKE2b-256 9bb6cdfc130d9a63cad8b1da3ecb9878a06e635821c3dded338600e4077c48b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 b649c28104a549458400ce449c70506e916f8848d8245d921e17d027d344fa8a
MD5 0a3950c185fe58e0f6474c68ae53a3fb
BLAKE2b-256 ab2ecd6cba3f8b8dd2fcb39decd2085513c9e0e47686344fe93d71db0cf65f0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2410a3a4130820d85c3e3df1443efa08855a090dc60f04350fb238f1b16a7e07
MD5 187983ef1a8a38f58c84989a5db55b40
BLAKE2b-256 9be9334326d5d2ab7e4879cb5b2aac5e72d6d7fa87281b39b3a44d099fdae177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2054f0c2adaa3756690c12b04257915150f07533bf4def898a61e8a7ebc3d31c
MD5 e9563e63799f59b5243a36bea2230505
BLAKE2b-256 355ddfff4f45cef34f0ed40d13974d0d7116d2a9d231dae3191d7c5767969a76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytensor-2.18.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.6

File hashes

Hashes for pytensor-2.18.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f8746cc6f67c38550df4c83fdd2eb8a4ecfc301a0398f4674dafcca595fc4890
MD5 164b99440c83bbf78ef0ba9d91ee10fc
BLAKE2b-256 0e781fbf21d6c0d9326a820df0a9c335bedc0ffa622fe08f83bcb8228b67d035

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2a8e1a080dd402733666fdeb4097f40392261b5dfca12c1e4ef861af660a64f2
MD5 7ccea39a8764e54b8e362e57834aae9f
BLAKE2b-256 7c15073c9d06090df1807acb565e7c17bab9f7134093443cc314668c842cb3b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 9c72c3b9e1d24369812d125d22146c260c16cf8cfdadce41c69889aa5962afbf
MD5 51abbf991b1c70cfe9759977ea32728d
BLAKE2b-256 fdb495bed2d6c93844df4bebaf9e1d748e53ac3c85083f4b46685b8ff19c4a54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7402788978a8909d762692235458f867a5d248c093e356f820fe6e04c9ccd14a
MD5 425fd06eb9d94653647fe4c54691f311
BLAKE2b-256 1af11a8be2c8965c240e1eaa69a5fc06b168603ef28d9699319f22c9e4435657

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytensor-2.18.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0927ddf6e915ce7757ffe460b50aa4024ece4555979a241fae4f624e212706a1
MD5 b841781b5fc00a33c58d1c7922787c5c
BLAKE2b-256 9eabe791997eaecc9655b52bf1e3103d4aa2b629815896e241f753781637d0df

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