Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d7a02fa1
提交
d7a02fa1
authored
12月 16, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
12月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for Constants in OpFromGraph constructor
上级
10bb77bf
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
8 行删除
+30
-8
builders.py
aesara/compile/builders.py
+13
-4
test_builders.py
tests/compile/test_builders.py
+17
-4
没有找到文件。
aesara/compile/builders.py
浏览文件 @
d7a02fa1
...
...
@@ -11,6 +11,7 @@ from aesara.configdefaults import config
from
aesara.gradient
import
DisconnectedType
,
Rop
,
grad
from
aesara.graph.basic
import
(
Apply
,
Constant
,
Variable
,
clone_replace
,
graph_inputs
,
...
...
@@ -331,13 +332,21 @@ class OpFromGraph(Op, HasInnerGraph):
name
=
None
,
**
kwargs
,
):
if
not
isinstance
(
outputs
,
list
):
raise
TypeError
(
f
"outputs must be list, got {type(outputs)}"
)
if
not
(
isinstance
(
inputs
,
list
)
and
isinstance
(
outputs
,
list
)):
raise
TypeError
(
"Inputs and outputs must be lists"
)
for
i
in
inputs
+
outputs
:
if
not
isinstance
(
i
,
Variable
):
raise
TypeError
(
"inputs and outputs must be Variable instances"
,
i
)
raise
TypeError
(
f
"Inputs and outputs must be Variable instances; got {i}"
)
if
i
in
inputs
and
isinstance
(
i
,
Constant
):
raise
TypeError
(
f
"Constants not allowed as inputs; {i}"
)
if
"updates"
in
kwargs
or
"givens"
in
kwargs
:
raise
TypeError
(
"updates and givens are not allowed here"
)
raise
NotImplementedError
(
"Updates and givens are not allowed here"
)
self
.
is_inline
=
inline
# To correctly support shared variables the inner fct should
# not see them. Otherwise there is a problem with the gradient.
...
...
tests/compile/test_builders.py
浏览文件 @
d7a02fa1
...
...
@@ -19,12 +19,28 @@ from aesara.tensor.math import round as aet_round
from
aesara.tensor.math
import
sigmoid
from
aesara.tensor.math
import
sum
as
aet_sum
from
aesara.tensor.random.utils
import
RandomStream
from
aesara.tensor.shape
import
specify_shape
from
aesara.tensor.type
import
TensorType
,
matrices
,
matrix
,
scalar
,
vector
,
vectors
from
tests
import
unittest_tools
from
tests.graph.utils
import
MyVariable
class
TestOpFromGraph
(
unittest_tools
.
InferShapeTester
):
def
test_valid_input
(
self
):
x
,
y
,
z
=
matrices
(
"xyz"
)
with
pytest
.
raises
(
TypeError
):
OpFromGraph
((
x
,),
(
x
,))
with
pytest
.
raises
(
TypeError
):
OpFromGraph
([
1
],
[
1
])
with
pytest
.
raises
(
TypeError
):
OpFromGraph
([
x
,
as_tensor
(
1
)],
[
x
])
with
pytest
.
raises
(
NotImplementedError
):
OpFromGraph
([
x
],
[
x
],
updates
=
{})
@pytest.mark.parametrize
(
"cls_ofg"
,
[
OpFromGraph
,
partial
(
OpFromGraph
,
inline
=
True
)]
)
...
...
@@ -39,9 +55,6 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
xv
=
np
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
yv
=
np
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
*
3
zv
=
np
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
*
5
# print function, function.__module__
# print fn.maker.fgraph.toposort()
fn
(
xv
,
yv
,
zv
)
assert
np
.
all
(
8.0
==
fn
(
xv
,
yv
,
zv
))
assert
np
.
all
(
8.0
==
fn
(
xv
,
yv
,
zv
))
...
...
@@ -412,7 +425,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
# shape
x
=
MyVariable
(
"x"
)
y
=
matrix
(
"y"
)
z
=
as_tensor
([
1
,
2
]
)
z
=
specify_shape
(
vector
(
"z"
),
(
2
,)
)
op_graph
=
OpFromGraph
([
x
,
y
,
z
],
[
x
,
y
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论