Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
916e863f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
916e863f
编写于
6月 15, 2018
作者:
T
Tao Luo
提交者:
GitHub
6月 15, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11504 from reyoung/feature/polish_generate_fn
Polish inline math and duplicable/optional in auto generated doc
上级
0329ee74
3571df87
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
10 deletion
+19
-10
python/paddle/fluid/layers/layer_function_generator.py
python/paddle/fluid/layers/layer_function_generator.py
+19
-10
未找到文件。
python/paddle/fluid/layers/layer_function_generator.py
浏览文件 @
916e863f
...
@@ -44,6 +44,11 @@ def _type_to_str_(tp):
...
@@ -44,6 +44,11 @@ def _type_to_str_(tp):
return
framework_pb2
.
AttrType
.
Name
(
tp
)
return
framework_pb2
.
AttrType
.
Name
(
tp
)
_two_dollar_pattern_
=
re
.
compile
(
r
"\$\$([^\$]+)\$\$"
)
_single_dollar_pattern_
=
re
.
compile
(
r
"\$([^\$]+)\$"
)
_two_bang_pattern_
=
re
.
compile
(
r
"!!([^!]+)!!"
)
def
_generate_doc_string_
(
op_proto
):
def
_generate_doc_string_
(
op_proto
):
"""
"""
Generate docstring by OpProto
Generate docstring by OpProto
...
@@ -55,22 +60,26 @@ def _generate_doc_string_(op_proto):
...
@@ -55,22 +60,26 @@ def _generate_doc_string_(op_proto):
str: the document string
str: the document string
"""
"""
def
escape_math
(
text
):
return
_two_bang_pattern_
.
sub
(
r
'$$\1$$'
,
_single_dollar_pattern_
.
sub
(
r
':math:`\1`'
,
_two_dollar_pattern_
.
sub
(
r
"!!\1!!"
,
text
)))
if
not
isinstance
(
op_proto
,
framework_pb2
.
OpProto
):
if
not
isinstance
(
op_proto
,
framework_pb2
.
OpProto
):
raise
TypeError
(
"OpProto should be `framework_pb2.OpProto`"
)
raise
TypeError
(
"OpProto should be `framework_pb2.OpProto`"
)
buf
=
cStringIO
.
StringIO
()
buf
=
cStringIO
.
StringIO
()
buf
.
write
(
op_proto
.
comment
)
buf
.
write
(
escape_math
(
op_proto
.
comment
)
)
buf
.
write
(
'
\n
Args:
\n
'
)
buf
.
write
(
'
\n
Args:
\n
'
)
for
each_input
in
op_proto
.
inputs
:
for
each_input
in
op_proto
.
inputs
:
line_begin
=
' {0}: '
.
format
(
_convert_
(
each_input
.
name
))
line_begin
=
' {0}: '
.
format
(
_convert_
(
each_input
.
name
))
buf
.
write
(
line_begin
)
buf
.
write
(
line_begin
)
buf
.
write
(
each_input
.
comment
)
buf
.
write
(
escape_math
(
each_input
.
comment
))
buf
.
write
(
'
\n
'
)
if
each_input
.
duplicable
:
buf
.
write
(
' '
*
len
(
line_begin
))
buf
.
write
(
" Duplicatable."
)
buf
.
write
(
'Duplicable: '
)
if
each_input
.
dispensable
:
buf
.
write
(
str
(
each_input
.
duplicable
))
buf
.
write
(
" Optional."
)
buf
.
write
(
' Optional: '
)
buf
.
write
(
str
(
each_input
.
dispensable
))
buf
.
write
(
'
\n
'
)
buf
.
write
(
'
\n
'
)
skip_attrs
=
OpProtoHolder
.
generated_op_attr_names
()
skip_attrs
=
OpProtoHolder
.
generated_op_attr_names
()
...
@@ -83,7 +92,7 @@ def _generate_doc_string_(op_proto):
...
@@ -83,7 +92,7 @@ def _generate_doc_string_(op_proto):
buf
.
write
(
' ('
)
buf
.
write
(
' ('
)
buf
.
write
(
_type_to_str_
(
each_attr
.
type
))
buf
.
write
(
_type_to_str_
(
each_attr
.
type
))
buf
.
write
(
'): '
)
buf
.
write
(
'): '
)
buf
.
write
(
e
ach_attr
.
comment
)
buf
.
write
(
e
scape_math
(
each_attr
.
comment
)
)
buf
.
write
(
'
\n
'
)
buf
.
write
(
'
\n
'
)
if
len
(
op_proto
.
outputs
)
!=
0
:
if
len
(
op_proto
.
outputs
)
!=
0
:
...
@@ -92,7 +101,7 @@ def _generate_doc_string_(op_proto):
...
@@ -92,7 +101,7 @@ def _generate_doc_string_(op_proto):
for
each_opt
in
op_proto
.
outputs
:
for
each_opt
in
op_proto
.
outputs
:
if
not
each_opt
.
intermediate
:
if
not
each_opt
.
intermediate
:
break
break
buf
.
write
(
e
ach_opt
.
comment
)
buf
.
write
(
e
scape_math
(
each_opt
.
comment
)
)
return
buf
.
getvalue
()
return
buf
.
getvalue
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录