Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
8d47be57
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
8
Star
4
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8d47be57
编写于
6月 19, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
!285 Fix issue that parsing special expression is uncorrected, and code duplication.
Merge pull request !285 from ggpolar/br_wzk_dev
上级
10a84730
9725d3c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
8 deletion
+32
-8
mindinsight/mindconverter/ast_edits.py
mindinsight/mindconverter/ast_edits.py
+26
-1
mindinsight/mindconverter/code_analysis.py
mindinsight/mindconverter/code_analysis.py
+6
-7
未找到文件。
mindinsight/mindconverter/ast_edits.py
浏览文件 @
8d47be57
...
@@ -477,6 +477,31 @@ class AstEditVisitor(ast.NodeVisitor):
...
@@ -477,6 +477,31 @@ class AstEditVisitor(ast.NodeVisitor):
return
standard_api_call_name
,
match_case
return
standard_api_call_name
,
match_case
@
staticmethod
def
_get_call_parameters_str
(
call_node
):
"""Get parameters string for a call node."""
if
not
isinstance
(
call_node
,
ast
.
Call
):
raise
NodeTypeNotSupport
(
'It is not ast.Call node type.'
)
parameters_str
=
''
call_str
=
pasta
.
dump
(
call_node
)
call_name
=
pasta
.
dump
(
call_node
.
func
)
last_parameter_str
=
''
if
call_node
.
args
:
last_parameter_str
=
pasta
.
dump
(
call_node
.
args
[
-
1
])
if
call_node
.
keywords
:
last_parameter_str
=
pasta
.
dump
(
call_node
.
keywords
[
-
1
])
if
last_parameter_str
:
left_parenthesis_pos
=
call_str
.
find
(
call_name
)
+
len
(
call_name
)
# call is like abc.call(a, b,), last parameter is b,
# but parameters string must have last ',' character after the last parameter b.
last_parameter_pos
=
call_str
.
rfind
(
last_parameter_str
)
+
len
(
last_parameter_str
)
right_parenthesis_pos
=
call_str
.
find
(
')'
,
last_parameter_pos
)
# parameters start pos must skip '(' character for calling.
parameters_str
=
call_str
[
left_parenthesis_pos
+
1
:
right_parenthesis_pos
]
return
parameters_str
def
mapping_api
(
self
,
call_node
,
check_context
=
True
):
def
mapping_api
(
self
,
call_node
,
check_context
=
True
):
"""
"""
Convert api_name in code to MindSpore api, if api_name is a python api, code will not convert.
Convert api_name in code to MindSpore api, if api_name is a python api, code will not convert.
...
@@ -498,7 +523,7 @@ class AstEditVisitor(ast.NodeVisitor):
...
@@ -498,7 +523,7 @@ class AstEditVisitor(ast.NodeVisitor):
return
code
return
code
# find full api expected to be converted. eg:expr="nn.Conv2d(1,2,3)" args_str="(1,2,3)"
# find full api expected to be converted. eg:expr="nn.Conv2d(1,2,3)" args_str="(1,2,3)"
args_str
=
code
[
len
(
api_call_name
):].
strip
()
args_str
=
'('
+
self
.
_get_call_parameters_str
(
call_node
)
+
')'
try
:
try
:
api_name
,
_
=
self
.
_infer_api_name
(
call_node
.
func
,
check_context
)
api_name
,
_
=
self
.
_infer_api_name
(
call_node
.
func
,
check_context
)
...
...
mindinsight/mindconverter/code_analysis.py
浏览文件 @
8d47be57
...
@@ -193,13 +193,12 @@ class CodeAnalyzer(ast.NodeVisitor):
...
@@ -193,13 +193,12 @@ class CodeAnalyzer(ast.NodeVisitor):
for
node_references
in
root_scope
.
external_references
.
values
():
for
node_references
in
root_scope
.
external_references
.
values
():
for
node_ref
in
node_references
:
for
node_ref
in
node_references
:
if
node_ref
.
name_ref
:
if
node_ref
.
name_ref
:
# (from)import alias, node_ref.name_ref.id is alias name
# case1: (from)import alias, node_ref.name_ref.id is node_ref.name_ref.definition.asname.
if
node_ref
.
name_ref
.
definition
.
asname
==
node_ref
.
name_ref
.
id
:
# case2: import without alias, node_ref.name_ref.definition.asname is None.
external_name_ref
[
node_ref
.
name_ref
.
id
]
=
node_ref
# e.g., import a.b.c, the reference definition id maybe is a, a.b or a.b.c.
# import without alias, node_ref.name_ref.definition.asname is None.
# The reference id a.b.c is really wanted.
# e.g., import a.b.c, reference maybe is a, a.b or a.b.c in the root_scope.external_references.
if
node_ref
.
name_ref
.
id
in
[
node_ref
.
name_ref
.
definition
.
asname
,
# The reference a.b.c is really wanted.
node_ref
.
name_ref
.
definition
.
name
]:
elif
node_ref
.
name_ref
.
definition
.
name
==
node_ref
.
name_ref
.
id
:
external_name_ref
[
node_ref
.
name_ref
.
id
]
=
node_ref
external_name_ref
[
node_ref
.
name_ref
.
id
]
=
node_ref
else
:
else
:
pass
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录