Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyTensor is a fork of Aesara -- a Python library for defining, optimizing, and efficiently evaluating mathematical expressions involving multi-dimensional arrays.

License

NotificationsYou must be signed in to change notification settings

jessegrabowski/pytensor

 
 

Repository files navigation

PyTensor logo

Tests StatusCoverage

PyTensor is a Python library that allows one to define, optimize, andefficiently evaluate mathematical expressions involving multi-dimensional arrays.It provides the computational backend forPyMC.

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 providescompilation via C,JAX, andNumba
  • Contrary to PyTorch and TensorFlow, PyTensor maintains a static graph which can be modified in-place toallow for advanced optimizations

Getting started

importpytensorfrompytensorimporttensoraspt# Declare two symbolic floating-point scalarsa=pt.dscalar("a")b=pt.dscalar("b")# Create a simple example expressionc=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)assertf_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)assertf_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]

Seethe PyTensor documentation for in-depth tutorials.

Installation

The latest release of PyTensor can be installed from PyPI usingpip:

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 usingpip:

pip install git+https://github.com/pymc-devs/pytensor

Background

PyTensor is a fork ofAesara, which is a fork ofTheano.

Contributing

We welcome bug reports and fixes and improvements to the documentation.

For more information on contributing, please see thecontributing guide.

A good place to start contributing is by looking through the issueshere.

About

PyTensor is a fork of Aesara -- a Python library for defining, optimizing, and efficiently evaluating mathematical expressions involving multi-dimensional arrays.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python96.6%
  • C++1.5%
  • C1.5%
  • Cython0.3%
  • Shell0.1%
  • HTML0.0%

[8]ページ先頭

©2009-2025 Movatter.jp