Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c5e1011b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 1 年 前同步成功
通知
2292
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c5e1011b
编写于
11月 14, 2022
作者:
N
Nyakku Shigure
提交者:
GitHub
11月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CodeStyle][F821] refactor unittests utility function `parameterized` related code (#47869)
上级
18549417
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
52 deletion
+17
-52
python/paddle/fluid/tests/unittests/distribution/parameterize.py
...paddle/fluid/tests/unittests/distribution/parameterize.py
+5
-42
python/paddle/fluid/tests/unittests/fft/test_fft_with_static_graph.py
...e/fluid/tests/unittests/fft/test_fft_with_static_graph.py
+12
-10
未找到文件。
python/paddle/fluid/tests/unittests/distribution/parameterize.py
浏览文件 @
c5e1011b
...
...
@@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
collections
import
contextlib
import
functools
import
inspect
import
re
import
sys
from
unittest
import
SkipTest
import
numpy
as
np
import
config
...
...
@@ -72,7 +73,6 @@ def parameterize_cls(fields, values=None):
def
parameterize_func
(
input
,
name_func
=
None
,
doc_func
=
None
,
skip_on_empty
=
False
):
doc_func
=
doc_func
or
default_doc_func
name_func
=
name_func
or
default_name_func
def
wrapper
(
f
,
instance
=
None
):
...
...
@@ -87,7 +87,7 @@ def parameterize_func(
"`parameterized.expand([], skip_on_empty=True)` to skip "
"this test when the input is empty)"
)
return
wraps
(
f
)(
skip_on_empty_helper
)
return
functools
.
wraps
(
f
)(
skip_on_empty_helper
)
digits
=
len
(
str
(
len
(
parameters
)
-
1
))
for
num
,
p
in
enumerate
(
parameters
):
...
...
@@ -100,7 +100,7 @@ def parameterize_func(
# patch objects between new functions
nf
=
reapply_patches_if_need
(
f
)
frame_locals
[
name
]
=
param_as_standalone_func
(
p
,
nf
,
name
)
frame_locals
[
name
].
__doc__
=
doc_func
(
f
,
num
,
p
)
frame_locals
[
name
].
__doc__
=
f
.
__doc__
# Delete original patches to prevent new function from evaluating
# original patching object as well as re-constrfucted patches.
...
...
@@ -113,7 +113,7 @@ def parameterize_func(
def
reapply_patches_if_need
(
func
):
def
dummy_wrapper
(
orgfunc
):
@
wraps
(
orgfunc
)
@
functools
.
wraps
(
orgfunc
)
def
dummy_func
(
*
args
,
**
kwargs
):
return
orgfunc
(
*
args
,
**
kwargs
)
...
...
@@ -142,27 +142,6 @@ def default_name_func(func, num, p):
return
base_name
+
name_suffix
def
default_doc_func
(
func
,
num
,
p
):
if
func
.
__doc__
is
None
:
return
None
all_args_with_values
=
parameterized_argument_value_pairs
(
func
,
p
)
# Assumes that the function passed is a bound method.
descs
=
[
"%s=%s"
%
(
n
,
short_repr
(
v
))
for
n
,
v
in
all_args_with_values
]
# The documentation might be a multiline string, so split it
# and just work with the first string, ignoring the period
# at the end if there is one.
first
,
nl
,
rest
=
func
.
__doc__
.
lstrip
().
partition
(
"
\n
"
)
suffix
=
""
if
first
.
endswith
(
"."
):
suffix
=
"."
first
=
first
[:
-
1
]
args
=
"%s[with %s]"
%
(
len
(
first
)
and
" "
or
""
,
", "
.
join
(
descs
))
return
""
.
join
(
to_text
(
x
)
for
x
in
[
first
.
rstrip
(),
args
,
suffix
,
nl
,
rest
])
def
param_as_standalone_func
(
p
,
func
,
name
):
@
functools
.
wraps
(
func
)
def
standalone_func
(
*
a
):
...
...
@@ -252,22 +231,6 @@ def to_safe_name(s):
return
str
(
re
.
sub
(
"[^a-zA-Z0-9_]+"
,
"_"
,
s
))
@
contextlib
.
contextmanager
def
stgraph
(
func
,
*
args
):
"""static graph exec context"""
paddle
.
enable_static
()
mp
,
sp
=
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()
with
paddle
.
static
.
program_guard
(
mp
,
sp
):
input
=
paddle
.
static
.
data
(
'input'
,
x
.
shape
,
dtype
=
x
.
dtype
)
output
=
func
(
input
,
n
,
axes
,
norm
)
exe
=
paddle
.
static
.
Executor
(
place
)
exe
.
run
(
sp
)
[
output
]
=
exe
.
run
(
mp
,
feed
=
{
'input'
:
x
},
fetch_list
=
[
output
])
yield
output
paddle
.
disable_static
()
# alias
parameterize
=
parameterize_func
param_cls
=
parameterize_cls
...
...
python/paddle/fluid/tests/unittests/fft/test_fft_with_static_graph.py
浏览文件 @
c5e1011b
...
...
@@ -1817,13 +1817,14 @@ class TestFftShift(unittest.TestCase):
paddle
.
enable_static
()
mp
,
sp
=
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()
with
paddle
.
static
.
program_guard
(
mp
,
sp
):
input
=
paddle
.
static
.
data
(
'input'
,
x
.
shape
,
dtype
=
x
.
dtype
)
output
=
paddle
.
fft
.
fftshift
(
input
,
axes
)
input
=
paddle
.
static
.
data
(
'input'
,
self
.
x
.
shape
,
dtype
=
self
.
x
.
dtype
)
output
=
paddle
.
fft
.
fftshift
(
input
,
self
.
axes
)
exe
=
paddle
.
static
.
Executor
(
place
)
exe
=
paddle
.
static
.
Executor
(
self
.
place
)
exe
.
run
(
sp
)
[
output
]
=
exe
.
run
(
mp
,
feed
=
{
'input'
:
x
},
fetch_list
=
[
output
])
yield
output
[
output
]
=
exe
.
run
(
mp
,
feed
=
{
'input'
:
self
.
x
},
fetch_list
=
[
output
])
paddle
.
disable_static
()
...
...
@@ -1848,13 +1849,14 @@ class TestIfftShift(unittest.TestCase):
paddle
.
enable_static
()
mp
,
sp
=
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()
with
paddle
.
static
.
program_guard
(
mp
,
sp
):
input
=
paddle
.
static
.
data
(
'input'
,
x
.
shape
,
dtype
=
x
.
dtype
)
output
=
paddle
.
fft
.
ifftshift
(
input
,
axes
)
input
=
paddle
.
static
.
data
(
'input'
,
self
.
x
.
shape
,
dtype
=
self
.
x
.
dtype
)
output
=
paddle
.
fft
.
ifftshift
(
input
,
self
.
axes
)
exe
=
paddle
.
static
.
Executor
(
place
)
exe
=
paddle
.
static
.
Executor
(
self
.
place
)
exe
.
run
(
sp
)
[
output
]
=
exe
.
run
(
mp
,
feed
=
{
'input'
:
x
},
fetch_list
=
[
output
])
yield
output
[
output
]
=
exe
.
run
(
mp
,
feed
=
{
'input'
:
self
.
x
},
fetch_list
=
[
output
])
paddle
.
disable_static
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录