Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
flybirding10011
DI-treetensor
提交
7ff4109d
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,发现更多精彩内容 >>
提交
7ff4109d
编写于
9月 19, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc(hansbug): add documentation for treetensor.torch.Tensor
上级
3422e98c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
0 deletion
+55
-0
treetensor/torch/tensor.py
treetensor/torch/tensor.py
+55
-0
未找到文件。
treetensor/torch/tensor.py
浏览文件 @
7ff4109d
...
...
@@ -28,6 +28,11 @@ class Tensor(TreeTorch):
@
doc_from
(
torch
.
Tensor
.
numpy
)
@
method_treelize
(
return_type
=
ndarray
)
def
numpy
(
self
:
torch
.
Tensor
)
->
np
.
ndarray
:
"""
Returns ``self`` tree tensor as a NumPy ``ndarray``.
This tensor and the returned :class:`treetensor.numpy.ndarray` share the same underlying storage.
Changes to self tensor will be reflected in the ``ndarray`` and vice versa.
"""
return
self
.
numpy
()
@
doc_from
(
torch
.
Tensor
.
tolist
)
...
...
@@ -56,28 +61,78 @@ class Tensor(TreeTorch):
@
doc_from
(
torch
.
Tensor
.
cpu
)
@
method_treelize
()
def
cpu
(
self
:
torch
.
Tensor
,
*
args
,
**
kwargs
):
"""
Returns a copy of this tree tensor in CPU memory.
If this tree tensor is already in CPU memory and on the correct device,
then no copy is performed and the original object is returned.
"""
return
self
.
cpu
(
*
args
,
**
kwargs
)
@
doc_from
(
torch
.
Tensor
.
cuda
)
@
method_treelize
()
def
cuda
(
self
:
torch
.
Tensor
,
*
args
,
**
kwargs
):
"""
Returns a copy of this tree tensor in CUDA memory.
If this tree tensor is already in CUDA memory and on the correct device,
then no copy is performed and the original object is returned.
"""
return
self
.
cuda
(
*
args
,
**
kwargs
)
@
doc_from
(
torch
.
Tensor
.
to
)
@
method_treelize
()
def
to
(
self
:
torch
.
Tensor
,
*
args
,
**
kwargs
):
"""
Turn the original tree tensor to another format.
Example::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.tensor({
... 'a': [[1, 11], [2, 22], [3, 33]],
... 'b': {'x': [[4, 5], [6, 7]]},
... }).to(torch.float64)
<Tensor 0x7ff363bb6518>
├── a --> tensor([[ 1., 11.],
│ [ 2., 22.],
│ [ 3., 33.]], dtype=torch.float64)
└── b --> <Tensor 0x7ff363bb6ef0>
└── x --> tensor([[4., 5.],
[6., 7.]], dtype=torch.float64)
"""
return
self
.
to
(
*
args
,
**
kwargs
)
@
doc_from
(
torch
.
Tensor
.
numel
)
@
ireduce
(
sum
)
@
method_treelize
(
return_type
=
TreeObject
)
def
numel
(
self
:
torch
.
Tensor
):
"""
See :func:`treetensor.torch.numel`
"""
return
self
.
numel
()
@
property
@
doc_from
(
torch
.
Tensor
.
shape
)
@
method_treelize
(
return_type
=
Size
)
def
shape
(
self
:
torch
.
Tensor
):
"""
Get the size of the tensors in the tree.
Example::
>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.tensor({
... 'a': [[1, 11], [2, 22], [3, 33]],
... 'b': {'x': [[4, 5], [6, 7]]},
... }).shape
<Size 0x7ff363bbbd68>
├── a --> torch.Size([3, 2])
└── b --> <Size 0x7ff363bbbcf8>
└── x --> torch.Size([2, 2])
"""
return
self
.
shape
@
doc_from
(
torch
.
Tensor
.
all
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录