Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c66aa65
提交
3c66aa65
authored
4月 08, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
4月 08, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove useless int() in f-strings
上级
246714b6
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
20 行删除
+18
-20
basic.py
pytensor/scalar/basic.py
+10
-10
loop.py
pytensor/scalar/loop.py
+8
-10
没有找到文件。
pytensor/scalar/basic.py
浏览文件 @
3c66aa65
...
@@ -4333,9 +4333,9 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4333,9 +4333,9 @@ class Composite(ScalarInnerGraphOp):
# Rename internal variables
# Rename internal variables
for
i
,
r
in
enumerate
(
self
.
fgraph
.
inputs
):
for
i
,
r
in
enumerate
(
self
.
fgraph
.
inputs
):
r
.
name
=
f
"i{i
nt(i)
}"
r
.
name
=
f
"i{i}"
for
i
,
r
in
enumerate
(
self
.
fgraph
.
outputs
):
for
i
,
r
in
enumerate
(
self
.
fgraph
.
outputs
):
r
.
name
=
f
"o{i
nt(i)
}"
r
.
name
=
f
"o{i}"
io
=
set
(
self
.
fgraph
.
inputs
+
self
.
fgraph
.
outputs
)
io
=
set
(
self
.
fgraph
.
inputs
+
self
.
fgraph
.
outputs
)
for
i
,
r
in
enumerate
(
self
.
fgraph
.
variables
):
for
i
,
r
in
enumerate
(
self
.
fgraph
.
variables
):
if
(
if
(
...
@@ -4343,7 +4343,7 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4343,7 +4343,7 @@ class Composite(ScalarInnerGraphOp):
and
r
not
in
io
and
r
not
in
io
and
len
(
self
.
fgraph
.
clients
[
r
])
>
1
and
len
(
self
.
fgraph
.
clients
[
r
])
>
1
):
):
r
.
name
=
f
"t{i
nt(i)
}"
r
.
name
=
f
"t{i}"
if
len
(
self
.
fgraph
.
outputs
)
>
1
or
len
(
self
.
fgraph
.
apply_nodes
)
>
10
:
if
len
(
self
.
fgraph
.
outputs
)
>
1
or
len
(
self
.
fgraph
.
apply_nodes
)
>
10
:
self
.
_name
=
"Composite{...}"
self
.
_name
=
"Composite{...}"
...
@@ -4431,7 +4431,7 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4431,7 +4431,7 @@ class Composite(ScalarInnerGraphOp):
return
self
.
_c_code
return
self
.
_c_code
fg
=
self
.
fgraph
fg
=
self
.
fgraph
subd
=
{
e
:
f
"
%
(i{i
nt(i)
})s"
for
i
,
e
in
enumerate
(
fg
.
inputs
)}
subd
=
{
e
:
f
"
%
(i{i})s"
for
i
,
e
in
enumerate
(
fg
.
inputs
)}
for
var
in
fg
.
variables
:
for
var
in
fg
.
variables
:
if
var
.
owner
is
None
:
if
var
.
owner
is
None
:
...
@@ -4458,11 +4458,11 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4458,11 +4458,11 @@ class Composite(ScalarInnerGraphOp):
for
output
in
node
.
outputs
:
for
output
in
node
.
outputs
:
if
output
not
in
subd
:
if
output
not
in
subd
:
i
+=
1
i
+=
1
name
=
f
"V
%(id)
s_tmp{i
nt(i)
}"
name
=
f
"V
%(id)
s_tmp{i}"
subd
[
output
]
=
name
subd
[
output
]
=
name
_c_code
+=
f
"{output.type.dtype_specs()[1]} {name};
\n
"
_c_code
+=
f
"{output.type.dtype_specs()[1]} {name};
\n
"
nodename
=
f
"
%(nodename)
s_subnode{
int(j)
}"
nodename
=
f
"
%(nodename)
s_subnode{
j
}"
nodenames
.
append
(
nodename
)
nodenames
.
append
(
nodename
)
s
=
node
.
op
.
c_code
(
s
=
node
.
op
.
c_code
(
...
@@ -4470,14 +4470,14 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4470,14 +4470,14 @@ class Composite(ScalarInnerGraphOp):
nodename
,
nodename
,
[
subd
[
input
]
for
input
in
node
.
inputs
],
[
subd
[
input
]
for
input
in
node
.
inputs
],
[
subd
[
output
]
for
output
in
node
.
outputs
],
[
subd
[
output
]
for
output
in
node
.
outputs
],
dict
(
fail
=
"
%(fail)
s"
,
id
=
f
"
%(id)
s_{
int(j)
}"
),
dict
(
fail
=
"
%(fail)
s"
,
id
=
f
"
%(id)
s_{
j
}"
),
)
)
_c_code
+=
s
_c_code
+=
s
_c_code
+=
"
\n
"
_c_code
+=
"
\n
"
# Copy the temporary outputs to the real outputs
# Copy the temporary outputs to the real outputs
for
i
,
output
in
enumerate
(
fg
.
outputs
):
for
i
,
output
in
enumerate
(
fg
.
outputs
):
_c_code
+=
f
"
%
(o{i
nt(i)
})s = {subd[output]};
\n
"
_c_code
+=
f
"
%
(o{i})s = {subd[output]};
\n
"
_c_code
+=
"}
\n
"
_c_code
+=
"}
\n
"
...
@@ -4488,8 +4488,8 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4488,8 +4488,8 @@ class Composite(ScalarInnerGraphOp):
def
c_code
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
def
c_code
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
d
=
dict
(
d
=
dict
(
chain
(
chain
(
zip
((
f
"i{i
nt(i)
}"
for
i
in
range
(
len
(
inames
))),
inames
,
strict
=
True
),
zip
((
f
"i{i}"
for
i
in
range
(
len
(
inames
))),
inames
,
strict
=
True
),
zip
((
f
"o{i
nt(i)
}"
for
i
in
range
(
len
(
onames
))),
onames
,
strict
=
True
),
zip
((
f
"o{i}"
for
i
in
range
(
len
(
onames
))),
onames
,
strict
=
True
),
),
),
**
sub
,
**
sub
,
)
)
...
...
pytensor/scalar/loop.py
浏览文件 @
3c66aa65
...
@@ -212,15 +212,13 @@ class ScalarLoop(ScalarInnerGraphOp):
...
@@ -212,15 +212,13 @@ class ScalarLoop(ScalarInnerGraphOp):
# The first input is `n_steps` so we skip it in the mapping dictionary
# The first input is `n_steps` so we skip it in the mapping dictionary
n_update
=
len
(
self
.
outputs
)
-
(
1
if
self
.
is_while
else
0
)
n_update
=
len
(
self
.
outputs
)
-
(
1
if
self
.
is_while
else
0
)
carry_subd
=
{
carry_subd
=
{
c
:
f
"
%
(i{i
nt(i)
})s"
for
i
,
c
in
enumerate
(
fgraph
.
inputs
[:
n_update
],
start
=
1
)
c
:
f
"
%
(i{i})s"
for
i
,
c
in
enumerate
(
fgraph
.
inputs
[:
n_update
],
start
=
1
)
}
}
constant_subd
=
{
constant_subd
=
{
c
:
f
"
%
(i{i
nt(i)
})s"
c
:
f
"
%
(i{i})s"
for
i
,
c
in
enumerate
(
fgraph
.
inputs
[
n_update
:],
start
=
n_update
+
1
)
for
i
,
c
in
enumerate
(
fgraph
.
inputs
[
n_update
:],
start
=
n_update
+
1
)
}
}
out_subd
=
{
out_subd
=
{
u
:
f
"
%
(o{i})s"
for
i
,
u
in
enumerate
(
fgraph
.
outputs
[:
n_update
])}
u
:
f
"
%
(o{int(i)})s"
for
i
,
u
in
enumerate
(
fgraph
.
outputs
[:
n_update
])
}
until_subd
=
{
u
:
"until"
for
u
in
fgraph
.
outputs
[
n_update
:]}
until_subd
=
{
u
:
"until"
for
u
in
fgraph
.
outputs
[
n_update
:]}
subd
=
{
**
carry_subd
,
**
constant_subd
,
**
until_subd
}
subd
=
{
**
carry_subd
,
**
constant_subd
,
**
until_subd
}
...
@@ -267,11 +265,11 @@ class ScalarLoop(ScalarInnerGraphOp):
...
@@ -267,11 +265,11 @@ class ScalarLoop(ScalarInnerGraphOp):
for
output
in
node
.
outputs
:
for
output
in
node
.
outputs
:
if
output
not
in
subd
:
if
output
not
in
subd
:
i
+=
1
i
+=
1
name
=
f
"V
%(id)
s_tmp{i
nt(i)
}"
name
=
f
"V
%(id)
s_tmp{i}"
subd
[
output
]
=
name
subd
[
output
]
=
name
_c_code
+=
f
"{output.type.dtype_specs()[1]} {name};
\n
"
_c_code
+=
f
"{output.type.dtype_specs()[1]} {name};
\n
"
nodename
=
f
"
%(nodename)
s_subnode{
int(j)
}"
nodename
=
f
"
%(nodename)
s_subnode{
j
}"
nodenames
.
append
(
nodename
)
nodenames
.
append
(
nodename
)
s
=
node
.
op
.
c_code
(
s
=
node
.
op
.
c_code
(
...
@@ -281,7 +279,7 @@ class ScalarLoop(ScalarInnerGraphOp):
...
@@ -281,7 +279,7 @@ class ScalarLoop(ScalarInnerGraphOp):
# The initial value of `update` was set to `init` before the loop
# The initial value of `update` was set to `init` before the loop
[
subd
[
input
]
for
input
in
node
.
inputs
],
[
subd
[
input
]
for
input
in
node
.
inputs
],
[
subd
[
output
]
for
output
in
node
.
outputs
],
[
subd
[
output
]
for
output
in
node
.
outputs
],
dict
(
fail
=
"
%(fail)
s"
,
id
=
f
"
%(id)
s_{
int(j)
}"
),
dict
(
fail
=
"
%(fail)
s"
,
id
=
f
"
%(id)
s_{
j
}"
),
)
)
_c_code
+=
s
_c_code
+=
s
_c_code
+=
"
\n
"
_c_code
+=
"
\n
"
...
@@ -320,8 +318,8 @@ class ScalarLoop(ScalarInnerGraphOp):
...
@@ -320,8 +318,8 @@ class ScalarLoop(ScalarInnerGraphOp):
def
c_code
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
def
c_code
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
d
=
dict
(
d
=
dict
(
chain
(
chain
(
zip
((
f
"i{i
nt(i)
}"
for
i
in
range
(
len
(
inames
))),
inames
,
strict
=
True
),
zip
((
f
"i{i}"
for
i
in
range
(
len
(
inames
))),
inames
,
strict
=
True
),
zip
((
f
"o{i
nt(i)
}"
for
i
in
range
(
len
(
onames
))),
onames
,
strict
=
True
),
zip
((
f
"o{i}"
for
i
in
range
(
len
(
onames
))),
onames
,
strict
=
True
),
),
),
**
sub
,
**
sub
,
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论