Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
DI-treetensor
提交
a56cbc33
D
DI-treetensor
项目概览
OpenDILab开源决策智能平台
/
DI-treetensor
12 个月 前同步成功
通知
43
Star
172
Fork
11
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
a56cbc33
编写于
9月 21, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev, doc, test(hansbug): complete isfinite, isinf, isnan
上级
42904f2e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
193 addition
and
0 deletion
+193
-0
test/torch/test_funcs.py
test/torch/test_funcs.py
+42
-0
test/torch/test_tensor.py
test/torch/test_tensor.py
+42
-0
treetensor/torch/funcs.py
treetensor/torch/funcs.py
+85
-0
treetensor/torch/tensor.py
treetensor/torch/tensor.py
+24
-0
未找到文件。
test/torch/test_funcs.py
浏览文件 @
a56cbc33
...
...
@@ -644,3 +644,45 @@ class TestTorchFuncs:
'a'
:
[[
19
,
10
],
[
43
,
26
]],
'b'
:
{
'x'
:
[[
44
,
32
],
[
80
,
59
]]},
})).
all
()
def
test_isfinite
(
self
):
t1
=
ttorch
.
isfinite
(
torch
.
tensor
([
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)]))
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
(
t1
==
ttorch
.
tensor
([
True
,
False
,
True
,
False
,
False
])).
all
()
t2
=
ttorch
.
isfinite
(
ttorch
.
tensor
({
'a'
:
[
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)],
'b'
:
{
'x'
:
[[
1
,
float
(
'inf'
),
-
2
],
[
float
(
'-inf'
),
3
,
float
(
'nan'
)]]}
}))
assert
(
t2
==
ttorch
.
tensor
({
'a'
:
[
True
,
False
,
True
,
False
,
False
],
'b'
:
{
'x'
:
[[
True
,
False
,
True
],
[
False
,
True
,
False
]]},
}))
def
test_isinf
(
self
):
t1
=
ttorch
.
isinf
(
torch
.
tensor
([
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)]))
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
(
t1
==
ttorch
.
tensor
([
False
,
True
,
False
,
True
,
False
])).
all
()
t2
=
ttorch
.
isinf
(
ttorch
.
tensor
({
'a'
:
[
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)],
'b'
:
{
'x'
:
[[
1
,
float
(
'inf'
),
-
2
],
[
float
(
'-inf'
),
3
,
float
(
'nan'
)]]}
}))
assert
(
t2
==
ttorch
.
tensor
({
'a'
:
[
False
,
True
,
False
,
True
,
False
],
'b'
:
{
'x'
:
[[
False
,
True
,
False
],
[
True
,
False
,
False
]]},
}))
def
test_isnan
(
self
):
t1
=
ttorch
.
isnan
(
torch
.
tensor
([
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)]))
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
(
t1
==
ttorch
.
tensor
([
False
,
False
,
False
,
False
,
True
])).
all
()
t2
=
ttorch
.
isnan
(
ttorch
.
tensor
({
'a'
:
[
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)],
'b'
:
{
'x'
:
[[
1
,
float
(
'inf'
),
-
2
],
[
float
(
'-inf'
),
3
,
float
(
'nan'
)]]}
}))
assert
(
t2
==
ttorch
.
tensor
({
'a'
:
[
False
,
False
,
False
,
False
,
True
],
'b'
:
{
'x'
:
[[
False
,
False
,
False
],
[
False
,
False
,
True
]]},
})).
all
()
test/torch/test_tensor.py
浏览文件 @
a56cbc33
...
...
@@ -281,3 +281,45 @@ class TestTorchTensor:
'a'
:
[[
19
,
10
],
[
43
,
26
]],
'b'
:
{
'x'
:
[[
44
,
32
],
[
80
,
59
]]},
})).
all
()
def
test_isfinite
(
self
):
t1
=
torch
.
tensor
([
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)]).
isfinite
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
(
t1
==
ttorch
.
tensor
([
True
,
False
,
True
,
False
,
False
])).
all
()
t2
=
ttorch
.
tensor
({
'a'
:
[
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)],
'b'
:
{
'x'
:
[[
1
,
float
(
'inf'
),
-
2
],
[
float
(
'-inf'
),
3
,
float
(
'nan'
)]]}
}).
isfinite
()
assert
(
t2
==
ttorch
.
tensor
({
'a'
:
[
True
,
False
,
True
,
False
,
False
],
'b'
:
{
'x'
:
[[
True
,
False
,
True
],
[
False
,
True
,
False
]]},
}))
def
test_isinf
(
self
):
t1
=
torch
.
tensor
([
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)]).
isinf
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
(
t1
==
ttorch
.
tensor
([
False
,
True
,
False
,
True
,
False
])).
all
()
t2
=
ttorch
.
tensor
({
'a'
:
[
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)],
'b'
:
{
'x'
:
[[
1
,
float
(
'inf'
),
-
2
],
[
float
(
'-inf'
),
3
,
float
(
'nan'
)]]}
}).
isinf
()
assert
(
t2
==
ttorch
.
tensor
({
'a'
:
[
False
,
True
,
False
,
True
,
False
],
'b'
:
{
'x'
:
[[
False
,
True
,
False
],
[
True
,
False
,
False
]]},
}))
def
test_isnan
(
self
):
t1
=
torch
.
tensor
([
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)]).
isnan
()
assert
isinstance
(
t1
,
torch
.
Tensor
)
assert
(
t1
==
ttorch
.
tensor
([
False
,
False
,
False
,
False
,
True
])).
all
()
t2
=
ttorch
.
tensor
({
'a'
:
[
1
,
float
(
'inf'
),
2
,
float
(
'-inf'
),
float
(
'nan'
)],
'b'
:
{
'x'
:
[[
1
,
float
(
'inf'
),
-
2
],
[
float
(
'-inf'
),
3
,
float
(
'nan'
)]]}
}).
isnan
()
assert
(
t2
==
ttorch
.
tensor
({
'a'
:
[
False
,
False
,
False
,
False
,
True
],
'b'
:
{
'x'
:
[[
False
,
False
,
False
],
[
False
,
False
,
True
]]},
})).
all
()
treetensor/torch/funcs.py
浏览文件 @
a56cbc33
...
...
@@ -22,6 +22,7 @@ __all__ = [
'eq'
,
'ne'
,
'lt'
,
'le'
,
'gt'
,
'ge'
,
'equal'
,
'tensor'
,
'clone'
,
'dot'
,
'matmul'
,
'mm'
,
'isfinite'
,
'isinf'
,
'isnan'
,
]
func_treelize
=
post_process
(
post_process
(
args_mapping
(
...
...
@@ -954,3 +955,87 @@ def mm(input, mat2, *args, **kwargs):
[80, 59]])
"""
return
torch
.
mm
(
input
,
mat2
,
*
args
,
**
kwargs
)
# noinspection PyShadowingBuiltins
@
doc_from
(
torch
.
isfinite
)
@
func_treelize
()
def
isfinite
(
input
):
"""
In ``treetensor``, you can get a tree of new tensors with boolean elements
representing if each element is `finite` or not.
Examples::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([ True, False, True, False, False])
>>> ttorch.isfinite(ttorch.tensor({
... 'a': [1, float('inf'), 2, float('-inf'), float('nan')],
... 'b': {'x': [[1, float('inf'), -2], [float('-inf'), 3, float('nan')]]}
... }))
<Tensor 0x7fb782a15970>
├── a --> tensor([ True, False, True, False, False])
└── b --> <Tensor 0x7fb782a1e040>
└── x --> tensor([[ True, False, True],
[False, True, False]])
"""
return
torch
.
isfinite
(
input
)
# noinspection PyShadowingBuiltins
@
doc_from
(
torch
.
isinf
)
@
func_treelize
()
def
isinf
(
input
):
"""
In ``treetensor``, you can test if each element of ``input``
is infinite (positive or negative infinity) or not.
Examples::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False, True, False, True, False])
>>> ttorch.isinf(ttorch.tensor({
... 'a': [1, float('inf'), 2, float('-inf'), float('nan')],
... 'b': {'x': [[1, float('inf'), -2], [float('-inf'), 3, float('nan')]]}
... }))
<Tensor 0x7fb782a29b80>
├── a --> tensor([False, True, False, True, False])
└── b --> <Tensor 0x7fb782a2d1f0>
└── x --> tensor([[False, True, False],
[ True, False, False]])
"""
return
torch
.
isinf
(
input
)
# noinspection PyShadowingBuiltins
@
doc_from
(
torch
.
isnan
)
@
func_treelize
()
def
isnan
(
input
):
"""
In ``treetensor``, you get a tree of new tensors with boolean elements representing
if each element of ``input`` is NaN or not
Examples::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.isnan(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False, False, False, False, True])
>>> ttorch.isnan(ttorch.tensor({
... 'a': [1, float('inf'), 2, float('-inf'), float('nan')],
... 'b': {'x': [[1, float('inf'), -2], [float('-inf'), 3, float('nan')]]}
... }))
<Tensor 0x7fb782a2d0a0>
├── a --> tensor([False, False, False, False, True])
└── b --> <Tensor 0x7fb782a29d90>
└── x --> tensor([[False, False, False],
[False, False, True]])
"""
return
torch
.
isnan
(
input
)
treetensor/torch/tensor.py
浏览文件 @
a56cbc33
...
...
@@ -293,3 +293,27 @@ class Tensor(Torch, metaclass=clsmeta(_to_tensor, allow_dict=True)):
See :func:`treetensor.torch.matmul`.
"""
return
self
.
matmul
(
tensor2
,
*
args
,
**
kwargs
)
@
doc_from
(
torch
.
Tensor
.
isfinite
)
@
method_treelize
()
def
isfinite
(
self
):
"""
See :func:`treetensor.torch.isfinite`.
"""
return
self
.
isfinite
()
@
doc_from
(
torch
.
Tensor
.
isinf
)
@
method_treelize
()
def
isinf
(
self
):
"""
See :func:`treetensor.torch.isinf`.
"""
return
self
.
isinf
()
@
doc_from
(
torch
.
Tensor
.
isnan
)
@
method_treelize
()
def
isnan
(
self
):
"""
See :func:`treetensor.torch.isnan`.
"""
return
self
.
isnan
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录