Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
3cd01622
T
treevalue
项目概览
OpenDILab开源决策智能平台
/
treevalue
8 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
3cd01622
编写于
11月 09, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'main' into refactor/color
上级
5c6514a1
da5022b0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
3 deletion
+61
-3
test/tree/func/test_func.py
test/tree/func/test_func.py
+40
-0
treevalue/tree/func/cfunc.pyx
treevalue/tree/func/cfunc.pyx
+21
-3
未找到文件。
test/tree/func/test_func.py
浏览文件 @
3cd01622
...
...
@@ -217,3 +217,43 @@ class TestTreeFuncFunc:
return
x
+
y
assert
MyTreeValue
.
plus
(
TreeValue
({
'a'
:
1
,
'b'
:
2
}),
2
)
==
MyTreeValue
({
'a'
:
3
,
'b'
:
4
})
def
test_missing
(
self
):
@
func_treelize
(
mode
=
'outer'
,
missing
=
lambda
:
[])
def
append
(
arr
:
list
,
*
args
):
for
item
in
args
:
if
item
:
arr
.
append
(
item
)
return
arr
t0
=
TreeValue
({})
t1
=
TreeValue
({
'a'
:
2
,
'b'
:
7
,
'x'
:
{
'c'
:
4
,
'd'
:
9
}})
t2
=
TreeValue
({
'a'
:
4
,
'b'
:
48
,
'x'
:
{
'c'
:
-
11
,
'd'
:
54
}})
t3
=
TreeValue
({
'a'
:
9
,
'b'
:
-
12
,
'x'
:
{
'c'
:
3
,
'd'
:
4
}})
assert
append
(
t0
,
t1
,
t2
,
t3
)
==
TreeValue
({
'a'
:
[
2
,
4
,
9
],
'b'
:
[
7
,
48
,
-
12
],
'x'
:
{
'c'
:
[
4
,
-
11
,
3
],
'd'
:
[
9
,
54
,
4
],
}
})
t0
=
TreeValue
({})
t1
=
TreeValue
({
'a'
:
2
,
'x'
:
{
'c'
:
4
,
'd'
:
9
}})
t2
=
TreeValue
({
'a'
:
4
,
'b'
:
48
,
'x'
:
{
'd'
:
54
}})
t3
=
TreeValue
({
'b'
:
-
12
,
'x'
:
7
,
'y'
:
{
'e'
:
3
,
'f'
:
4
}})
assert
append
(
t0
,
t1
,
t2
,
t3
)
==
TreeValue
({
'a'
:
[
2
,
4
],
'b'
:
[
48
,
-
12
],
'x'
:
{
'c'
:
[
4
,
7
],
'd'
:
[
9
,
54
,
7
],
},
'y'
:
{
'e'
:
[
3
],
'f'
:
[
4
],
},
})
treevalue/tree/func/cfunc.pyx
浏览文件 @
3cd01622
...
...
@@ -12,6 +12,8 @@ from ..common.storage cimport TreeStorage
from
..tree.structural
cimport
_c_subside
,
_c_rise
from
..tree.tree
cimport
TreeValue
_VALUE_IS_MISSING
=
SingletonMark
(
'value_is_missing'
)
cdef
object
_c_func_treelize_run
(
object
func
,
list
args
,
dict
kwargs
,
_e_tree_mode
mode
,
bool
inherit
,
bool
allow_missing
,
object
missing_func
):
cdef
list
ck_args
=
[]
...
...
@@ -33,8 +35,24 @@ cdef object _c_func_treelize_run(object func, list args, dict kwargs,
else
:
ck_kwargs
.
append
((
k
,
v
,
False
))
cdef
list
_a_args
cdef
dict
_a_kwargs
if
not
has_tree
:
return
func
(
*
args
,
**
kwargs
)
_a_args
=
[]
for
v
in
args
:
if
v
is
not
_VALUE_IS_MISSING
:
_a_args
.
append
(
v
)
else
:
_a_args
.
append
(
missing_func
())
_a_kwargs
=
{}
for
k
,
v
in
kwargs
.
items
():
if
v
is
not
_VALUE_IS_MISSING
:
_a_kwargs
[
k
]
=
v
else
:
_a_kwargs
[
k
]
=
missing_func
()
return
func
(
*
_a_args
,
**
_a_kwargs
)
cdef
dict
_d_res
=
{}
cdef
str
ak
...
...
@@ -51,7 +69,7 @@ cdef object _c_func_treelize_run(object func, list args, dict kwargs,
_l_args
.
append
(
av
[
k
])
except
KeyError
:
if
allow_missing
:
_l_args
.
append
(
missing_func
()
)
_l_args
.
append
(
_VALUE_IS_MISSING
)
else
:
raise
KeyError
(
"Missing is off, key {key} not found in {item}."
.
format
(
key
=
repr
(
k
),
item
=
repr
(
av
),
...
...
@@ -71,7 +89,7 @@ cdef object _c_func_treelize_run(object func, list args, dict kwargs,
_d_kwargs
[
ak
]
=
av
[
k
]
except
KeyError
:
if
allow_missing
:
_d_kwargs
[
ak
]
=
missing_func
()
_d_kwargs
[
ak
]
=
_VALUE_IS_MISSING
else
:
raise
KeyError
(
"Missing is off, key {key} not found in {item}."
.
format
(
key
=
repr
(
k
),
item
=
repr
(
av
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录