Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
flybirding10011
DI-treetensor
提交
33d88ece
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,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
33d88ece
编写于
9月 13, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc(hansbug): add doc for any, zeros, zeros_like
上级
007d22dd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
98 addition
and
3 deletion
+98
-3
treetensor/torch/funcs.py
treetensor/torch/funcs.py
+98
-3
未找到文件。
treetensor/torch/funcs.py
浏览文件 @
33d88ece
...
...
@@ -30,12 +30,54 @@ func_treelize = post_process(post_process(args_mapping(
@
doc_from
(
torch
.
zeros
)
@
func_treelize
()
def
zeros
(
*
args
,
**
kwargs
):
"""
In ``treetensor``, you can use ``zeros`` to create a tree of tensors with all zeros.
Example::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.zeros(2, 3) # the same as torch.zeros(2, 3)
torch.tensor([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]])
>>> ttorch.zeros({
>>> 'a': (2, 3),
>>> 'b': (4, ),
>>> })
ttorch.tensor({
'a': torch.tensor([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]]),
'b': torch.tensor([0.0, 0.0, 0.0, 0.0]),
})
"""
return
torch
.
zeros
(
*
args
,
**
kwargs
)
@
doc_from
(
torch
.
zeros_like
)
@
func_treelize
()
def
zeros_like
(
input_
,
*
args
,
**
kwargs
):
"""
In ``treetensor``, you can use ``zeros_like`` to create a tree of tensors with all zeros like another tree.
Example::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.zeros_like(torch.randn(2, 3)) # the same as torch.zeros_like(torch.randn(2, 3))
torch.tensor([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]])
>>> ttorch.zeros_like({
>>> 'a': torch.randn(2, 3),
>>> 'b': torch.randn(4, ),
>>> })
ttorch.tensor({
'a': torch.tensor([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]]),
'b': torch.tensor([0.0, 0.0, 0.0, 0.0]),
})
"""
return
torch
.
zeros_like
(
input_
,
*
args
,
**
kwargs
)
...
...
@@ -110,21 +152,36 @@ def all(input_, *args, **kwargs):
>>> import torch
>>> import treetensor.torch as ttorch
>>> all(torch.tensor([True, True])) # the same as torch.all
>>>
ttorch.
all(torch.tensor([True, True])) # the same as torch.all
torch.tensor(True)
>>> all(ttorch.tensor({
>>>
ttorch.
all(ttorch.tensor({
>>> 'a': [True, True],
>>> 'b': [True, True],
>>> }))
torch.tensor(True)
>>>
all(T
ensor({
>>>
ttorch.all(ttorch.t
ensor({
>>> 'a': [True, True],
>>> 'b': [True, False],
>>> }))
torch.tensor(False)
.. note::
In this ``all`` function, the return value should be a tensor with single boolean value.
If what you need is a tree of boolean tensors, you should do like this
>>> ttorch.tensor({
>>> 'a': [True, True],
>>> 'b': [True, False],
>>> }).map(torch.all)
ttorch.tensor({
'a': torch.tensor(True),
'b': torch.tensor(False),
})
"""
return
torch
.
all
(
input_
,
*
args
,
**
kwargs
)
...
...
@@ -133,6 +190,44 @@ def all(input_, *args, **kwargs):
@
tireduce
(
torch
.
any
)
@
func_treelize
(
return_type
=
TreeObject
)
def
any
(
input_
,
*
args
,
**
kwargs
):
"""
In ``treetensor``, you can get the ``any`` result of a whole tree with this function.
Example::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.any(torch.tensor([False, False])) # the same as torch.any
torch.tensor(False)
>>> ttorch.any(ttorch.tensor({
>>> 'a': [True, False],
>>> 'b': [False, False],
>>> }))
torch.tensor(True)
>>> ttorch.any(ttorch.tensor({
>>> 'a': [False, False],
>>> 'b': [False, False],
>>> }))
torch.tensor(False)
.. note::
In this ``any`` function, the return value should be a tensor with single boolean value.
If what you need is a tree of boolean tensors, you should do like this
>>> ttorch.tensor({
>>> 'a': [True, False],
>>> 'b': [False, False],
>>> }).map(torch.any)
ttorch.tensor({
'a': torch.tensor(True),
'b': torch.tensor(False),
})
"""
return
torch
.
any
(
input_
,
*
args
,
**
kwargs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录