Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
flybirding10011
DI-treetensor
提交
f6e128a6
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,发现更多精彩内容 >>
提交
f6e128a6
编写于
9月 20, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(hansbug): add all documentation for treetensor.torch part
上级
04bebab0
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
140 addition
and
6 deletion
+140
-6
test/torch/test_tensor.py
test/torch/test_tensor.py
+137
-3
treetensor/common/trees.py
treetensor/common/trees.py
+2
-2
treetensor/torch/tensor.py
treetensor/torch/tensor.py
+1
-1
未找到文件。
test/torch/test_tensor.py
浏览文件 @
f6e128a6
...
...
@@ -5,6 +5,7 @@ from treevalue import func_treelize, typetrans, TreeValue
import
treetensor.numpy
as
tnp
import
treetensor.torch
as
ttorch
from
treetensor.common
import
Object
_all_is
=
func_treelize
(
return_type
=
ttorch
.
Tensor
)(
lambda
x
,
y
:
x
is
y
)
...
...
@@ -69,8 +70,141 @@ class TestTorchTensor:
}))
def
test_all
(
self
):
assert
(
self
.
_DEMO_1
==
self
.
_DEMO_1
).
all
()
assert
not
(
self
.
_DEMO_1
==
self
.
_DEMO_2
).
all
()
t1
=
ttorch
.
Tensor
({
'a'
:
[
True
,
True
],
'b'
:
{
'x'
:
[[
True
,
True
,
],
[
True
,
True
,
]]}
}).
all
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
t1
.
dtype
==
torch
.
bool
assert
t1
t2
=
ttorch
.
Tensor
({
'a'
:
[
True
,
False
],
'b'
:
{
'x'
:
[[
True
,
True
,
],
[
True
,
True
,
]]}
}).
all
()
assert
isinstance
(
t2
,
torch
.
Tensor
)
assert
t2
.
dtype
==
torch
.
bool
assert
not
t2
def
test_tolist
(
self
):
pass
assert
self
.
_DEMO_1
.
tolist
()
==
Object
({
'a'
:
[[
1
,
2
,
3
],
[
4
,
5
,
6
]],
'b'
:
[[
1
,
2
],
[
5
,
6
]],
'x'
:
{
'c'
:
[
3
,
5
,
6
,
7
],
'd'
:
[[[
1
,
2
],
[
8
,
9
]]],
}
})
def
test_any
(
self
):
t1
=
ttorch
.
Tensor
({
'a'
:
[
True
,
False
],
'b'
:
{
'x'
:
[[
False
,
False
,
],
[
False
,
False
,
]]}
}).
any
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
t1
.
dtype
==
torch
.
bool
assert
t1
t2
=
ttorch
.
Tensor
({
'a'
:
[
False
,
False
],
'b'
:
{
'x'
:
[[
False
,
False
,
],
[
False
,
False
,
]]}
}).
any
()
assert
isinstance
(
t2
,
torch
.
Tensor
)
assert
t2
.
dtype
==
torch
.
bool
assert
not
t2
def
test_max
(
self
):
t1
=
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
}).
max
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
t1
.
tolist
()
==
3
def
test_min
(
self
):
t1
=
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
}).
min
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
t1
.
tolist
()
==
-
1
def
test_sum
(
self
):
t1
=
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
}).
sum
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
t1
.
tolist
()
==
7
def
test_eq
(
self
):
assert
((
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
})
==
ttorch
.
Tensor
({
'a'
:
[
1
,
21
],
'b'
:
{
'x'
:
[[
-
1
,
3
],
[
12
,
-
10
]]}
}))
==
ttorch
.
Tensor
({
'a'
:
[
True
,
False
],
'b'
:
{
'x'
:
[[
False
,
True
],
[
False
,
False
]]}
})).
all
()
def
test_ne
(
self
):
assert
((
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
})
!=
ttorch
.
Tensor
({
'a'
:
[
1
,
21
],
'b'
:
{
'x'
:
[[
-
1
,
3
],
[
12
,
-
10
]]}
}))
==
ttorch
.
Tensor
({
'a'
:
[
False
,
True
],
'b'
:
{
'x'
:
[[
True
,
False
],
[
True
,
True
]]}
})).
all
()
def
test_lt
(
self
):
assert
((
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
})
<
ttorch
.
Tensor
({
'a'
:
[
1
,
21
],
'b'
:
{
'x'
:
[[
-
1
,
3
],
[
12
,
-
10
]]}
}))
==
ttorch
.
Tensor
({
'a'
:
[
False
,
True
],
'b'
:
{
'x'
:
[[
False
,
False
],
[
True
,
False
]]}
})).
all
()
def
test_le
(
self
):
assert
((
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
})
<=
ttorch
.
Tensor
({
'a'
:
[
1
,
21
],
'b'
:
{
'x'
:
[[
-
1
,
3
],
[
12
,
-
10
]]}
}))
==
ttorch
.
Tensor
({
'a'
:
[
True
,
True
],
'b'
:
{
'x'
:
[[
False
,
True
],
[
True
,
False
]]}
})).
all
()
def
test_gt
(
self
):
assert
((
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
})
>
ttorch
.
Tensor
({
'a'
:
[
1
,
21
],
'b'
:
{
'x'
:
[[
-
1
,
3
],
[
12
,
-
10
]]}
}))
==
ttorch
.
Tensor
({
'a'
:
[
False
,
False
],
'b'
:
{
'x'
:
[[
True
,
False
],
[
False
,
True
]]}
})).
all
()
def
test_ge
(
self
):
assert
((
ttorch
.
Tensor
({
'a'
:
[
1
,
2
],
'b'
:
{
'x'
:
[[
0
,
3
],
[
2
,
-
1
]]}
})
>=
ttorch
.
Tensor
({
'a'
:
[
1
,
21
],
'b'
:
{
'x'
:
[[
-
1
,
3
],
[
12
,
-
10
]]}
}))
==
ttorch
.
Tensor
({
'a'
:
[
True
,
False
],
'b'
:
{
'x'
:
[[
True
,
True
],
[
False
,
True
]]}
})).
all
()
treetensor/common/trees.py
浏览文件 @
f6e128a6
...
...
@@ -27,8 +27,8 @@ def print_tree(tree: TreeValue, repr_: Callable = str,
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``.
- 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.
"""
...
...
treetensor/torch/tensor.py
浏览文件 @
f6e128a6
...
...
@@ -88,7 +88,7 @@ class Tensor(Torch, metaclass=clsmeta(_to_tensor, allow_dict=True)):
>>> 'b': [1, 2, 3],
>>> 'c': True,
>>> }).tolist()
Tree
Object({
Object({
'a': [[1, 2], [3, 4]],
'b': [1, 2, 3],
'c': True,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录