Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
31ab8fdd
提交
31ab8fdd
authored
3月 11, 2022
作者:
Ricardo
提交者:
Ricardo Vieira
3月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix `DiffOp` output type when input has partially known shape
上级
fde62163
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
1 行删除
+34
-1
extra_ops.py
aesara/tensor/extra_ops.py
+12
-1
test_extra_ops.py
tests/tensor/test_extra_ops.py
+22
-0
没有找到文件。
aesara/tensor/extra_ops.py
浏览文件 @
31ab8fdd
...
@@ -2,6 +2,7 @@ from collections.abc import Collection
...
@@ -2,6 +2,7 @@ from collections.abc import Collection
from
typing
import
Iterable
,
Tuple
,
Union
from
typing
import
Iterable
,
Tuple
,
Union
import
numpy
as
np
import
numpy
as
np
import
numpy.core.numeric
import
aesara
import
aesara
from
aesara.gradient
import
(
from
aesara.gradient
import
(
...
@@ -482,7 +483,17 @@ class DiffOp(Op):
...
@@ -482,7 +483,17 @@ class DiffOp(Op):
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
at
.
as_tensor_variable
(
x
)
x
=
at
.
as_tensor_variable
(
x
)
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
axis
=
numpy
.
core
.
numeric
.
normalize_axis_index
(
self
.
axis
,
x
.
ndim
)
shape
=
[
None
]
*
x
.
type
.
ndim
for
i
,
shape_i
in
enumerate
(
x
.
type
.
shape
):
if
shape_i
is
None
:
continue
if
i
==
axis
:
shape
[
i
]
=
max
(
0
,
shape_i
-
self
.
n
)
else
:
shape
[
i
]
=
shape_i
out_type
=
TensorType
(
dtype
=
x
.
type
.
dtype
,
shape
=
shape
)
return
Apply
(
self
,
[
x
],
[
out_type
()])
def
perform
(
self
,
node
,
inputs
,
output_storage
):
def
perform
(
self
,
node
,
inputs
,
output_storage
):
x
=
inputs
[
0
]
x
=
inputs
[
0
]
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
31ab8fdd
...
@@ -302,6 +302,28 @@ class TestDiffOp(utt.InferShapeTester):
...
@@ -302,6 +302,28 @@ class TestDiffOp(utt.InferShapeTester):
g
=
aesara
.
function
([
x
],
diff
(
x
,
n
=
n
,
axis
=
axis
))
g
=
aesara
.
function
([
x
],
diff
(
x
,
n
=
n
,
axis
=
axis
))
assert
np
.
allclose
(
np
.
diff
(
a
,
n
=
n
,
axis
=
axis
),
g
(
a
))
assert
np
.
allclose
(
np
.
diff
(
a
,
n
=
n
,
axis
=
axis
),
g
(
a
))
@pytest.mark.parametrize
(
"x_type"
,
(
at
.
TensorType
(
"float64"
,
(
None
,
None
)),
at
.
TensorType
(
"float64"
,
(
None
,
30
)),
at
.
TensorType
(
"float64"
,
(
10
,
None
)),
at
.
TensorType
(
"float64"
,
(
10
,
30
)),
),
)
def
test_output_type
(
self
,
x_type
):
x
=
x_type
(
"x"
)
x_test
=
np
.
empty
((
10
,
30
))
for
axis
in
(
-
2
,
-
1
,
0
,
1
):
for
n
in
(
0
,
1
,
2
,
10
,
11
):
out
=
diff
(
x
,
n
=
n
,
axis
=
axis
)
out_test
=
np
.
diff
(
x_test
,
n
=
n
,
axis
=
axis
)
for
i
in
range
(
2
):
if
x
.
type
.
shape
[
i
]
is
None
:
assert
out
.
type
.
shape
[
i
]
is
None
else
:
assert
out
.
type
.
shape
[
i
]
==
out_test
.
shape
[
i
]
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
x
=
matrix
(
"x"
)
x
=
matrix
(
"x"
)
a
=
np
.
random
.
random
((
30
,
50
))
.
astype
(
config
.
floatX
)
a
=
np
.
random
.
random
((
30
,
50
))
.
astype
(
config
.
floatX
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论