Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
99589bb9
提交
99589bb9
authored
6月 21, 2024
作者:
Virgile Andreani
提交者:
Ricardo Vieira
7月 03, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify boolean operations with any and all
上级
8a6d2aae
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
8 行增加
和
10 行删除
+8
-10
gradient.py
pytensor/gradient.py
+6
-8
elemwise.py
pytensor/tensor/elemwise.py
+2
-2
没有找到文件。
pytensor/gradient.py
浏览文件 @
99589bb9
...
@@ -1041,13 +1041,12 @@ def _populate_grad_dict(var_to_app_to_idx, grad_dict, wrt, cost_name=None):
...
@@ -1041,13 +1041,12 @@ def _populate_grad_dict(var_to_app_to_idx, grad_dict, wrt, cost_name=None):
# list of bools indicating if each input is connected to the cost
# list of bools indicating if each input is connected to the cost
inputs_connected
=
[
inputs_connected
=
[
(
(
True
any
(
in
[
input_to_output
and
output_to_cost
input_to_output
and
output_to_cost
for
input_to_output
,
output_to_cost
in
zip
(
for
input_to_output
,
output_to_cost
in
zip
(
input_to_outputs
,
outputs_connected
input_to_outputs
,
outputs_connected
)
)
]
)
)
)
for
input_to_outputs
in
connection_pattern
for
input_to_outputs
in
connection_pattern
]
]
...
@@ -1067,25 +1066,24 @@ def _populate_grad_dict(var_to_app_to_idx, grad_dict, wrt, cost_name=None):
...
@@ -1067,25 +1066,24 @@ def _populate_grad_dict(var_to_app_to_idx, grad_dict, wrt, cost_name=None):
# List of bools indicating if each input only has NullType outputs
# List of bools indicating if each input only has NullType outputs
only_connected_to_nan
=
[
only_connected_to_nan
=
[
(
(
True
not
any
(
not
in
[
in_to_out
and
out_to_cost
and
not
out_nan
in_to_out
and
out_to_cost
and
not
out_nan
for
in_to_out
,
out_to_cost
,
out_nan
in
zip
(
for
in_to_out
,
out_to_cost
,
out_nan
in
zip
(
in_to_outs
,
outputs_connected
,
ograd_is_nan
in_to_outs
,
outputs_connected
,
ograd_is_nan
)
)
]
)
)
)
for
in_to_outs
in
connection_pattern
for
in_to_outs
in
connection_pattern
]
]
if
True
not
in
inputs_connected
:
if
not
any
(
inputs_connected
)
:
# All outputs of this op are disconnected so we can skip
# All outputs of this op are disconnected so we can skip
# Calling the op's grad method and report that the inputs
# Calling the op's grad method and report that the inputs
# are disconnected
# are disconnected
# (The op's grad method could do this too, but this saves the
# (The op's grad method could do this too, but this saves the
# implementer the trouble of worrying about this case)
# implementer the trouble of worrying about this case)
input_grads
=
[
disconnected_type
()
for
ipt
in
inputs
]
input_grads
=
[
disconnected_type
()
for
ipt
in
inputs
]
elif
False
not
in
only_connected_to_nan
:
elif
all
(
only_connected_to_nan
)
:
# All inputs are only connected to nan gradients, so we don't
# All inputs are only connected to nan gradients, so we don't
# need to bother calling the grad method. We know the gradient
# need to bother calling the grad method. We know the gradient
# with respect to all connected inputs is nan.
# with respect to all connected inputs is nan.
...
...
pytensor/tensor/elemwise.py
浏览文件 @
99589bb9
...
@@ -201,12 +201,12 @@ class DimShuffle(ExternalCOp):
...
@@ -201,12 +201,12 @@ class DimShuffle(ExternalCOp):
f
"input is incorrect for this op. Expected {self.input_broadcastable}, got {ib}."
f
"input is incorrect for this op. Expected {self.input_broadcastable}, got {ib}."
)
)
for
expected
,
b
in
zip
(
self
.
input_broadcastable
,
ib
):
for
expected
,
b
in
zip
(
self
.
input_broadcastable
,
ib
):
if
expected
is
True
and
b
is
False
:
if
expected
and
not
b
:
raise
TypeError
(
raise
TypeError
(
"The broadcastable pattern of the "
"The broadcastable pattern of the "
f
"input is incorrect for this op. Expected {self.input_broadcastable}, got {ib}."
f
"input is incorrect for this op. Expected {self.input_broadcastable}, got {ib}."
)
)
# else, expected == b or
expected is False and b is True
# else, expected == b or
not expected and b
# Both case are good.
# Both case are good.
out_static_shape
=
[]
out_static_shape
=
[]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论