Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d47ce12b
提交
d47ce12b
authored
4月 12, 2022
作者:
Ricardo
提交者:
Brandon T. Willard
4月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not use c_code for non-dense inputs in CheckAndRaise
上级
5e7b095c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
1 行删除
+23
-1
raise_op.py
aesara/raise_op.py
+6
-1
test_raise_op.py
tests/test_raise_op.py
+17
-0
没有找到文件。
aesara/raise_op.py
浏览文件 @
d47ce12b
...
@@ -10,6 +10,7 @@ from aesara.graph.basic import Apply, Variable
...
@@ -10,6 +10,7 @@ from aesara.graph.basic import Apply, Variable
from
aesara.link.c.op
import
COp
from
aesara.link.c.op
import
COp
from
aesara.link.c.params_type
import
ParamsType
from
aesara.link.c.params_type
import
ParamsType
from
aesara.link.c.type
import
Generic
from
aesara.link.c.type
import
Generic
from
aesara.tensor.type
import
DenseTensorType
class
ExceptionType
(
Generic
):
class
ExceptionType
(
Generic
):
...
@@ -101,6 +102,10 @@ class CheckAndRaise(COp):
...
@@ -101,6 +102,10 @@ class CheckAndRaise(COp):
return
[[
1
]]
+
[[
0
]]
*
(
len
(
node
.
inputs
)
-
1
)
return
[[
1
]]
+
[[
0
]]
*
(
len
(
node
.
inputs
)
-
1
)
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
props
):
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
props
):
if
not
isinstance
(
node
.
inputs
[
0
]
.
type
,
DenseTensorType
):
raise
NotImplementedError
(
f
"CheckAndRaise c_code not implemented for input type {node.inputs[0].type}"
)
value_name
,
*
cond_names
=
inames
value_name
,
*
cond_names
=
inames
out_name
=
onames
[
0
]
out_name
=
onames
[
0
]
check
=
[]
check
=
[]
...
@@ -129,7 +134,7 @@ class CheckAndRaise(COp):
...
@@ -129,7 +134,7 @@ class CheckAndRaise(COp):
return
res
return
res
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,
0
)
return
(
1
,
1
)
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
return
[
input_shapes
[
0
]]
return
[
input_shapes
[
0
]]
...
...
tests/test_raise_op.py
浏览文件 @
d47ce12b
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
import
scipy.sparse
import
aesara
import
aesara
import
aesara.tensor
as
at
import
aesara.tensor
as
at
from
aesara.compile.mode
import
OPT_FAST_RUN
,
Mode
from
aesara.compile.mode
import
OPT_FAST_RUN
,
Mode
from
aesara.graph.basic
import
Constant
,
equal_computations
from
aesara.graph.basic
import
Constant
,
equal_computations
from
aesara.raise_op
import
Assert
,
CheckAndRaise
,
assert_op
from
aesara.raise_op
import
Assert
,
CheckAndRaise
,
assert_op
from
aesara.sparse
import
as_sparse_variable
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
...
@@ -114,3 +116,18 @@ class TestCheckAndRaiseInferShape(utt.InferShapeTester):
...
@@ -114,3 +116,18 @@ class TestCheckAndRaiseInferShape(utt.InferShapeTester):
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
admat
,
adscal
,
bdscal
],
[
out
],
[
admat_val
,
adscal_val
,
bdscal_val
],
Assert
[
admat
,
adscal
,
bdscal
],
[
out
],
[
admat_val
,
adscal_val
,
bdscal_val
],
Assert
)
)
def
test_CheckAndRaise_sparse_variable
():
check_and_raise
=
CheckAndRaise
(
ValueError
,
"sparse_check"
)
spe1
=
scipy
.
sparse
.
csc_matrix
(
scipy
.
sparse
.
eye
(
5
,
3
))
aspe1
=
as_sparse_variable
(
spe1
)
a1
=
check_and_raise
(
aspe1
,
aspe1
.
sum
()
>
2
)
assert
a1
.
sum
()
.
eval
()
==
3
spe2
=
scipy
.
sparse
.
csc_matrix
(
scipy
.
sparse
.
eye
(
5
,
1
))
aspe2
=
as_sparse_variable
(
spe2
)
a2
=
check_and_raise
(
aspe1
,
aspe2
.
sum
()
>
2
)
with
pytest
.
raises
(
ValueError
,
match
=
"sparse_check"
):
a2
.
sum
()
.
eval
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论