Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
3a738c40
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,发现更多精彩内容 >>
提交
3a738c40
编写于
1月 01, 2022
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev(hansbug): add base delayed option (not implemented)
上级
7078368f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
17 deletion
+21
-17
treevalue/tree/func/cfunc.pxd
treevalue/tree/func/cfunc.pxd
+5
-3
treevalue/tree/func/cfunc.pyx
treevalue/tree/func/cfunc.pyx
+10
-8
treevalue/tree/func/func.py
treevalue/tree/func/func.py
+5
-5
treevalue/tree/tree/structural.pyx
treevalue/tree/tree/structural.pyx
+1
-1
未找到文件。
treevalue/tree/func/cfunc.pxd
浏览文件 @
3a738c40
...
...
@@ -6,11 +6,13 @@ from libcpp cimport bool
from
.modes
cimport
_e_tree_mode
cdef
object
_c_func_treelize_run
(
object
func
,
list
args
,
dict
kwargs
,
_e_tree_mode
mode
,
bool
inherit
,
bool
allow_missing
,
object
missing_func
)
_e_tree_mode
mode
,
bool
inherit
,
bool
allow_missing
,
object
missing_func
,
bool
delayed
)
cpdef
object
_d_func_treelize
(
object
func
,
object
mode
,
object
return_type
,
bool
inherit
,
object
missing
,
object
subside
,
object
rise
)
bool
delayed
,
object
subside
,
object
rise
)
cdef
object
_c_common_value
(
object
item
)
cdef
tuple
_c_missing_process
(
object
missing
)
cpdef
object
func_treelize
(
object
mode
=
*
,
object
return_type
=
*
,
bool
inherit
=
*
,
object
missing
=
*
,
object
subside
=
*
,
object
rise
=
*
)
bool
delayed
=
*
,
object
subside
=
*
,
object
rise
=
*
)
treevalue/tree/func/cfunc.pyx
浏览文件 @
3a738c40
...
...
@@ -17,7 +17,9 @@ _VALUE_IS_MISSING = SingletonMark('value_is_missing')
MISSING_NOT_ALLOW
=
SingletonMark
(
"missing_not_allow"
)
cdef
object
_c_func_treelize_run
(
object
func
,
list
args
,
dict
kwargs
,
_e_tree_mode
mode
,
bool
inherit
,
bool
allow_missing
,
object
missing_func
):
_e_tree_mode
mode
,
bool
inherit
,
bool
allow_missing
,
object
missing_func
,
bool
delayed
):
cdef
list
ck_args
=
[]
cdef
list
ck_kwargs
=
[]
cdef
bool
has_tree
=
False
...
...
@@ -117,7 +119,7 @@ cdef object _c_func_treelize_run(object func, list args, dict kwargs,
))
_d_res
[
k
]
=
_c_func_treelize_run
(
func
,
_l_args
,
_d_kwargs
,
mode
,
inherit
,
allow_missing
,
missing_func
)
mode
,
inherit
,
allow_missing
,
missing_func
,
delayed
)
return
TreeStorage
(
_d_res
)
...
...
@@ -131,7 +133,7 @@ def _w_rise_func(object tree, bool dict_=True, bool list_=True, bool tuple_=True
# runtime function
def
_w_func_treelize_run
(
*
args
,
object
__w_func
,
_e_tree_mode
__w_mode
,
object
__w_return_type
,
bool
__w_inherit
,
bool
__w_allow_missing
,
object
__w_missing_func
,
object
__w_subside
,
object
__w_rise
,
**
kwargs
):
bool
__w_delayed
,
object
__w_subside
,
object
__w_rise
,
**
kwargs
):
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
()}
...
...
@@ -140,7 +142,7 @@ def _w_func_treelize_run(*args, object __w_func, _e_tree_mode __w_mode, object _
_a_kwargs
=
{
key
:
_w_subside_func
(
value
,
**
__w_subside
)
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_inherit
,
__w_allow_missing
,
__w_missing_func
,
__w_delayed
)
cdef
object
_o_res
if
__w_return_type
is
not
None
:
...
...
@@ -176,7 +178,7 @@ cdef inline tuple _c_missing_process(object missing):
# build-time function
cpdef
object
_d_func_treelize
(
object
func
,
object
mode
,
object
return_type
,
bool
inherit
,
object
missing
,
object
subside
,
object
rise
):
bool
delayed
,
object
subside
,
object
rise
):
cdef
_e_tree_mode
_v_mode
=
_c_load_mode
(
mode
)
cdef
bool
allow_missing
cdef
object
missing_func
...
...
@@ -195,12 +197,12 @@ cpdef object _d_func_treelize(object func, object mode, object return_type, bool
_c_check
(
_v_mode
,
return_type
,
inherit
,
allow_missing
,
missing_func
)
return
partial
(
_w_func_treelize_run
,
__w_func
=
func
,
__w_mode
=
_v_mode
,
__w_return_type
=
return_type
,
__w_inherit
=
inherit
,
__w_allow_missing
=
allow_missing
,
__w_missing_func
=
missing_func
,
__w_subside
=
_v_subside
,
__w_rise
=
_v_rise
)
__w_
delayed
=
delayed
,
__w_
subside
=
_v_subside
,
__w_rise
=
_v_rise
)
@
cython
.
binding
(
True
)
cpdef
object
func_treelize
(
object
mode
=
'strict'
,
object
return_type
=
TreeValue
,
bool
inherit
=
True
,
object
missing
=
MISSING_NOT_ALLOW
,
object
subside
=
None
,
object
rise
=
None
):
bool
delayed
=
False
,
object
subside
=
None
,
object
rise
=
None
):
"""
Overview:
Wrap a common function to tree-supported function.
...
...
@@ -233,4 +235,4 @@ cpdef object func_treelize(object mode='strict', object return_type=TreeValue,
>>> ssum(t1, t2) # TreeValue({'a': 12, 'b': 24, 'x': {'c': 36, 'd': 9}})
"""
return
partial
(
_d_func_treelize
,
mode
=
mode
,
return_type
=
return_type
,
inherit
=
inherit
,
missing
=
missing
,
subside
=
subside
,
rise
=
rise
)
inherit
=
inherit
,
missing
=
missing
,
delayed
=
delayed
,
subside
=
subside
,
rise
=
rise
)
treevalue/tree/func/func.py
浏览文件 @
3a738c40
...
...
@@ -12,7 +12,7 @@ TreeClassType_ = TypeVar("TreeClassType_", bound=TreeValue)
def
func_treelize
(
mode
:
str
=
'strict'
,
return_type
:
Optional
[
Type
[
TreeClassType_
]]
=
TreeValue
,
inherit
:
bool
=
True
,
missing
:
Union
[
Any
,
Callable
]
=
MISSING_NOT_ALLOW
,
inherit
:
bool
=
True
,
missing
:
Union
[
Any
,
Callable
]
=
MISSING_NOT_ALLOW
,
delayed
:
bool
=
False
,
subside
:
Union
[
Mapping
,
bool
,
None
]
=
None
,
rise
:
Union
[
Mapping
,
bool
,
None
]
=
None
):
"""
Overview:
...
...
@@ -21,7 +21,7 @@ def func_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassType
Arguments:
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- return_type (:obj:`Optional[Type[TreeClassType_]]`): 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`.
- 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.
- subside (:obj:`Union[Mapping, bool, None]`): Subside enabled to function's arguments or not,
\
...
...
@@ -47,7 +47,7 @@ def func_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassType
"""
def
_decorator
(
func
):
_treelized
=
_c_func_treelize
(
mode
,
return_type
,
inherit
,
missing
,
subside
,
rise
)(
func
)
_treelized
=
_c_func_treelize
(
mode
,
return_type
,
inherit
,
missing
,
delayed
,
subside
,
rise
)(
func
)
@
wraps
(
func
)
def
_new_func
(
*
args
,
**
kwargs
):
...
...
@@ -82,7 +82,7 @@ def method_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassTy
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- return_type (:obj:`Optional[Type[TreeClassType_]]`): Return type of the wrapped function,
\
default is `AUTO_DETECT_RETURN_VALUE`, which means automatically use the decorated method's class.
- inherit (:obj:`bool`): Allow inherit in wrapped function, default is `True`.
- inherit (:obj:`bool`): Allow inherit
ing
in wrapped function, default is `True`.
- 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.
- subside (:obj:`Union[Mapping, bool, None]`): Subside enabled to function's arguments or not,
\
...
...
@@ -154,7 +154,7 @@ def classmethod_treelize(mode: str = 'strict', return_type: Optional[Type[TreeCl
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- return_type (:obj:`Optional[Type[TreeClassType_]]`): Return type of the wrapped function,
\
default is `AUTO_DETECT_RETURN_VALUE`, which means automatically use the decorated method's class.
- inherit (:obj:`bool`): Allow inherit in wrapped function, default is `True`.
- inherit (:obj:`bool`): Allow inherit
ing
in wrapped function, default is `True`.
- 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.
- subside (:obj:`Union[Mapping, bool, None]`): Subside enabled to function's arguments or not,
\
...
...
treevalue/tree/tree/structural.pyx
浏览文件 @
3a738c40
...
...
@@ -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
),
_i_types
_c_load_mode
(
mode
),
inherit
,
allow_missing
,
missing_func
,
False
),
_i_types
cdef
inline
object
_c_subside_keep_type
(
object
t
):
return
t
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录