Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a5f8b693
提交
a5f8b693
authored
9月 17, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
9月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Type conversion and checking in IfElse.make_node
上级
8528590d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
16 行删除
+25
-16
ifelse.py
aesara/ifelse.py
+14
-9
test_ifelse.py
tests/test_ifelse.py
+11
-7
没有找到文件。
aesara/ifelse.py
浏览文件 @
a5f8b693
...
...
@@ -175,6 +175,11 @@ class IfElse(_NoPythonOp):
if
not
isinstance
(
input_f
,
Variable
):
input_f
=
as_symbolic
(
input_f
)
if
type
(
input_f
.
type
)
!=
type
(
input_t
.
type
):
# noqa: E721
raise
TypeError
(
f
"Input types {type(input_t.type)} and {type(input_f.type)} do not match."
)
if
isinstance
(
input_t
.
type
,
HasDataType
)
and
isinstance
(
input_f
.
type
,
HasDataType
):
...
...
@@ -207,18 +212,18 @@ class IfElse(_NoPythonOp):
# TODO FIXME: The presence of this keyword is a strong
# assumption. Find something that's guaranteed by the/a
# confirmed interface.
output_
type
_t
=
input_t
.
type
.
clone
(
shape
=
new_shape
)()
output_
type
_f
=
input_f
.
type
.
clone
(
shape
=
new_shape
)()
output_
var
_t
=
input_t
.
type
.
clone
(
shape
=
new_shape
)()
output_
var
_f
=
input_f
.
type
.
clone
(
shape
=
new_shape
)()
else
:
output_
type
_t
=
input_t
.
type
()
output_
type
_f
=
input_f
.
type
()
output_
var
_t
=
input_t
.
type
()
output_
var
_f
=
input_f
.
type
()
input_t
=
output_type_f
.
type
.
convert
_variable
(
input_t
)
input_f
=
output_type_t
.
type
.
convert
_variable
(
input_f
)
input_t
_
=
output_var_f
.
type
.
filter
_variable
(
input_t
)
input_f
_
=
output_var_t
.
type
.
filter
_variable
(
input_f
)
new_inputs_true_branch
.
append
(
input_t
)
new_inputs_false_branch
.
append
(
input_f
)
output_vars
.
append
(
output_
type
_t
)
new_inputs_true_branch
.
append
(
input_t
_
)
new_inputs_false_branch
.
append
(
input_f
_
)
output_vars
.
append
(
output_
var
_t
)
return
Apply
(
self
,
...
...
tests/test_ifelse.py
浏览文件 @
a5f8b693
...
...
@@ -325,22 +325,24 @@ class TestIfelse(utt.OptimizationTestMixin):
with
pytest
.
raises
(
TypeError
):
ifelse
(
cond
,
y
,
x
)
def
test_sparse_tensor_error
(
self
):
def
test_sparse_conversions
(
self
):
from
aesara.sparse
import
matrix
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
data
=
rng
.
random
((
2
,
3
))
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
y
=
aesara
.
sparse
.
matrix
(
"csc"
,
dtype
=
self
.
dtype
,
name
=
"y"
)
z
=
aesara
.
sparse
.
matrix
(
"csr"
,
dtype
=
self
.
dtype
,
name
=
"z"
)
y
=
matrix
(
"csc"
,
dtype
=
self
.
dtype
,
name
=
"y"
)
z
=
matrix
(
"csr"
,
dtype
=
self
.
dtype
,
name
=
"z"
)
cond
=
iscalar
(
"cond"
)
with
pytest
.
raises
(
NotImplementedError
):
with
pytest
.
raises
(
TypeError
,
match
=
".*do not match."
):
ifelse
(
cond
,
x
,
y
)
with
pytest
.
raises
(
NotImplementedError
):
with
pytest
.
raises
(
TypeError
,
match
=
".*do not match."
):
ifelse
(
cond
,
y
,
x
)
with
pytest
.
raises
(
NotImplemented
Error
):
with
pytest
.
raises
(
Type
Error
):
ifelse
(
cond
,
x
,
z
)
with
pytest
.
raises
(
NotImplemented
Error
):
with
pytest
.
raises
(
Type
Error
):
ifelse
(
cond
,
z
,
x
)
with
pytest
.
raises
(
TypeError
):
ifelse
(
cond
,
y
,
z
)
...
...
@@ -534,6 +536,8 @@ class TestIfelse(utt.OptimizationTestMixin):
[
((
2
,),
(
3
,),
np
.
r_
[
1.0
,
2.0
],
np
.
r_
[
1.0
,
2.0
,
3.0
],
(
None
,)),
((
None
,),
(
3
,),
np
.
r_
[
1.0
,
2.0
],
np
.
r_
[
1.0
,
2.0
,
3.0
],
(
None
,)),
((
3
,),
(
None
,),
np
.
r_
[
1.0
,
2.0
,
3.0
],
np
.
r_
[
1.0
,
2.0
],
(
None
,)),
((
2
,
1
),
(
None
,
1
),
np
.
c_
[[
1.0
,
2.0
]],
np
.
c_
[[
1.0
,
2.0
,
3.0
]],
(
None
,
1
)),
((
3
,),
(
3
,),
np
.
r_
[
1.0
,
2.0
,
3.0
],
np
.
r_
[
1.0
,
2.0
,
3.0
],
(
3
,)),
((
1
,),
(
3
,),
np
.
r_
[
1.0
],
np
.
r_
[
1.0
,
2.0
,
3.0
],
(
None
,)),
],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论