Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
迷茫中的程序媛
DI-treetensor
提交
04bebab0
D
DI-treetensor
项目概览
迷茫中的程序媛
/
DI-treetensor
与 Fork 源项目一致
Fork自
OpenDILab开源决策智能平台 / DI-treetensor
通知
1
Star
1
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,发现更多精彩内容 >>
提交
04bebab0
编写于
9月 20, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc(hansbug): add documentation for treetensor.common and treetensor.utils
上级
e77d7718
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
87 addition
and
2 deletion
+87
-2
docs/source/api_doc/common/trees.rst
docs/source/api_doc/common/trees.rst
+8
-1
docs/source/api_doc/numpy/index.rst
docs/source/api_doc/numpy/index.rst
+4
-0
docs/source/api_doc/torch/index.rst
docs/source/api_doc/torch/index.rst
+4
-0
docs/source/api_doc/utils/doc.rst
docs/source/api_doc/utils/doc.rst
+14
-0
treetensor/common/object.py
treetensor/common/object.py
+5
-0
treetensor/common/trees.py
treetensor/common/trees.py
+52
-1
未找到文件。
docs/source/api_doc/common/trees.rst
浏览文件 @
04bebab0
...
...
@@ -13,5 +13,12 @@ BaseTreeStruct
-----------------------
.. autoclass:: BaseTreeStruct
:members:
:members: __repr__, __str__
clsmeta
------------------------
.. autofunction:: clsmeta
docs/source/api_doc/numpy/index.rst
浏览文件 @
04bebab0
treetensor.numpy
=====================
.. py:currentmodule:: treetensor.numpy
.. automodule:: treetensor.numpy
.. toctree::
:maxdepth: 2
...
...
docs/source/api_doc/torch/index.rst
浏览文件 @
04bebab0
treetensor.torch
=====================
.. py:currentmodule:: treetensor.torch
.. automodule:: treetensor.torch
.. toctree::
:maxdepth: 2
...
...
docs/source/api_doc/utils/doc.rst
0 → 100644
浏览文件 @
04bebab0
Documentation Decorators
=============================
.. py:currentmodule:: treetensor.utils
.. automodule:: treetensor.utils.doc
doc_from
------------------
.. autofunction:: doc_from
treetensor/common/object.py
浏览文件 @
04bebab0
...
...
@@ -10,6 +10,11 @@ def _object(obj):
class
Object
(
BaseTreeStruct
,
metaclass
=
clsmeta
(
_object
,
allow_dict
=
True
)):
"""
Overview:
Generic object tree class, used in :py:mod:`treetensor.numpy` and :py:mod:`treetensor.torch`.
"""
def
__init__
(
self
,
data
):
"""
In :class:`treetensor.common.Object`, object or object tree can be initialized.
...
...
treetensor/common/trees.py
浏览文件 @
04bebab0
...
...
@@ -3,6 +3,7 @@ import io
import
os
from
functools
import
partial
from
typing
import
Optional
,
Tuple
,
Callable
from
typing
import
Type
from
treevalue
import
func_treelize
as
original_func_treelize
from
treevalue
import
general_tree_value
,
TreeValue
...
...
@@ -20,6 +21,17 @@ __all__ = [
def
print_tree
(
tree
:
TreeValue
,
repr_
:
Callable
=
str
,
ascii_
:
bool
=
False
,
show_node_id
:
bool
=
True
,
file
=
None
):
"""
Overview:
Print a tree structure to the given file.
Arguments:
- tree (:obj:`TreeValue`): Given tree object.
- repr\_ (:obj:`Callable`): Representation function, default is ``str``.
- ascii\_ (:obj:`bool`): Use ascii to print the tree, default is ``False``.
- show_node_id (:obj:`bool`): Show node id of the tree, default is ``True``.
- file: Output file of this print procedure, default is ``None`` which means to stdout.
"""
print_to_file
=
partial
(
builtins
.
print
,
file
=
file
)
node_ids
=
{}
if
ascii_
:
...
...
@@ -86,15 +98,54 @@ class BaseTreeStruct(general_tree_value()):
"""
def
__repr__
(
self
):
"""
Get the tree-based representation format of this object.
Examples::
>>> from treetensor.common import Object
>>> repr(Object(1)) # Object is subclass of BaseTreeStruct
'1'
>>> repr(Object({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}))
'<Object 0x7fe00b121220>
\n
├── a --> 1
\n
├── b --> 2
\n
└── x --> <Object 0x7fe00b121c10>
\n
├── c --> 3
\n
└── d --> 4
\n
'
>>> Object({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}})
<Object 0x7fe00b1271c0>
├── a --> 1
├── b --> 2
└── x --> <Object 0x7fe00b127910>
├── c --> 3
└── d --> 4
"""
with
io
.
StringIO
()
as
sfile
:
print_tree
(
self
,
repr_
=
repr
,
ascii_
=
False
,
file
=
sfile
)
return
sfile
.
getvalue
()
def
__str__
(
self
):
"""
The same as :py:meth:`BaseTreeStruct.__repr__`.
"""
return
self
.
__repr__
()
def
clsmeta
(
func
,
allow_dict
:
bool
=
False
):
def
clsmeta
(
func
,
allow_dict
:
bool
=
False
)
->
Type
[
type
]:
"""
Overview:
Create a metaclass based on generating function.
Used in :py:class:`treetensor.common.Object`,
:py:class:`treetensor.torch.Tensor` and :py:class:`treetensor.torch.Size`.
Can do modify onto the constructor function of the classes.
Arguments:
- func: Generating function.
- allow_dict (:obj:`bool`): Auto transform dictionary to :py:class:`treevalue.TreeValue` class,
\
default is ``False``.
Returns:
- metaclass (:obj:`Type[type]`): Metaclass for creating a new class.
"""
class
_TempTreeValue
(
TreeValue
):
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录