Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
flybirding10011
DI-treetensor
提交
e6afc90e
D
DI-treetensor
项目概览
flybirding10011
/
DI-treetensor
与 Fork 源项目一致
Fork自
OpenDILab开源决策智能平台 / DI-treetensor
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DI-treetensor
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e6afc90e
编写于
9月 12, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc(hansbug): optimize documentation in treetensor.torch
上级
ec55fa86
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
31 deletion
+44
-31
docs/source/apidoc_gen.py
docs/source/apidoc_gen.py
+12
-10
treetensor/torch/funcs.py
treetensor/torch/funcs.py
+23
-20
treetensor/utils/doc.py
treetensor/utils/doc.py
+9
-1
未找到文件。
docs/source/apidoc_gen.py
浏览文件 @
e6afc90e
...
@@ -3,6 +3,7 @@ import types
...
@@ -3,6 +3,7 @@ import types
from
typing
import
List
from
typing
import
List
_DOC_TAG
=
'__doc_names__'
_DOC_TAG
=
'__doc_names__'
_DIRECT_DOC_TAG
=
'__direct_doc__'
def
_is_tagged_name
(
clazz
,
name
):
def
_is_tagged_name
(
clazz
,
name
):
...
@@ -38,14 +39,15 @@ if __name__ == '__main__':
...
@@ -38,14 +39,15 @@ if __name__ == '__main__':
print
()
print
()
_item
=
getattr
(
_module
,
_name
)
_item
=
getattr
(
_module
,
_name
)
if
isinstance
(
_item
,
types
.
FunctionType
):
if
getattr
(
_item
,
_DIRECT_DOC_TAG
,
None
):
print
(
f
'.. autofunction::
{
package_name
}
.
{
_name
}
'
)
print
(
_item
.
__doc__
)
print
()
elif
isinstance
(
_item
,
type
):
print
(
f
'.. autoclass::
{
package_name
}
.
{
_name
}
'
)
print
(
f
' :members:
{
", "
.
join
(
sorted
(
_find_class_members
(
_item
)))
}
'
)
print
()
else
:
else
:
print
(
f
'.. autodata::
{
package_name
}
.
{
_name
}
'
)
if
isinstance
(
_item
,
types
.
FunctionType
):
print
(
f
' :annotation:'
)
print
(
f
'.. autofunction::
{
package_name
}
.
{
_name
}
'
)
print
()
elif
isinstance
(
_item
,
type
):
print
(
f
'.. autoclass::
{
package_name
}
.
{
_name
}
'
)
print
(
f
' :members:
{
", "
.
join
(
sorted
(
_find_class_members
(
_item
)))
}
'
)
else
:
print
(
f
'.. autodata::
{
package_name
}
.
{
_name
}
'
)
print
(
f
' :annotation:'
)
print
()
treetensor/torch/funcs.py
浏览文件 @
e6afc90e
...
@@ -3,15 +3,18 @@ from typing import List
...
@@ -3,15 +3,18 @@ from typing import List
import
torch
import
torch
from
treevalue
import
func_treelize
as
original_func_treelize
from
treevalue
import
func_treelize
as
original_func_treelize
from
treevalue.utils
import
post_process
from
.tensor
import
TreeTensor
,
tireduce
from
.tensor
import
TreeTensor
,
tireduce
from
..common
import
TreeObject
,
ireduce
from
..common
import
TreeObject
,
ireduce
from
..utils
import
inherit_doc
as
original_inherit_doc
from
..utils
import
replaceable_partial
,
direct_doc
,
inherit_doc
from
..utils
import
replaceable_partial
def
_doc_stripper
(
src
,
_
,
lines
:
List
[
str
]):
def
_doc_stripper
(
src
,
_
,
lines
:
List
[
str
]):
_name
,
_version
=
src
.
__name__
,
torch
.
__version__
_name
,
_version
=
src
.
__name__
,
torch
.
__version__
if
lines
:
lines
[
0
]
=
f
'.. function::
{
lines
[
0
]
}
'
return
[
return
[
f
'.. note::'
,
f
'.. note::'
,
f
''
,
f
''
,
...
@@ -20,12 +23,12 @@ def _doc_stripper(src, _, lines: List[str]):
...
@@ -20,12 +23,12 @@ def _doc_stripper(src, _, lines: List[str]):
f
' in `torch v
{
_version
}
<https://pytorch.org/docs/
{
_version
}
/>`_.'
,
f
' in `torch v
{
_version
}
<https://pytorch.org/docs/
{
_version
}
/>`_.'
,
f
' **Its arguments
\'
arrangements depend on the version of pytorch you installed**.'
,
f
' **Its arguments
\'
arrangements depend on the version of pytorch you installed**.'
,
f
''
,
f
''
,
*
lines
[
1
:]
*
lines
,
]
]
func_treelize
=
replaceable_partial
(
original_func_treelize
,
return_type
=
TreeTensor
)
func_treelize
=
replaceable_partial
(
original_func_treelize
,
return_type
=
TreeTensor
)
inherit_doc
=
replaceable_partial
(
original_inherit_doc
,
stripper
=
_doc_stripper
)
docs
=
post_process
(
post_process
(
direct_doc
))(
replaceable_partial
(
inherit_doc
,
stripper
=
_doc_stripper
)
)
__all__
=
[
__all__
=
[
'zeros'
,
'zeros_like'
,
'zeros'
,
'zeros_like'
,
...
@@ -39,99 +42,99 @@ __all__ = [
...
@@ -39,99 +42,99 @@ __all__ = [
]
]
@
inherit_doc
(
torch
.
zeros
)
@
docs
(
torch
.
zeros
)
@
func_treelize
()
@
func_treelize
()
def
zeros
(
*
args
,
**
kwargs
):
def
zeros
(
*
args
,
**
kwargs
):
return
torch
.
zeros
(
*
args
,
**
kwargs
)
return
torch
.
zeros
(
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
zeros_like
)
@
docs
(
torch
.
zeros_like
)
@
func_treelize
()
@
func_treelize
()
def
zeros_like
(
input_
,
*
args
,
**
kwargs
):
def
zeros_like
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
zeros_like
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
zeros_like
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
randn
)
@
docs
(
torch
.
randn
)
@
func_treelize
()
@
func_treelize
()
def
randn
(
*
args
,
**
kwargs
):
def
randn
(
*
args
,
**
kwargs
):
return
torch
.
randn
(
*
args
,
**
kwargs
)
return
torch
.
randn
(
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
randn_like
)
@
docs
(
torch
.
randn_like
)
@
func_treelize
()
@
func_treelize
()
def
randn_like
(
input_
,
*
args
,
**
kwargs
):
def
randn_like
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
randn_like
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
randn_like
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
randint
)
@
docs
(
torch
.
randint
)
@
func_treelize
()
@
func_treelize
()
def
randint
(
*
args
,
**
kwargs
):
def
randint
(
*
args
,
**
kwargs
):
return
torch
.
randint
(
*
args
,
**
kwargs
)
return
torch
.
randint
(
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
randint_like
)
@
docs
(
torch
.
randint_like
)
@
func_treelize
()
@
func_treelize
()
def
randint_like
(
input_
,
*
args
,
**
kwargs
):
def
randint_like
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
randint_like
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
randint_like
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
ones
)
@
docs
(
torch
.
ones
)
@
func_treelize
()
@
func_treelize
()
def
ones
(
*
args
,
**
kwargs
):
def
ones
(
*
args
,
**
kwargs
):
return
torch
.
ones
(
*
args
,
**
kwargs
)
return
torch
.
ones
(
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
ones_like
)
@
docs
(
torch
.
ones_like
)
@
func_treelize
()
@
func_treelize
()
def
ones_like
(
input_
,
*
args
,
**
kwargs
):
def
ones_like
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
ones_like
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
ones_like
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
full
)
@
docs
(
torch
.
full
)
@
func_treelize
()
@
func_treelize
()
def
full
(
*
args
,
**
kwargs
):
def
full
(
*
args
,
**
kwargs
):
return
torch
.
full
(
*
args
,
**
kwargs
)
return
torch
.
full
(
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
full_like
)
@
docs
(
torch
.
full_like
)
@
func_treelize
()
@
func_treelize
()
def
full_like
(
input_
,
*
args
,
**
kwargs
):
def
full_like
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
full_like
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
full_like
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
empty
)
@
docs
(
torch
.
empty
)
@
func_treelize
()
@
func_treelize
()
def
empty
(
*
args
,
**
kwargs
):
def
empty
(
*
args
,
**
kwargs
):
return
torch
.
empty
(
*
args
,
**
kwargs
)
return
torch
.
empty
(
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
empty_like
)
@
docs
(
torch
.
empty_like
)
@
func_treelize
()
@
func_treelize
()
def
empty_like
(
input_
,
*
args
,
**
kwargs
):
def
empty_like
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
empty_like
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
empty_like
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
all
)
@
docs
(
torch
.
all
)
@
tireduce
(
torch
.
all
)
@
tireduce
(
torch
.
all
)
@
func_treelize
(
return_type
=
TreeObject
)
@
func_treelize
(
return_type
=
TreeObject
)
def
all
(
input_
,
*
args
,
**
kwargs
):
def
all
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
all
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
all
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
any
)
@
docs
(
torch
.
any
)
@
tireduce
(
torch
.
any
)
@
tireduce
(
torch
.
any
)
@
func_treelize
(
return_type
=
TreeObject
)
@
func_treelize
(
return_type
=
TreeObject
)
def
any
(
input_
,
*
args
,
**
kwargs
):
def
any
(
input_
,
*
args
,
**
kwargs
):
return
torch
.
any
(
input_
,
*
args
,
**
kwargs
)
return
torch
.
any
(
input_
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
eq
)
@
docs
(
torch
.
eq
)
@
func_treelize
()
@
func_treelize
()
def
eq
(
input_
,
other
,
*
args
,
**
kwargs
):
def
eq
(
input_
,
other
,
*
args
,
**
kwargs
):
return
torch
.
eq
(
input_
,
other
,
*
args
,
**
kwargs
)
return
torch
.
eq
(
input_
,
other
,
*
args
,
**
kwargs
)
@
inherit_doc
(
torch
.
equal
)
@
docs
(
torch
.
equal
)
@
ireduce
(
builtins
.
all
)
@
ireduce
(
builtins
.
all
)
@
func_treelize
()
@
func_treelize
()
def
equal
(
input_
,
other
,
*
args
,
**
kwargs
):
def
equal
(
input_
,
other
,
*
args
,
**
kwargs
):
...
...
treetensor/utils/doc.py
浏览文件 @
e6afc90e
...
@@ -2,7 +2,7 @@ import os
...
@@ -2,7 +2,7 @@ import os
from
typing
import
List
,
Optional
,
Callable
,
Any
from
typing
import
List
,
Optional
,
Callable
,
Any
__all__
=
[
__all__
=
[
'inherit_doc'
,
'inherit_doc'
,
'direct_doc'
,
]
]
...
@@ -37,3 +37,11 @@ def inherit_doc(src, stripper: Optional[Callable[[Any, Any, List[str]], List[str
...
@@ -37,3 +37,11 @@ def inherit_doc(src, stripper: Optional[Callable[[Any, Any, List[str]], List[str
return
obj
return
obj
return
_decorator
return
_decorator
_DIRECT_DOC
=
'__direct_doc__'
def
direct_doc
(
obj
):
setattr
(
obj
,
_DIRECT_DOC
,
True
)
return
obj
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录