Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
401b495f
T
treevalue
项目概览
OpenDILab开源决策智能平台
/
treevalue
大约 1 年 前同步成功
通知
3
Star
213
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
treevalue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
401b495f
编写于
1月 01, 2022
作者:
HansBug
😆
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev(hansbug): add delayed for subside and union
上级
33ac4c6e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
13 deletion
+19
-13
treevalue/tree/func/cfunc.pyx
treevalue/tree/func/cfunc.pyx
+6
-4
treevalue/tree/tree/structural.pxd
treevalue/tree/tree/structural.pxd
+2
-2
treevalue/tree/tree/structural.pyx
treevalue/tree/tree/structural.pyx
+11
-7
未找到文件。
treevalue/tree/func/cfunc.pyx
浏览文件 @
401b495f
...
...
@@ -168,8 +168,8 @@ cdef object _c_func_treelize_run(object func, list args, dict kwargs, _e_tree_mo
return
TreeStorage
(
_d_res
)
def
_w_subside_func
(
object
value
,
bool
dict_
=
True
,
bool
list_
=
True
,
bool
tuple_
=
True
,
bool
inherit
=
True
,
object
mode
=
'strict'
,
object
missing
=
MISSING_NOT_ALLOW
):
return
_c_subside
(
value
,
dict_
,
list_
,
tuple_
,
inherit
,
mode
,
missing
)[
0
]
object
mode
=
'strict'
,
object
missing
=
MISSING_NOT_ALLOW
,
bool
delayed
=
False
):
return
_c_subside
(
value
,
dict_
,
list_
,
tuple_
,
inherit
,
mode
,
missing
,
delayed
)[
0
]
def
_w_rise_func
(
object
tree
,
bool
dict_
=
True
,
bool
list_
=
True
,
bool
tuple_
=
True
,
object
template
=
None
):
return
_c_rise
(
tree
,
dict_
,
list_
,
tuple_
,
template
)
...
...
@@ -181,9 +181,11 @@ def _w_func_treelize_run(*args, object __w_func, _e_tree_mode __w_mode, object _
cdef
list
_a_args
=
[(
item
.
_detach
()
if
isinstance
(
item
,
TreeValue
)
else
item
)
for
item
in
args
]
cdef
dict
_a_kwargs
=
{
k
:
(
v
.
_detach
()
if
isinstance
(
v
,
TreeValue
)
else
v
)
for
k
,
v
in
kwargs
.
items
()}
cdef
dict
_w_subside_cfg
if
__w_subside
is
not
None
:
_a_args
=
[
_w_subside_func
(
item
,
**
__w_subside
)
for
item
in
_a_args
]
_a_kwargs
=
{
key
:
_w_subside_func
(
value
,
**
__w_subside
)
for
key
,
value
in
_a_kwargs
.
items
()}
_w_subside_cfg
=
{
'delayed'
:
__w_delayed
,
**
__w_subside
}
_a_args
=
[
_w_subside_func
(
item
,
**
_w_subside_cfg
)
for
item
in
_a_args
]
_a_kwargs
=
{
key
:
_w_subside_func
(
value
,
**
_w_subside_cfg
)
for
key
,
value
in
_a_kwargs
.
items
()}
cdef
object
_st_res
=
_c_func_treelize_run
(
__w_func
,
_a_args
,
_a_kwargs
,
__w_mode
,
__w_inherit
,
__w_allow_missing
,
__w_missing_func
,
__w_delayed
)
...
...
treevalue/tree/tree/structural.pxd
浏览文件 @
401b495f
...
...
@@ -12,10 +12,10 @@ cdef object _c_subside_process(tuple value, object it)
cdef
tuple
_c_subside_build
(
object
value
,
bool
dict_
,
bool
list_
,
bool
tuple_
)
cdef
void
_c_subside_missing
()
cdef
object
_c_subside
(
object
value
,
bool
dict_
,
bool
list_
,
bool
tuple_
,
bool
inherit
,
object
mode
,
object
missing
)
object
mode
,
object
missing
,
bool
delayed
)
cdef
object
_c_subside_keep_type
(
object
t
)
cpdef
object
subside
(
object
value
,
bool
dict_
=
*
,
bool
list_
=
*
,
bool
tuple_
=
*
,
object
return_type
=
*
,
bool
inherit
=
*
,
object
mode
=
*
,
object
missing
=
*
)
object
return_type
=
*
,
bool
inherit
=
*
,
object
mode
=
*
,
object
missing
=
*
,
bool
delayed
=
*
)
cdef
object
_c_rise_tree_builder
(
tuple
p
,
object
it
)
cdef
tuple
_c_rise_tree_process
(
object
t
)
...
...
treevalue/tree/tree/structural.pyx
浏览文件 @
401b495f
...
...
@@ -84,7 +84,7 @@ cdef inline void _c_subside_missing():
pass
cdef
object
_c_subside
(
object
value
,
bool
dict_
,
bool
list_
,
bool
tuple_
,
bool
inherit
,
object
mode
,
object
missing
):
object
mode
,
object
missing
,
bool
delayed
):
cdef
object
builder
,
_i_args
,
_i_types
builder
,
_i_args
,
_i_types
=
_c_subside_build
(
value
,
dict_
,
list_
,
tuple_
)
cdef
list
args
=
list
(
_i_args
)
...
...
@@ -94,7 +94,7 @@ cdef object _c_subside(object value, bool dict_, bool list_, bool tuple_, bool i
allow_missing
,
missing_func
=
_c_missing_process
(
missing
)
return
_c_func_treelize_run
(
_SubsideCall
(
builder
),
args
,
{},
_c_load_mode
(
mode
),
inherit
,
allow_missing
,
missing_func
,
False
),
_i_types
_c_load_mode
(
mode
),
inherit
,
allow_missing
,
missing_func
,
delayed
),
_i_types
cdef
inline
object
_c_subside_keep_type
(
object
t
):
return
t
...
...
@@ -102,7 +102,7 @@ cdef inline object _c_subside_keep_type(object t):
@
cython
.
binding
(
True
)
cpdef
object
subside
(
object
value
,
bool
dict_
=
True
,
bool
list_
=
True
,
bool
tuple_
=
True
,
object
return_type
=
None
,
bool
inherit
=
True
,
object
mode
=
'strict'
,
object
missing
=
MISSING_NOT_ALLOW
):
object
mode
=
'strict'
,
object
missing
=
MISSING_NOT_ALLOW
,
bool
delayed
=
False
):
"""
Overview:
Drift down the structures (list, tuple, dict) down to the tree's value.
...
...
@@ -119,6 +119,8 @@ cpdef object subside(object value, bool dict_=True, bool list_=True, bool tuple_
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- missing (:obj:`Union[Any, Callable]`): Missing value or lambda generator of when missing,
\
default is `MISSING_NOT_ALLOW`, which means raise `KeyError` when missing detected.
- delayed (:obj:`bool`): Enable delayed mode or not, the calculation will be delayed when enabled,
\
default is ``False``, which means to all the calculation at once.
Returns:
- return (:obj:`_TreeValue`): Subsided tree value.
...
...
@@ -143,7 +145,7 @@ cpdef object subside(object value, bool dict_=True, bool list_=True, bool tuple_
>>> #}), all structures above the tree values are subsided to the bottom of the tree.
"""
cdef
object
result
,
_i_types
result
,
_i_types
=
_c_subside
(
value
,
dict_
,
list_
,
tuple_
,
inherit
,
mode
,
missing
)
result
,
_i_types
=
_c_subside
(
value
,
dict_
,
list_
,
tuple_
,
inherit
,
mode
,
missing
,
delayed
)
cdef
object
type_
cdef
set
types
...
...
@@ -162,7 +164,7 @@ cpdef object subside(object value, bool dict_=True, bool list_=True, bool tuple_
@
cython
.
binding
(
True
)
def
union
(
*
trees
,
object
return_type
=
None
,
bool
inherit
=
True
,
object
mode
=
'strict'
,
object
missing
=
MISSING_NOT_ALLOW
):
object
mode
=
'strict'
,
object
missing
=
MISSING_NOT_ALLOW
,
bool
delayed
=
False
):
"""
Overview:
Union tree values together.
...
...
@@ -170,10 +172,12 @@ def union(*trees, object return_type=None, bool inherit=True,
Arguments:
- trees (:obj:`_TreeValue`): Tree value objects.
- return_type (:obj:`Optional[Type[_ClassType]]`): Return type of the wrapped function, default is `TreeValue`.
- inherit (:obj:`bool`): Allow inherit in wrapped function, default is `True`.
- inherit (:obj:`bool`): Allow inherit
ing
in wrapped function, default is `True`.
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- missing (:obj:`Union[Any, Callable]`): Missing value or lambda generator of when missing,
\
default is `MISSING_NOT_ALLOW`, which means raise `KeyError` when missing detected.
- delayed (:obj:`bool`): Enable delayed mode or not, the calculation will be delayed when enabled,
\
default is ``False``, which means to all the calculation at once.
Returns:
- result (:obj:`TreeValue`): Unionised tree value.
...
...
@@ -184,7 +188,7 @@ def union(*trees, object return_type=None, bool inherit=True,
>>> union(t, tx) # TreeValue({'a': (1, True), 'b': (2, False), 'x': {'c': (3, True), 'd': (4, False)}})
"""
cdef
object
result
,
_i_types
result
,
_i_types
=
_c_subside
(
tuple
(
trees
),
True
,
True
,
True
,
inherit
,
mode
,
missing
)
result
,
_i_types
=
_c_subside
(
tuple
(
trees
),
True
,
True
,
True
,
inherit
,
mode
,
missing
,
delayed
)
cdef
object
type_
cdef
list
types
...
...
HansBug
😆
@HansBug
mentioned in commit
04d1ccb0
·
1月 02, 2022
mentioned in commit
04d1ccb0
mentioned in commit 04d1ccb01ba5cd3a3db7e0e11c12929ce8e7940c
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录