Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d6858fe2
提交
d6858fe2
authored
6月 18, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
6月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make Elemwise.infer_shape return TensorType-ed values
上级
90a0f733
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
5 行删除
+20
-5
elemwise.py
aesara/tensor/elemwise.py
+5
-3
test_elemwise.py
tests/tensor/test_elemwise.py
+15
-2
没有找到文件。
aesara/tensor/elemwise.py
浏览文件 @
d6858fe2
from
copy
import
copy
from
copy
import
copy
from
typing
import
Tuple
,
Union
from
typing
import
List
,
Tuple
,
Union
import
numpy
as
np
import
numpy
as
np
...
@@ -29,6 +29,7 @@ from aesara.tensor.type import (
...
@@ -29,6 +29,7 @@ from aesara.tensor.type import (
float_dtypes
,
float_dtypes
,
lvector
,
lvector
,
)
)
from
aesara.tensor.var
import
TensorVariable
from
aesara.utils
import
uniq
from
aesara.utils
import
uniq
...
@@ -802,7 +803,7 @@ class Elemwise(OpenMPOp):
...
@@ -802,7 +803,7 @@ class Elemwise(OpenMPOp):
else
:
else
:
storage
[
0
]
=
variable
storage
[
0
]
=
variable
def
infer_shape
(
self
,
fgraph
,
node
,
i_shapes
):
def
infer_shape
(
self
,
fgraph
,
node
,
i_shapes
)
->
List
[
Tuple
[
TensorVariable
,
...
]]
:
if
len
(
node
.
outputs
)
>
1
:
if
len
(
node
.
outputs
)
>
1
:
from
aesara.tensor.basic_opt
import
ShapeError
from
aesara.tensor.basic_opt
import
ShapeError
...
@@ -813,7 +814,8 @@ class Elemwise(OpenMPOp):
...
@@ -813,7 +814,8 @@ class Elemwise(OpenMPOp):
out_shape
=
aesara
.
tensor
.
broadcast_shape
(
*
i_shapes
,
arrays_are_shapes
=
True
)
out_shape
=
aesara
.
tensor
.
broadcast_shape
(
*
i_shapes
,
arrays_are_shapes
=
True
)
return
[
out_shape
]
# The `as_tensor_variable` should convert `ScalarType`s to `TensorType`s
return
[
tuple
(
as_tensor_variable
(
s
)
for
s
in
out_shape
)]
def
_c_all
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
def
_c_all
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
# Some `Op`s directly call `Elemwise._c_all` or `Elemwise.c_code`
# Some `Op`s directly call `Elemwise._c_all` or `Elemwise.c_code`
...
...
tests/tensor/test_elemwise.py
浏览文件 @
d6858fe2
...
@@ -26,6 +26,7 @@ from aesara.tensor.type import (
...
@@ -26,6 +26,7 @@ from aesara.tensor.type import (
bmatrix
,
bmatrix
,
bscalar
,
bscalar
,
discrete_dtypes
,
discrete_dtypes
,
lscalar
,
matrix
,
matrix
,
scalar
,
scalar
,
tensor
,
tensor
,
...
@@ -815,8 +816,8 @@ class TestElemwise(unittest_tools.InferShapeTester):
...
@@ -815,8 +816,8 @@ class TestElemwise(unittest_tools.InferShapeTester):
assert
len
(
res_shape
)
==
1
assert
len
(
res_shape
)
==
1
assert
len
(
res_shape
[
0
])
==
2
assert
len
(
res_shape
[
0
])
==
2
assert
res_shape
[
0
][
0
]
.
data
==
1
assert
aesara
.
get_scalar_constant_value
(
res_shape
[
0
][
0
])
==
1
assert
res_shape
[
0
][
1
]
.
data
==
1
assert
aesara
.
get_scalar_constant_value
(
res_shape
[
0
][
1
])
==
1
def
test_multi_output
(
self
):
def
test_multi_output
(
self
):
class
CustomElemwise
(
Elemwise
):
class
CustomElemwise
(
Elemwise
):
...
@@ -841,6 +842,18 @@ class TestElemwise(unittest_tools.InferShapeTester):
...
@@ -841,6 +842,18 @@ class TestElemwise(unittest_tools.InferShapeTester):
with
pytest
.
raises
(
ShapeError
):
with
pytest
.
raises
(
ShapeError
):
z_1
.
owner
.
op
.
infer_shape
(
None
,
z_1
.
owner
,
[
in_1_shape
,
in_1_shape
])
z_1
.
owner
.
op
.
infer_shape
(
None
,
z_1
.
owner
,
[
in_1_shape
,
in_1_shape
])
def
test_shape_types
(
self
):
x
=
tensor
(
np
.
float64
,
(
None
,
1
))
y
=
tensor
(
np
.
float64
,
(
50
,
10
))
z
=
x
*
y
assert
isinstance
(
z
.
owner
.
op
,
Elemwise
)
(
out_shape
,)
=
z
.
owner
.
op
.
infer_shape
(
None
,
z
.
owner
,
[(
lscalar
(),
1
),
(
50
,
10
)])
assert
all
(
isinstance
(
v
.
type
,
TensorType
)
for
v
in
out_shape
)
def
test_not_implemented_elemwise_grad
():
def
test_not_implemented_elemwise_grad
():
# Regression test for unimplemented gradient in an Elemwise Op.
# Regression test for unimplemented gradient in an Elemwise Op.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论