Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
27781606
提交
27781606
authored
11月 15, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
11月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename replace/vectorize to replace/vectorize_graph
上级
902eeb6f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
17 行增加
和
11 行删除
+17
-11
__init__.py
pytensor/graph/__init__.py
+1
-1
replace.py
pytensor/graph/replace.py
+9
-3
blockwise.py
pytensor/tensor/blockwise.py
+2
-2
test_replace.py
tests/graph/test_replace.py
+5
-5
没有找到文件。
pytensor/graph/__init__.py
浏览文件 @
27781606
...
...
@@ -9,7 +9,7 @@ from pytensor.graph.basic import (
clone
,
ancestors
,
)
from
pytensor.graph.replace
import
clone_replace
,
graph_replace
,
vectorize
from
pytensor.graph.replace
import
clone_replace
,
graph_replace
,
vectorize
_graph
from
pytensor.graph.op
import
Op
from
pytensor.graph.type
import
Type
from
pytensor.graph.fg
import
FunctionGraph
...
...
pytensor/graph/replace.py
浏览文件 @
27781606
import
warnings
from
collections.abc
import
Iterable
,
Mapping
,
Sequence
from
functools
import
partial
,
singledispatch
from
typing
import
Optional
,
Union
,
cast
,
overload
...
...
@@ -215,7 +216,7 @@ def vectorize_node(node: Apply, *batched_inputs) -> Apply:
@overload
def
vectorize
(
def
vectorize
_graph
(
outputs
:
Variable
,
replace
:
Mapping
[
Variable
,
Variable
],
)
->
Variable
:
...
...
@@ -223,14 +224,14 @@ def vectorize(
@overload
def
vectorize
(
def
vectorize
_graph
(
outputs
:
Sequence
[
Variable
],
replace
:
Mapping
[
Variable
,
Variable
],
)
->
Sequence
[
Variable
]:
...
def
vectorize
(
def
vectorize
_graph
(
outputs
:
Union
[
Variable
,
Sequence
[
Variable
]],
replace
:
Mapping
[
Variable
,
Variable
],
)
->
Union
[
Variable
,
Sequence
[
Variable
]]:
...
...
@@ -309,3 +310,8 @@ def vectorize(
else
:
[
vect_output
]
=
seq_vect_outputs
return
vect_output
def
vectorize
(
*
args
,
**
kwargs
):
warnings
.
warn
(
"vectorize was renamed to vectorize_graph"
,
UserWarning
)
return
vectorize_node
(
*
args
,
**
kwargs
)
pytensor/tensor/blockwise.py
浏览文件 @
27781606
...
...
@@ -9,7 +9,7 @@ from pytensor.gradient import DisconnectedType
from
pytensor.graph.basic
import
Apply
,
Constant
,
Variable
from
pytensor.graph.null_type
import
NullType
from
pytensor.graph.op
import
Op
from
pytensor.graph.replace
import
_vectorize_node
,
vectorize
from
pytensor.graph.replace
import
_vectorize_node
,
vectorize
_graph
from
pytensor.tensor
import
as_tensor_variable
from
pytensor.tensor.shape
import
shape_padleft
from
pytensor.tensor.type
import
continuous_dtypes
,
discrete_dtypes
,
tensor
...
...
@@ -274,7 +274,7 @@ class Blockwise(Op):
core_igrads
=
self
.
core_op
.
L_op
(
core_inputs
,
core_outputs
,
core_ograds
)
igrads
=
vectorize
(
igrads
=
vectorize
_graph
(
[
core_igrad
for
core_igrad
in
core_igrads
if
core_igrad
is
not
None
],
replace
=
dict
(
zip
(
core_inputs
+
core_outputs
+
core_ograds
,
inputs
+
outputs
+
ograds
)
...
...
tests/graph/test_replace.py
浏览文件 @
27781606
...
...
@@ -5,7 +5,7 @@ import scipy.special
import
pytensor.tensor
as
pt
from
pytensor
import
config
,
function
,
shared
from
pytensor.graph.basic
import
equal_computations
,
graph_inputs
from
pytensor.graph.replace
import
clone_replace
,
graph_replace
,
vectorize
from
pytensor.graph.replace
import
clone_replace
,
graph_replace
,
vectorize
_graph
from
pytensor.tensor
import
dvector
,
fvector
,
vector
from
tests
import
unittest_tools
as
utt
from
tests.graph.utils
import
MyOp
,
MyVariable
...
...
@@ -226,7 +226,7 @@ class TestGraphReplace:
oc
=
graph_replace
([
o
],
{
fake
:
x
.
clone
()},
strict
=
True
)
class
TestVectorize
:
class
TestVectorize
Graph
:
# TODO: Add tests with multiple outputs, constants, and other singleton types
def
test_basic
(
self
):
...
...
@@ -234,10 +234,10 @@ class TestVectorize:
y
=
pt
.
exp
(
x
)
/
pt
.
sum
(
pt
.
exp
(
x
))
new_x
=
pt
.
matrix
(
"new_x"
)
[
new_y
]
=
vectorize
([
y
],
{
x
:
new_x
})
[
new_y
]
=
vectorize
_graph
([
y
],
{
x
:
new_x
})
# Check we can pass both a sequence or a single variable
alt_new_y
=
vectorize
(
y
,
{
x
:
new_x
})
alt_new_y
=
vectorize
_graph
(
y
,
{
x
:
new_x
})
assert
equal_computations
([
new_y
],
[
alt_new_y
])
fn
=
function
([
new_x
],
new_y
)
...
...
@@ -253,7 +253,7 @@ class TestVectorize:
y2
=
x
[
-
1
]
new_x
=
pt
.
matrix
(
"new_x"
)
[
new_y1
,
new_y2
]
=
vectorize
([
y1
,
y2
],
{
x
:
new_x
})
[
new_y1
,
new_y2
]
=
vectorize
_graph
([
y1
,
y2
],
{
x
:
new_x
})
fn
=
function
([
new_x
],
[
new_y1
,
new_y2
])
new_x_test
=
np
.
arange
(
9
)
.
reshape
(
3
,
3
)
.
astype
(
config
.
floatX
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论