Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ec6a3153
提交
ec6a3153
authored
5月 30, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
6月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update README dprint output
上级
1944353c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
63 行增加
和
63 行删除
+63
-63
README.rst
README.rst
+63
-63
没有找到文件。
README.rst
浏览文件 @
ec6a3153
...
@@ -22,69 +22,69 @@ Getting started
...
@@ -22,69 +22,69 @@ Getting started
.. code-block:: python
.. code-block:: python
import pytensor
import pytensor
from pytensor import tensor as pt
from pytensor import tensor as pt
# Declare two symbolic floating-point scalars
# Declare two symbolic floating-point scalars
a = pt.dscalar("a")
a = pt.dscalar("a")
b = pt.dscalar("b")
b = pt.dscalar("b")
# Create a simple example expression
# Create a simple example expression
c = a + b
c = a + b
# Convert the expression into a callable object that takes `(a, b)`
# Convert the expression into a callable object that takes `(a, b)`
# values as input and computes the value of `c`.
# values as input and computes the value of `c`.
f_c = pytensor.function([a, b], c)
f_c = pytensor.function([a, b], c)
assert f_c(1.5, 2.5) == 4.0
assert f_c(1.5, 2.5) == 4.0
# Compute the gradient of the example expression with respect to `a`
# Compute the gradient of the example expression with respect to `a`
dc = pytensor.grad(c, a)
dc = pytensor.grad(c, a)
f_dc = pytensor.function([a, b], dc)
f_dc = pytensor.function([a, b], dc)
assert f_dc(1.5, 2.5) == 1.0
assert f_dc(1.5, 2.5) == 1.0
# Compiling functions with `pytensor.function` also optimizes
# Compiling functions with `pytensor.function` also optimizes
# expression graphs by removing unnecessary operations and
# expression graphs by removing unnecessary operations and
# replacing computations with more efficient ones.
# replacing computations with more efficient ones.
v = pt.vector("v")
v = pt.vector("v")
M = pt.matrix("M")
M = pt.matrix("M")
d = a/a + (M + a).dot(v)
d = a/a + (M + a).dot(v)
pytensor.dprint(d)
pytensor.dprint(d)
# Elemwise{add,no_inplace} [id A] ''
# Add [id A]
# |InplaceDimShuffle{x} [id B] ''
# ├─ ExpandDims{axis=0} [id B]
# | |Elemwise{true_div,no_inplace} [id C] ''
# │ └─ True_div [id C]
# | |
a [id D]
# │ ├─
a [id D]
# | |
a [id D]
# │ └─
a [id D]
# |dot [id E] ''
# └─ dot [id E]
# |Elemwise{add,no_inplace} [id F] ''
# ├─ Add [id F]
# | |
M [id G]
# │ ├─
M [id G]
# | |InplaceDimShuffle{x,x} [id H] ''
# │ └─ ExpandDims{axes=[0, 1]} [id H]
# | |
a [id D]
# │ └─
a [id D]
# |
v [id I]
# └─
v [id I]
f_d = pytensor.function([a, v, M], d)
f_d = pytensor.function([a, v, M], d)
# `a/a` -> `1` and the dot product is replaced with a BLAS function
# `a/a` -> `1` and the dot product is replaced with a BLAS function
# (i.e. CGemv)
# (i.e. CGemv)
pytensor.dprint(f_d)
pytensor.dprint(f_d)
# Elemwise{Add}[(0, 1)] [id A] ''
5
# Add [id A]
5
# |TensorConstant{(1,) of 1.0}
[id B]
# ├─ [1.]
[id B]
# |CGemv{inplace} [id C] ''
4
# └─ CGemv{inplace} [id C]
4
# |AllocEmpty{dtype='float64'} [id D] ''
3
# ├─ AllocEmpty{dtype='float64'} [id D]
3
# | |Shape_i{0} [id E] ''
2
# │ └─ Shape_i{0} [id E]
2
# | |
M [id F]
# │ └─
M [id F]
# |TensorConstant{1.0}
[id G]
# ├─ 1.0
[id G]
# |Elemwise{add,no_inplace} [id H] ''
1
# ├─ Add [id H]
1
# | |
M [id F]
# │ ├─
M [id F]
# | |InplaceDimShuffle{x,x} [id I] ''
0
# │ └─ ExpandDims{axes=[0, 1]} [id I]
0
# | |
a [id J]
# │ └─
a [id J]
# |
v [id K]
# ├─
v [id K]
# |TensorConstant{0.0}
[id L]
# └─ 0.0
[id L]
See `the PyTensor documentation <https://pytensor.readthedocs.io/en/latest/>`__ for in-depth tutorials.
See `the PyTensor documentation <https://pytensor.readthedocs.io/en/latest/>`__ for in-depth tutorials.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论