Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
93c6e52a
P
Paddle
项目概览
wzpei9
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
93c6e52a
编写于
11月 12, 2017
作者:
Y
Yu Yang
提交者:
GitHub
11月 12, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Automatically generated doc string for generated layers (#5585)
上级
e602c707
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
5 deletion
+66
-5
python/paddle/v2/framework/layers.py
python/paddle/v2/framework/layers.py
+55
-5
python/paddle/v2/framework/tests/test_create_op_doc_string.py
...on/paddle/v2/framework/tests/test_create_op_doc_string.py
+11
-0
未找到文件。
python/paddle/v2/framework/layers.py
浏览文件 @
93c6e52a
import
paddle.v2.framework.core
as
core
import
paddle.v2.framework.proto.framework_pb2
as
framework_pb2
from
paddle.v2.framework.framework
import
OpProtoHolder
,
Variable
,
Program
,
\
Operator
from
paddle.v2.framework.initializer
import
ConstantInitializer
,
\
NormalInitializer
from
paddle.v2.framework.layer_helper
import
LayerHelper
,
unique_name
import
re
import
cStringIO
__all__
=
[
'fc'
,
'data'
,
'cross_entropy'
,
'conv2d'
,
'pool2d'
,
'embedding'
,
'concat'
,
...
...
@@ -240,6 +242,58 @@ def _convert_(name):
return
re
.
sub
(
'([a-z0-9])([A-Z])'
,
r
'\1_\2'
,
s1
).
lower
()
def
_generate_doc_string_
(
op_proto
):
"""
Generate docstring by OpProto
Args:
op_proto (framework_pb2.OpProto): a protobuf message typed OpProto
Returns:
str: the document string
"""
def
_type_to_str_
(
tp
):
return
framework_pb2
.
AttrType
.
Name
(
tp
)
if
not
isinstance
(
op_proto
,
framework_pb2
.
OpProto
):
raise
TypeError
(
"OpProto should be `framework_pb2.OpProto`"
)
buf
=
cStringIO
.
StringIO
()
buf
.
write
(
op_proto
.
comment
)
buf
.
write
(
'
\n
Args:
\n
'
)
for
each_input
in
op_proto
.
inputs
:
line_begin
=
' {0}: '
.
format
(
_convert_
(
each_input
.
name
))
buf
.
write
(
line_begin
)
buf
.
write
(
each_input
.
comment
)
buf
.
write
(
'
\n
'
)
buf
.
write
(
' '
*
len
(
line_begin
))
buf
.
write
(
'Duplicable: '
)
buf
.
write
(
str
(
each_input
.
duplicable
))
buf
.
write
(
' Optional: '
)
buf
.
write
(
str
(
each_input
.
dispensable
))
buf
.
write
(
'
\n
'
)
for
each_attr
in
op_proto
.
attrs
:
buf
.
write
(
' '
)
buf
.
write
(
each_attr
.
name
)
buf
.
write
(
' ('
)
buf
.
write
(
_type_to_str_
(
each_attr
.
type
))
buf
.
write
(
'): '
)
buf
.
write
(
each_attr
.
comment
)
buf
.
write
(
'
\n
'
)
if
len
(
op_proto
.
outputs
)
!=
0
:
buf
.
write
(
'
\n
Returns:
\n
'
)
buf
.
write
(
' '
)
for
each_opt
in
op_proto
.
outputs
:
if
not
each_opt
.
intermediate
:
break
buf
.
write
(
each_opt
.
comment
)
return
buf
.
getvalue
()
def
_create_op_func_
(
op_type
):
"""
Create an Operator for a Function.
...
...
@@ -298,11 +352,6 @@ def _create_op_func_(op_type):
return
dtype
def
func
(
**
kwargs
):
"""
This function implements the function for the operator. This process
involves doing the sanity check (using the function above), reading
inputs from protobuf and applying the activations on top.
"""
helper
=
LayerHelper
(
op_type
,
**
kwargs
)
dtype
=
infer_and_check_data_type
(
op_proto
,
**
kwargs
)
...
...
@@ -326,6 +375,7 @@ def _create_op_func_(op_type):
func
.
__name__
=
op_type
globals
()[
op_type
]
=
func
func
.
__doc__
=
_generate_doc_string_
(
op_proto
)
global
__all__
__all__
.
append
(
op_type
)
...
...
python/paddle/v2/framework/tests/test_create_op_doc_string.py
0 → 100644
浏览文件 @
93c6e52a
import
unittest
import
paddle.v2.framework.layers
as
layers
class
TestDocString
(
unittest
.
TestCase
):
def
test_layer_doc_string
(
self
):
print
layers
.
dropout
.
__doc__
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录