Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d3bd1f15
提交
d3bd1f15
authored
6月 21, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
6月 21, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more specialized static output shape to Eye
Importantly, it now provides broadcastability information which is needed elsewhere
上级
28d9d4dc
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
32 行删除
+44
-32
basic.py
pytensor/tensor/basic.py
+5
-1
test_basic.py
tests/tensor/test_basic.py
+39
-31
没有找到文件。
pytensor/tensor/basic.py
浏览文件 @
d3bd1f15
...
...
@@ -1273,6 +1273,7 @@ def triu_indices_from(
class
Eye
(
Op
):
_output_type_depends_on_input_value
=
True
__props__
=
(
"dtype"
,)
def
__init__
(
self
,
dtype
=
None
):
...
...
@@ -1287,10 +1288,13 @@ class Eye(Op):
assert
n
.
ndim
==
0
assert
m
.
ndim
==
0
assert
k
.
ndim
==
0
_
,
static_shape
=
infer_static_shape
((
n
,
m
))
return
Apply
(
self
,
[
n
,
m
,
k
],
[
TensorType
(
dtype
=
self
.
dtype
,
shape
=
(
None
,
None
)
)()],
[
TensorType
(
dtype
=
self
.
dtype
,
shape
=
static_shape
)()],
)
def
perform
(
self
,
node
,
inp
,
out_
):
...
...
tests/tensor/test_basic.py
浏览文件 @
d3bd1f15
...
...
@@ -937,38 +937,46 @@ def test_infer_static_shape():
assert
static_shape
==
(
1
,)
# This is slow for the ('int8', 3) version.
def
test_eye
():
def
check
(
dtype
,
N
,
M_
=
None
,
k
=
0
):
# PyTensor does not accept None as a tensor.
# So we must use a real value.
M
=
M_
# Currently DebugMode does not support None as inputs even if this is
# allowed.
if
M
is
None
and
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
]:
M
=
N
N_symb
=
iscalar
()
M_symb
=
iscalar
()
k_symb
=
iscalar
()
f
=
function
([
N_symb
,
M_symb
,
k_symb
],
eye
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
))
result
=
f
(
N
,
M
,
k
)
assert
np
.
allclose
(
result
,
np
.
eye
(
N
,
M_
,
k
,
dtype
=
dtype
))
assert
result
.
dtype
==
np
.
dtype
(
dtype
)
class
TestEye
:
# This is slow for the ('int8', 3) version.
def
test_basic
(
self
):
def
check
(
dtype
,
N
,
M_
=
None
,
k
=
0
):
# PyTensor does not accept None as a tensor.
# So we must use a real value.
M
=
M_
# Currently DebugMode does not support None as inputs even if this is
# allowed.
if
M
is
None
and
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
]:
M
=
N
N_symb
=
iscalar
()
M_symb
=
iscalar
()
k_symb
=
iscalar
()
f
=
function
(
[
N_symb
,
M_symb
,
k_symb
],
eye
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
)
)
result
=
f
(
N
,
M
,
k
)
assert
np
.
allclose
(
result
,
np
.
eye
(
N
,
M_
,
k
,
dtype
=
dtype
))
assert
result
.
dtype
==
np
.
dtype
(
dtype
)
for
dtype
in
ALL_DTYPES
:
check
(
dtype
,
3
)
# M != N, k = 0
check
(
dtype
,
3
,
5
)
check
(
dtype
,
5
,
3
)
# N == M, k != 0
check
(
dtype
,
3
,
3
,
1
)
check
(
dtype
,
3
,
3
,
-
1
)
# N < M, k != 0
check
(
dtype
,
3
,
5
,
1
)
check
(
dtype
,
3
,
5
,
-
1
)
# N > M, k != 0
check
(
dtype
,
5
,
3
,
1
)
check
(
dtype
,
5
,
3
,
-
1
)
for
dtype
in
ALL_DTYPES
:
check
(
dtype
,
3
)
# M != N, k = 0
check
(
dtype
,
3
,
5
)
check
(
dtype
,
5
,
3
)
# N == M, k != 0
check
(
dtype
,
3
,
3
,
1
)
check
(
dtype
,
3
,
3
,
-
1
)
# N < M, k != 0
check
(
dtype
,
3
,
5
,
1
)
check
(
dtype
,
3
,
5
,
-
1
)
# N > M, k != 0
check
(
dtype
,
5
,
3
,
1
)
check
(
dtype
,
5
,
3
,
-
1
)
def
test_static_output_type
(
self
):
l
=
lscalar
(
"l"
)
assert
eye
(
5
,
3
,
l
)
.
type
.
shape
==
(
5
,
3
)
assert
eye
(
1
,
l
,
3
)
.
type
.
shape
==
(
1
,
None
)
class
TestTriangle
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论