Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
DI-treetensor
提交
ba8e6f92
D
DI-treetensor
项目概览
wmsofts
/
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,体验更适合开发者的 AI 搜索 >>
提交
ba8e6f92
编写于
9月 29, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev(hansbug): upgrade auto function
上级
a44c0b66
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
21 deletion
+41
-21
treetensor/torch/funcs/base.py
treetensor/torch/funcs/base.py
+10
-6
treetensor/torch/tensor/tensor.py
treetensor/torch/tensor/tensor.py
+31
-15
未找到文件。
treetensor/torch/funcs/base.py
浏览文件 @
ba8e6f92
...
...
@@ -19,17 +19,21 @@ func_treelize = post_process(post_process(args_mapping(
doc_from_base
=
replaceable_partial
(
original_doc_from_base
,
base
=
torch
)
auto_tensor
=
replaceable_partial
(
auto_torch
,
cls
=
Tensor
)
_funcs_module
=
'.'
.
join
(
__name__
.
split
(
'.'
)[:
-
1
])
def
get_func_from_torch
(
name
):
func
=
getattr
(
torch
,
name
)
return_self_dec
=
return_self
if
func
.
__name__
.
endswith
(
"_"
)
else
(
lambda
x
:
x
)
@
func_treelize
()
@
wraps
(
func
)
@
doc_from_base
()
@
return_self_dec
@
post_process
(
auto_tensor
)
@
func_treelize
(
return_type
=
TreeValue
,
rise
=
True
)
@
wraps
(
func
,
assigned
=
(
'__name__'
,),
updated
=
())
def
_new_func
(
*
args
,
**
kwargs
):
return
func
(
*
args
,
**
kwargs
)
if
func
.
__name__
.
endswith
(
"_"
):
_new_func
=
return_self
(
_new_func
)
_new_func
=
doc_from_base
()(
_new_func
)
_new_func
.
__qualname__
=
_new_func
.
__name__
_new_func
.
__module__
=
_funcs_module
return
_new_func
treetensor/torch/tensor/tensor.py
浏览文件 @
ba8e6f92
from
functools
import
wraps
from
types
import
MethodType
import
numpy
as
np
import
torch
...
...
@@ -25,10 +26,33 @@ def _to_tensor(*args, **kwargs):
return
torch
.
tensor
(
*
args
,
**
kwargs
)
# noinspection PyMethodParameters
class
_TensorMeta
(
clsmeta
(
_to_tensor
,
allow_dict
=
True
)):
def
__getattr__
(
cls
,
name
):
if
hasattr
(
torch
.
Tensor
,
name
)
and
not
name
.
startswith
(
'_'
)
\
and
callable
(
getattr
(
torch
.
Tensor
,
name
)):
_origin_func
=
getattr
(
torch
.
Tensor
,
name
)
return_self_deco
=
return_self
if
name
.
endswith
(
'_'
)
else
(
lambda
x
:
x
)
@
doc_from_base
()
@
return_self_deco
@
post_process
(
lambda
r
:
replaceable_partial
(
auto_torch
,
cls
=
cls
)(
r
))
@
method_treelize
(
return_type
=
TreeValue
,
rise
=
True
)
@
wraps
(
_origin_func
,
assigned
=
(
'__name__'
,),
updated
=
())
def
_new_func
(
*
args
,
**
kwargs
):
return
_origin_func
(
*
args
,
**
kwargs
)
_new_func
.
__qualname__
=
f
'
{
cls
.
__name__
}
.
{
name
}
'
_new_func
.
__module__
=
cls
.
__module__
return
_new_func
else
:
raise
AttributeError
(
f
"type object
{
repr
(
cls
.
__name__
)
}
has no attribute
{
repr
(
name
)
}
"
)
# noinspection PyTypeChecker
@
current_names
()
@
class_autoremove
class
Tensor
(
Torch
,
metaclass
=
clsmeta
(
_to_tensor
,
allow_dict
=
True
)
):
class
Tensor
(
Torch
,
metaclass
=
_TensorMeta
):
# noinspection PyUnusedLocal
def
__init__
(
self
,
data
,
*
args
,
**
kwargs
):
"""
...
...
@@ -67,23 +91,15 @@ class Tensor(Torch, metaclass=clsmeta(_to_tensor, allow_dict=True)):
return
getattr
(
self
,
key
)
def
_attr_extern
(
self
,
name
):
tree
=
self
.
__get_attr
(
name
)
if
hasattr
(
torch
.
Tensor
,
name
)
and
not
name
.
startswith
(
'_'
)
\
and
callable
(
getattr
(
torch
.
Tensor
,
name
)):
from
.attr
import
TensorMethod
tree
=
tree
.
type
(
TensorMethod
)
@
wraps
(
getattr
(
torch
,
name
),
assigned
=
(
'__name__'
,
'__qualname__'
),
updated
=
())
def
_new_func
(
*
args
,
**
kwargs
):
result
=
tree
(
*
args
,
**
kwargs
)
return
self
if
name
.
endswith
(
'_'
)
else
result
_new_func
.
__self__
=
self
return
_new_func
elif
tree
.
map
(
lambda
x
:
torch
.
is_tensor
(
x
)).
all
():
return
tree
.
type
(
Tensor
)
return
MethodType
(
getattr
(
self
.
__class__
,
name
),
self
)
else
:
return
tree
tree
=
self
.
__get_attr
(
name
)
if
tree
.
map
(
lambda
x
:
torch
.
is_tensor
(
x
)).
all
():
return
tree
.
type
(
Tensor
)
else
:
return
tree
@
doc_from_base
()
@
method_treelize
(
return_type
=
ndarray
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录