kevin-toolbox-dev 1.4.8__py3-none-any.whl → 1.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kevin_toolbox/__init__.py +2 -2
- kevin_toolbox/data_flow/file/json_/write_json.py +2 -1
- kevin_toolbox/env_info/check_version_and_update.py +0 -1
- kevin_toolbox/nested_dict_list/copy_.py +4 -2
- kevin_toolbox/nested_dict_list/get_nodes.py +4 -2
- kevin_toolbox/nested_dict_list/traverse.py +75 -21
- kevin_toolbox/nested_dict_list/value_parser/replace_identical_with_reference.py +1 -4
- kevin_toolbox/patches/for_matplotlib/color/convert_format.py +0 -2
- kevin_toolbox/patches/for_matplotlib/common_charts/utils/save_plot.py +1 -0
- kevin_toolbox/patches/for_numpy/linalg/softmax.py +4 -1
- kevin_toolbox_dev-1.4.9.dist-info/METADATA +75 -0
- {kevin_toolbox_dev-1.4.8.dist-info → kevin_toolbox_dev-1.4.9.dist-info}/RECORD +14 -14
- kevin_toolbox_dev-1.4.8.dist-info/METADATA +0 -86
- {kevin_toolbox_dev-1.4.8.dist-info → kevin_toolbox_dev-1.4.9.dist-info}/WHEEL +0 -0
- {kevin_toolbox_dev-1.4.8.dist-info → kevin_toolbox_dev-1.4.9.dist-info}/top_level.txt +0 -0
kevin_toolbox/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "1.4.
|
1
|
+
__version__ = "1.4.9"
|
2
2
|
|
3
3
|
|
4
4
|
import os
|
@@ -12,5 +12,5 @@ os.system(
|
|
12
12
|
os.system(
|
13
13
|
f'python {os.path.split(__file__)[0]}/env_info/check_validity_and_uninstall.py '
|
14
14
|
f'--package_name kevin-toolbox-dev '
|
15
|
-
f'--expiration_timestamp
|
15
|
+
f'--expiration_timestamp 1758638079 --verbose 0'
|
16
16
|
)
|
@@ -56,7 +56,8 @@ def write_json(content, file_path, converters=None, b_use_suggested_converter=Fa
|
|
56
56
|
content = traverse(var=[copy.deepcopy(content)],
|
57
57
|
match_cond=lambda _, __, ___: True, action_mode="replace",
|
58
58
|
converter=lambda _, x: converter(x),
|
59
|
-
b_traverse_matched_element=True
|
59
|
+
b_traverse_matched_element=True,
|
60
|
+
b_skip_repeated_non_leaf_node=True)[0]
|
60
61
|
|
61
62
|
content = json.dumps(content, **output_format)
|
62
63
|
|
@@ -16,7 +16,6 @@ def check_version_and_update(package_name, cur_version=None, available_versions=
|
|
16
16
|
ex = subprocess.Popen(f'pip list | grep "{package_name} "', shell=True, stdout=subprocess.PIPE)
|
17
17
|
out, _ = ex.communicate()
|
18
18
|
out = out.decode().strip()
|
19
|
-
# breakpoint()
|
20
19
|
cur_version = out.split(package_name)[-1].strip()
|
21
20
|
|
22
21
|
# try to read available versions
|
@@ -123,7 +123,8 @@ def _copy_structure(var, b_keep_internal_references):
|
|
123
123
|
|
124
124
|
return traverse(var=[var], match_cond=lambda _, __, value: isinstance(value, (list, dict,)),
|
125
125
|
action_mode="replace", converter=converter,
|
126
|
-
traversal_mode="dfs_pre_order", b_traverse_matched_element=True
|
126
|
+
traversal_mode="dfs_pre_order", b_traverse_matched_element=True,
|
127
|
+
b_skip_repeated_non_leaf_node=True)[0]
|
127
128
|
|
128
129
|
|
129
130
|
def _copy_nodes(var, b_keep_internal_references):
|
@@ -149,7 +150,8 @@ def _copy_nodes(var, b_keep_internal_references):
|
|
149
150
|
|
150
151
|
return traverse(var=[var], match_cond=lambda _, __, value: not isinstance(value, (list, dict,)),
|
151
152
|
action_mode="replace", converter=converter,
|
152
|
-
traversal_mode="dfs_pre_order", b_traverse_matched_element=True
|
153
|
+
traversal_mode="dfs_pre_order", b_traverse_matched_element=True,
|
154
|
+
b_skip_repeated_non_leaf_node=True)[0]
|
153
155
|
|
154
156
|
|
155
157
|
if __name__ == '__main__':
|
@@ -2,7 +2,7 @@ from kevin_toolbox.nested_dict_list import traverse, get_value
|
|
2
2
|
from kevin_toolbox.nested_dict_list.name_handler import parse_name
|
3
3
|
|
4
4
|
|
5
|
-
def get_nodes(var, level=-1, b_strict=True):
|
5
|
+
def get_nodes(var, level=-1, b_strict=True, **kwargs):
|
6
6
|
"""
|
7
7
|
获取嵌套字典列表 var 中所有叶节点
|
8
8
|
以列表 [(name,value), ...] 形式返回,其中名字 name 的解释方式参考 name_handler.parse_name() 介绍
|
@@ -23,6 +23,8 @@ def get_nodes(var, level=-1, b_strict=True):
|
|
23
23
|
默认为 True,不添加。
|
24
24
|
"""
|
25
25
|
assert isinstance(level, (int,))
|
26
|
+
kwargs.setdefault("b_skip_repeated_non_leaf_node", False)
|
27
|
+
|
26
28
|
if level == 0:
|
27
29
|
return [("", var)]
|
28
30
|
|
@@ -38,7 +40,7 @@ def get_nodes(var, level=-1, b_strict=True):
|
|
38
40
|
res_empty.add(idx + "@None") # 添加哨兵,表示空节点,并不会被实际解释
|
39
41
|
return False
|
40
42
|
|
41
|
-
traverse(var=var, match_cond=func, action_mode="skip", b_use_name_as_idx=True)
|
43
|
+
traverse(var=var, match_cond=func, action_mode="skip", b_use_name_as_idx=True, **kwargs)
|
42
44
|
|
43
45
|
if level != -1:
|
44
46
|
names = set()
|
@@ -15,7 +15,8 @@ class Traversal_Mode(Enum):
|
|
15
15
|
|
16
16
|
|
17
17
|
def traverse(var, match_cond, action_mode="remove", converter=None,
|
18
|
-
b_use_name_as_idx=False, traversal_mode="dfs_pre_order", b_traverse_matched_element=False
|
18
|
+
b_use_name_as_idx=False, traversal_mode="dfs_pre_order", b_traverse_matched_element=False,
|
19
|
+
b_skip_repeated_non_leaf_node=None, cond_for_repeated_leaf_to_skip=None, **kwargs):
|
19
20
|
"""
|
20
21
|
遍历 var 找到符合 match_cond 的元素,将其按照 action_mode 指定的操作进行处理
|
21
22
|
|
@@ -48,46 +49,86 @@ def traverse(var, match_cond, action_mode="remove", converter=None,
|
|
48
49
|
默认为 "dfs_pre_order"
|
49
50
|
b_use_name_as_idx: <boolean> 对于 match_cond/converter 中的 idx 参数,是传入整体的 name 还是父节点的 index 或 key。
|
50
51
|
默认为 False
|
51
|
-
b_traverse_matched_element
|
52
|
+
b_traverse_matched_element: <boolean> 对于匹配上的元素,经过处理后,是否继续遍历该元素的内容
|
52
53
|
默认为 False
|
54
|
+
b_skip_repeated_non_leaf_node: <boolean> 是否跳过重复的非叶节点。
|
55
|
+
何为重复?
|
56
|
+
在内存中的id相同。
|
57
|
+
默认为 None,此时将根据 action_mode 的来决定:
|
58
|
+
- 对于会对节点进行修改的模式,比如 "remove" 和 "replace",将设为 True,以避免预期外的重复转换和替换。
|
59
|
+
- 对于不会修改节点内容的模式,比如 "skip",将设为 False。
|
60
|
+
cond_for_repeated_leaf_to_skip: <list/tuple of callable> 在叶节点位置上,遇到满足其中某个条件的重复的元素时需要跳过。
|
61
|
+
要求函数接受 叶节点的值,并返回一个 boolean,表示是否匹配成功。
|
62
|
+
默认为 None
|
53
63
|
"""
|
54
64
|
assert callable(match_cond)
|
55
65
|
action_mode = Action_Mode(action_mode)
|
56
66
|
if action_mode is Action_Mode.REPLACE:
|
57
67
|
assert callable(converter)
|
58
68
|
traversal_mode = Traversal_Mode(traversal_mode)
|
69
|
+
if b_skip_repeated_non_leaf_node is None:
|
70
|
+
if action_mode is Action_Mode.SKIP:
|
71
|
+
b_skip_repeated_non_leaf_node = False
|
72
|
+
else: # action_mode in (Action_Mode.REMOVE, Action_Mode.REPLACE)
|
73
|
+
b_skip_repeated_non_leaf_node = True
|
74
|
+
cond_for_repeated_leaf_to_skip = [] if cond_for_repeated_leaf_to_skip is None else cond_for_repeated_leaf_to_skip
|
75
|
+
|
76
|
+
passed_node_ids = {"leaf": set(), "non_leaf": set()}
|
59
77
|
|
60
78
|
if traversal_mode is Traversal_Mode.BFS:
|
61
|
-
return _bfs(var, match_cond, action_mode, converter, b_use_name_as_idx, b_traverse_matched_element
|
79
|
+
return _bfs(var, match_cond, action_mode, converter, b_use_name_as_idx, b_traverse_matched_element,
|
80
|
+
b_skip_repeated_non_leaf_node=b_skip_repeated_non_leaf_node,
|
81
|
+
cond_for_repeated_leaf_to_skip=cond_for_repeated_leaf_to_skip,
|
82
|
+
passed_node_ids=passed_node_ids)
|
62
83
|
else:
|
63
84
|
return _dfs(var, match_cond, action_mode, converter, b_use_name_as_idx, traversal_mode,
|
64
|
-
b_traverse_matched_element, ""
|
85
|
+
b_traverse_matched_element, pre_name="",
|
86
|
+
b_skip_repeated_non_leaf_node=b_skip_repeated_non_leaf_node,
|
87
|
+
cond_for_repeated_leaf_to_skip=cond_for_repeated_leaf_to_skip,
|
88
|
+
passed_node_ids=passed_node_ids)
|
65
89
|
|
66
90
|
|
67
|
-
def _bfs(var, match_cond, action_mode, converter, b_use_name_as_idx, b_traverse_matched_element
|
91
|
+
def _bfs(var, match_cond, action_mode, converter, b_use_name_as_idx, b_traverse_matched_element,
|
92
|
+
b_skip_repeated_non_leaf_node, cond_for_repeated_leaf_to_skip, passed_node_ids):
|
68
93
|
temp = [("", var)]
|
69
94
|
|
70
95
|
while len(temp):
|
71
|
-
pre_name,
|
72
|
-
if isinstance(
|
73
|
-
|
96
|
+
pre_name, it = temp.pop(0)
|
97
|
+
if isinstance(it, (list, dict)):
|
98
|
+
#
|
99
|
+
if b_skip_repeated_non_leaf_node:
|
100
|
+
if id(it) in passed_node_ids["non_leaf"]:
|
101
|
+
continue
|
102
|
+
else:
|
103
|
+
passed_node_ids["non_leaf"].add(id(it))
|
104
|
+
#
|
105
|
+
keys = list(range(len(it)) if isinstance(it, list) else it.keys())
|
74
106
|
keys.reverse() # 反过来便于 列表 弹出元素
|
75
|
-
idx_ls = _gen_idx(
|
107
|
+
idx_ls = _gen_idx(it, keys, b_use_name_as_idx, pre_name)
|
76
108
|
|
77
109
|
# 匹配&处理
|
78
110
|
for k, idx in zip(keys, idx_ls):
|
79
|
-
b_matched, b_popped = _deal(
|
80
|
-
|
111
|
+
b_matched, b_popped, b_skip = _deal(it, k, idx, match_cond, converter, action_mode,
|
112
|
+
cond_for_repeated_leaf_to_skip, passed_node_ids)
|
113
|
+
if b_skip or b_popped or (b_matched and not b_traverse_matched_element):
|
81
114
|
continue
|
82
115
|
# 添加到队尾
|
83
|
-
temp.append((idx,
|
116
|
+
temp.append((idx, it[k]))
|
84
117
|
|
85
118
|
return var
|
86
119
|
|
87
120
|
|
88
121
|
def _dfs(var, match_cond, action_mode, converter,
|
89
|
-
b_use_name_as_idx, traversal_mode, b_traverse_matched_element, pre_name
|
122
|
+
b_use_name_as_idx, traversal_mode, b_traverse_matched_element, pre_name,
|
123
|
+
b_skip_repeated_non_leaf_node, cond_for_repeated_leaf_to_skip, passed_node_ids):
|
90
124
|
if isinstance(var, (list, dict)):
|
125
|
+
#
|
126
|
+
if b_skip_repeated_non_leaf_node:
|
127
|
+
if id(var) in passed_node_ids["non_leaf"]:
|
128
|
+
return var
|
129
|
+
else:
|
130
|
+
passed_node_ids["non_leaf"].add(id(var))
|
131
|
+
#
|
91
132
|
keys = list(range(len(var)) if isinstance(var, list) else var.keys())
|
92
133
|
keys.reverse() # 反过来便于 列表 弹出元素
|
93
134
|
idx_ls = _gen_idx(var, keys, b_use_name_as_idx, pre_name)
|
@@ -98,29 +139,42 @@ def _dfs(var, match_cond, action_mode, converter,
|
|
98
139
|
# 匹配&处理
|
99
140
|
deal_res_ls = []
|
100
141
|
for k, idx in zip(keys, idx_ls):
|
101
|
-
deal_res_ls.append(_deal(var, k, idx, match_cond, converter, action_mode
|
142
|
+
deal_res_ls.append(_deal(var, k, idx, match_cond, converter, action_mode,
|
143
|
+
cond_for_repeated_leaf_to_skip, passed_node_ids))
|
102
144
|
# 递归遍历
|
103
|
-
for (b_matched, b_popped), k, idx in zip(deal_res_ls, keys, idx_ls):
|
104
|
-
if b_popped or (b_matched and not b_traverse_matched_element):
|
145
|
+
for (b_matched, b_popped, b_skip), k, idx in zip(deal_res_ls, keys, idx_ls):
|
146
|
+
if b_skip or b_popped or (b_matched and not b_traverse_matched_element):
|
105
147
|
continue
|
106
148
|
var[k] = _dfs(var[k], match_cond, action_mode, converter, b_use_name_as_idx, traversal_mode,
|
107
|
-
b_traverse_matched_element, idx
|
149
|
+
b_traverse_matched_element, idx,
|
150
|
+
b_skip_repeated_non_leaf_node, cond_for_repeated_leaf_to_skip, passed_node_ids)
|
108
151
|
else:
|
109
152
|
# 后序
|
110
153
|
# 递归遍历
|
111
154
|
for k, idx in zip(keys, idx_ls):
|
112
155
|
var[k] = _dfs(var[k], match_cond, action_mode, converter, b_use_name_as_idx, traversal_mode,
|
113
|
-
b_traverse_matched_element, idx
|
156
|
+
b_traverse_matched_element, idx,
|
157
|
+
b_skip_repeated_non_leaf_node, cond_for_repeated_leaf_to_skip, passed_node_ids)
|
114
158
|
# 匹配&处理
|
115
159
|
for k, idx in zip(keys, idx_ls):
|
116
|
-
_deal(var, k, idx, match_cond, converter, action_mode
|
160
|
+
_deal(var, k, idx, match_cond, converter, action_mode,
|
161
|
+
cond_for_repeated_leaf_to_skip, passed_node_ids)
|
117
162
|
else:
|
118
163
|
pass
|
119
164
|
return var
|
120
165
|
|
121
166
|
|
122
|
-
def _deal(var, k, idx, match_cond, converter, action_mode
|
167
|
+
def _deal(var, k, idx, match_cond, converter, action_mode,
|
168
|
+
cond_for_repeated_leaf_to_skip, passed_node_ids):
|
123
169
|
"""处理节点"""
|
170
|
+
b_skip = False
|
171
|
+
|
172
|
+
if cond_for_repeated_leaf_to_skip and not isinstance(var[k], (dict, list,)) and any(
|
173
|
+
[i(var[k]) for i in cond_for_repeated_leaf_to_skip]):
|
174
|
+
if id(var[k]) in passed_node_ids["leaf"]:
|
175
|
+
return None, None, True
|
176
|
+
else:
|
177
|
+
passed_node_ids["leaf"].add(id(var[k]))
|
124
178
|
# 匹配
|
125
179
|
b_matched = match_cond(type(var), idx, var[k])
|
126
180
|
b_popped = False
|
@@ -133,7 +187,7 @@ def _deal(var, k, idx, match_cond, converter, action_mode):
|
|
133
187
|
var[k] = converter(idx, var[k])
|
134
188
|
else:
|
135
189
|
pass
|
136
|
-
return b_matched, b_popped
|
190
|
+
return b_matched, b_popped, b_skip
|
137
191
|
|
138
192
|
|
139
193
|
def _gen_idx(var, keys, b_use_name_as_idx, pre_name):
|
@@ -70,10 +70,7 @@ def _forward(var, flag, match_cond):
|
|
70
70
|
# 任选其一进行保留,其余改为引用
|
71
71
|
keep_name = unprocessed_name_set.pop()
|
72
72
|
for name in unprocessed_name_set:
|
73
|
-
|
74
|
-
var = set_value(var=var, name=name, value=f'<{flag}>{{{keep_name}}}', b_force=False)
|
75
|
-
except:
|
76
|
-
breakpoint()
|
73
|
+
var = set_value(var=var, name=name, value=f'<{flag}>{{{keep_name}}}', b_force=False)
|
77
74
|
processed_name_set.update(unprocessed_name_set)
|
78
75
|
|
79
76
|
# 将叶节点中,未被处理过,且是 str,且以 flag 开头的字符串,添加多一个 flag,以示区分
|
@@ -6,8 +6,6 @@ def hex_to_rgba(hex_color):
|
|
6
6
|
assert len(hex_color) in (6, 8), \
|
7
7
|
f'hex_color should be 6 or 8 characters long (not including #). but got {len(hex_color)}'
|
8
8
|
res = list(int(hex_color[i * 2:i * 2 + 2], 16) for i in range(len(hex_color) // 2))
|
9
|
-
if len(res) not in (3, 4):
|
10
|
-
breakpoint()
|
11
9
|
if len(res) == 4:
|
12
10
|
res[3] /= 255
|
13
11
|
return tuple(res)
|
@@ -30,7 +30,7 @@ def softmax(x, axis=-1, temperature=None, b_use_log_over_x=False):
|
|
30
30
|
else:
|
31
31
|
# softmax(x)
|
32
32
|
# 为了数值稳定,减去最大值
|
33
|
-
x = x - np.max(x)
|
33
|
+
x = x - np.max(x, axis=axis, keepdims=True)
|
34
34
|
#
|
35
35
|
if temperature is not None:
|
36
36
|
assert temperature > 0
|
@@ -46,3 +46,6 @@ if __name__ == '__main__':
|
|
46
46
|
print(softmax(np.asarray([[[0], [0.1]]]), temperature=0.00001, axis=1))
|
47
47
|
print(softmax(np.asarray([[[0], [0.1]]]), temperature=0, axis=1))
|
48
48
|
print(softmax([0, 1, 2], temperature=0.1))
|
49
|
+
print(softmax([[5.0000e-01, 5.0000e-01],
|
50
|
+
[7.0000e-01, 3.0000e-01],
|
51
|
+
[0.0000e+00, 1.0000e+03]], axis=-1, temperature=None))
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: kevin-toolbox-dev
|
3
|
+
Version: 1.4.9
|
4
|
+
Summary: 一个常用的工具代码包集合
|
5
|
+
Home-page: https://github.com/cantbeblank96/kevin_toolbox
|
6
|
+
Download-URL: https://github.com/username/your-package/archive/refs/tags/v1.0.0.tar.gz
|
7
|
+
Author: kevin hsu
|
8
|
+
Author-email: xukaiming1996@163.com
|
9
|
+
License: MIT
|
10
|
+
Keywords: mathematics,pytorch,numpy,machine-learning,algorithm
|
11
|
+
Platform: UNKNOWN
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
13
|
+
Classifier: Programming Language :: Python
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
15
|
+
Requires-Python: >=3.6
|
16
|
+
Description-Content-Type: text/markdown
|
17
|
+
Requires-Dist: torch (>=1.2.0)
|
18
|
+
Requires-Dist: numpy (>=1.19.0)
|
19
|
+
Provides-Extra: plot
|
20
|
+
Requires-Dist: matplotlib (>=3.0) ; extra == 'plot'
|
21
|
+
Provides-Extra: rest
|
22
|
+
Requires-Dist: pytest (>=6.2.5) ; extra == 'rest'
|
23
|
+
Requires-Dist: line-profiler (>=3.5) ; extra == 'rest'
|
24
|
+
|
25
|
+
# kevin_toolbox
|
26
|
+
|
27
|
+
一个通用的工具代码包集合
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
环境要求
|
32
|
+
|
33
|
+
```shell
|
34
|
+
numpy>=1.19
|
35
|
+
pytorch>=1.2
|
36
|
+
```
|
37
|
+
|
38
|
+
安装方法:
|
39
|
+
|
40
|
+
```shell
|
41
|
+
pip install kevin-toolbox --no-dependencies
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
[项目地址 Repo](https://github.com/cantbeblank96/kevin_toolbox)
|
47
|
+
|
48
|
+
[使用指南 User_Guide](./notes/User_Guide.md)
|
49
|
+
|
50
|
+
[免责声明 Disclaimer](./notes/Disclaimer.md)
|
51
|
+
|
52
|
+
[版本更新记录](./notes/Release_Record.md):
|
53
|
+
|
54
|
+
- v 1.4.9 (2025-03-27)【new feature】【bug fix】
|
55
|
+
|
56
|
+
- patches.for_numpy.linalg
|
57
|
+
- 【bug fix】fix bug in softmax(),修改 33 行,从减去全局最大值改为减去各个分组内部的最大值,避免全局最大值过大导致某些分组全体数值过小导致计算溢出。
|
58
|
+
- patches.for_matplotlib.common_charts.utils
|
59
|
+
- modify save_plot(),在最后增加 plt.close() 用于及时销毁已使用完的画布,避免不必要的内存占用。
|
60
|
+
- nested_dict_list
|
61
|
+
- 【new feature】modify traverse(),增加以下参数以更加精确地控制遍历时的行为:
|
62
|
+
- b_skip_repeated_non_leaf_node: 是否跳过重复的非叶节点。
|
63
|
+
- 何为重复?在内存中的id相同。
|
64
|
+
- 默认为 None,此时将根据 action_mode 的来决定:
|
65
|
+
- 对于会对节点进行修改的模式,比如 "remove" 和 "replace",将设为 True,以避免预期外的重复转换和替换。
|
66
|
+
- 对于不会修改节点内容的模式,比如 "skip",将设为 False。
|
67
|
+
- cond_for_repeated_leaf_to_skip:函数列表。在叶节点位置上,遇到满足其中某个条件的重复的元素时需要跳过。
|
68
|
+
- 同步修改内部使用了 traverse() 的 get_nodes() 和 copy_() 等函数。
|
69
|
+
- 新增了对应的测试用例。
|
70
|
+
- data_flow.file.json_
|
71
|
+
- 【bug fix】fix bug in write()。
|
72
|
+
- bug 归因:在 json_.write() 中通过使用 ndl.traverse() 来找出待转换的元素并进行转换,但是在 v1.4.8 前,该函数默认不会跳过重复(在内存中的id相同)出现的内容。由于该内容的不同引用实际上指向的是同一个,因此对这些引用的分别多次操作实际上就是对该内容进行了多次操作。
|
73
|
+
- bug 解决:在后续 v1.4.9 中为 ndl.traverse() 新增了 b_skip_repeated_non_leaf_node 用于控制是否需要跳过重复的引用。我们只需要在使用该函数时,令参数 b_skip_repeated_non_leaf_node=True即可。
|
74
|
+
|
75
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
kevin_toolbox/__init__.py,sha256
|
1
|
+
kevin_toolbox/__init__.py,sha256=Zz_PMwRXXXicnPLZzuj-A3qHU3jPIQ9XsqfQexBaPGg,410
|
2
2
|
kevin_toolbox/computer_science/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
kevin_toolbox/computer_science/algorithm/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
4
4
|
kevin_toolbox/computer_science/algorithm/cache_manager/__init__.py,sha256=p2hddkZ1HfYF9-m2Hx-o9IotwQHd4QwDCePy2ADpTDA,41
|
@@ -84,7 +84,7 @@ kevin_toolbox/data_flow/file/excel/__init__.py,sha256=5m_rmklI6n6yk4rSAEW39pxzYT
|
|
84
84
|
kevin_toolbox/data_flow/file/excel/write_excel_with_matrix.py,sha256=zrY_l0xCBpjqxm_9MoGpEXaZ4V_UwRMRgShessJ1sxA,5121
|
85
85
|
kevin_toolbox/data_flow/file/json_/__init__.py,sha256=VAt8COS2tO3PJRuhSc43i35fEOlArFM_YahdTmEBaHE,85
|
86
86
|
kevin_toolbox/data_flow/file/json_/read_json.py,sha256=RyCeNONMmvVOeX_F3kSSmED_nx4opipLe8OHJzXKZvQ,2151
|
87
|
-
kevin_toolbox/data_flow/file/json_/write_json.py,sha256=
|
87
|
+
kevin_toolbox/data_flow/file/json_/write_json.py,sha256=UYlyknBNs8t_8xHw8mJj0PBPwFp_to5j6NzaWi1Qkjw,4261
|
88
88
|
kevin_toolbox/data_flow/file/json_/converter/__init__.py,sha256=oQMgAgzELLq_f4LIIfz5E6l_E7g4lFsXqfmnJ3tPZTY,401
|
89
89
|
kevin_toolbox/data_flow/file/json_/converter/convert_dict_key_to_number.py,sha256=SuSZj_HCqKZutHAJ5AttABnGBRZplPGQhMxJBt2Wlgc,559
|
90
90
|
kevin_toolbox/data_flow/file/json_/converter/convert_ndarray_to_list.py,sha256=GALpC1MFJ4aMzs0FZIfJScYznfCP-gmhPeM8sWXGSWg,391
|
@@ -146,7 +146,7 @@ kevin_toolbox/developing/temperate/my_iterator_base.py,sha256=gLv9zdM987BHRghTfA
|
|
146
146
|
kevin_toolbox/developing/temperate/sequence_map_base.py,sha256=ha1EIMhn9lBF05s9niHLTuxhRslOx5faOk8UIjhhxUk,217
|
147
147
|
kevin_toolbox/env_info/__init__.py,sha256=8Io5RN5RcbEoMLHY4wfMa4pJxa1w0SMaXBN4v6k5CrM,134
|
148
148
|
kevin_toolbox/env_info/check_validity_and_uninstall.py,sha256=FOLeVKRqqiFnAQpx_AmIc8D3UcJigzIx58XDTJgv_qw,1676
|
149
|
-
kevin_toolbox/env_info/check_version_and_update.py,sha256=
|
149
|
+
kevin_toolbox/env_info/check_version_and_update.py,sha256=OjcfApg-szXu5Q8DKYhVJSr2fYmZHdqztZTAEMdumn4,2716
|
150
150
|
kevin_toolbox/env_info/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
151
151
|
kevin_toolbox/env_info/test/test_check_.py,sha256=wiIM_UVy_ksdq3la-pbF605Lhl5iW3a-0S_B74QzPT8,2054
|
152
152
|
kevin_toolbox/env_info/test/test_variable_.py,sha256=n9To8UNfBSNey8Xy7relXcbrf0yX8ZoZzfJctd2fHBs,1657
|
@@ -243,14 +243,14 @@ kevin_toolbox/math/utils/get_function_table_for_array_and_tensor.py,sha256=hZrXb
|
|
243
243
|
kevin_toolbox/math/utils/set_crop_by_box.py,sha256=NzW7M26Av097RchLUAhaO84ETLV121uxsNot_U6otLw,1775
|
244
244
|
kevin_toolbox/math/utils/split_integer_most_evenly.py,sha256=6hTWKXYx3YlotNMaw8cmecWO0A4C_Ny2kxgN9asiN9A,345
|
245
245
|
kevin_toolbox/nested_dict_list/__init__.py,sha256=ALcn1tYdBdDWUHyIQj588UfHgrAwbUcZu_bN2v-cEAc,333
|
246
|
-
kevin_toolbox/nested_dict_list/copy_.py,sha256=
|
246
|
+
kevin_toolbox/nested_dict_list/copy_.py,sha256=iS8P4JZ4SyBwZksObt2t1e4p0tXrsUu9NRtmjifjX5Q,6256
|
247
247
|
kevin_toolbox/nested_dict_list/count_leaf_node_nums.py,sha256=l67u47EvO1inoGinUqH6RZ7cHXwN0VcBQPUvSheqAvA,614
|
248
248
|
kevin_toolbox/nested_dict_list/get_hash.py,sha256=Ygadnn5dnvIeE-9t39p2EwNKNRLzomL37ZsRD5daXxo,1286
|
249
|
-
kevin_toolbox/nested_dict_list/get_nodes.py,sha256=
|
249
|
+
kevin_toolbox/nested_dict_list/get_nodes.py,sha256=3NJ2BPhNLr6hgooo-dOXLHZ6c-XjqOersLgTwTTXqbE,3831
|
250
250
|
kevin_toolbox/nested_dict_list/get_value.py,sha256=IiAqQCphyv-pAZWuQRWm0anEwxYQOkC9CttY5ZlUbSs,2389
|
251
251
|
kevin_toolbox/nested_dict_list/set_default.py,sha256=laSgGP1CbApNgFB9HZGCtxCG9fe7u1C-YOx9ZCoHJms,3460
|
252
252
|
kevin_toolbox/nested_dict_list/set_value.py,sha256=AQ4foDtKo4JxyR---of-VSxjhRWfqkv6TrnQ4EoRo3M,3711
|
253
|
-
kevin_toolbox/nested_dict_list/traverse.py,sha256=
|
253
|
+
kevin_toolbox/nested_dict_list/traverse.py,sha256=3P4mep8LNdDurxZgIEOqpB3k5chHOfQ0jQreWXjevDk,10327
|
254
254
|
kevin_toolbox/nested_dict_list/name_handler/__init__.py,sha256=P_pWq78oN6NdvWg2h6AduW_sUqbeaaVyoWWbW9kbgmU,107
|
255
255
|
kevin_toolbox/nested_dict_list/name_handler/build_name.py,sha256=VPWyjE8i8l-4Zm4tkD06Ie4J2NCsmI32ecOxZQqqmok,989
|
256
256
|
kevin_toolbox/nested_dict_list/name_handler/escape_node.py,sha256=niT9MxmsyrSZYhKXlWzdoKXVYhWRCR-kmQBkZopznpA,1163
|
@@ -277,7 +277,7 @@ kevin_toolbox/nested_dict_list/value_parser/cal_relation_between_references.py,s
|
|
277
277
|
kevin_toolbox/nested_dict_list/value_parser/eval_references.py,sha256=YQyOm3awKVRusXxSNObjJ2yPf0oE4gleobOn_RN_nzU,2301
|
278
278
|
kevin_toolbox/nested_dict_list/value_parser/parse_and_eval_references.py,sha256=RQEDFFNAhQQcX9H8curwja-pI2gKZlVx4M2qeneBOhA,2370
|
279
279
|
kevin_toolbox/nested_dict_list/value_parser/parse_references.py,sha256=G470xNzrRpYlS5To8R5yV0M6nX4iE5LLMp_eV49bh3Y,2116
|
280
|
-
kevin_toolbox/nested_dict_list/value_parser/replace_identical_with_reference.py,sha256=
|
280
|
+
kevin_toolbox/nested_dict_list/value_parser/replace_identical_with_reference.py,sha256=yTOZ0-8ZKbO7bS1jCvTZyLtS8OOvaalVG0O3arJa8NY,5349
|
281
281
|
kevin_toolbox/network/__init__.py,sha256=wOY_SKvbxzIIH_OFccMw3-LVUwZQwz8BTb82ht88JHA,346
|
282
282
|
kevin_toolbox/network/download_file.py,sha256=hW6DbdKPWcVqkG8U7NK2bwwubPtmaPHp3ftfuAjMNgI,6896
|
283
283
|
kevin_toolbox/network/fetch_content.py,sha256=WjpwZ_7pyfrAAmxNyHMu3onkbucELnHKYXDBM1fSSEY,2167
|
@@ -295,7 +295,7 @@ kevin_toolbox/patches/for_matplotlib/clear_border_of_axes.py,sha256=aQtzrw4W-DUf
|
|
295
295
|
kevin_toolbox/patches/for_matplotlib/variable.py,sha256=oJ0E8YEhnRMd0HmWKi3X56-m7sZ2ROlOnGOkyFTHUrU,645
|
296
296
|
kevin_toolbox/patches/for_matplotlib/color/__init__.py,sha256=5VGALqLCFsGqBWrOnFouVxkpp_DfqMIcKDLzYPdOTy8,170
|
297
297
|
kevin_toolbox/patches/for_matplotlib/color/color_format.py,sha256=ADwKfPmryxOuN691ol_2djOIkGQGJcnUAcqE3pbxGJs,205
|
298
|
-
kevin_toolbox/patches/for_matplotlib/color/convert_format.py,sha256=
|
298
|
+
kevin_toolbox/patches/for_matplotlib/color/convert_format.py,sha256=lTnKgXgCLvKPJc8L6xq_ABmTh5MeMb6vYIVj-lSkmVc,3988
|
299
299
|
kevin_toolbox/patches/for_matplotlib/color/generate_color_list.py,sha256=TZm-TkOuJbFzJ0_RklliQ9SHjMUhJvjbu7DUJGtgvw0,1993
|
300
300
|
kevin_toolbox/patches/for_matplotlib/color/get_format.py,sha256=l_vX8DUsWHNzLwveuF60TLcbQ_P7PvVt1yH_7FjElDs,312
|
301
301
|
kevin_toolbox/patches/for_matplotlib/common_charts/__init__.py,sha256=cxQT-iA6JdWqPqoXvw535_8_zJWZr0Mqr3Ln7oV2awo,2024
|
@@ -308,14 +308,14 @@ kevin_toolbox/patches/for_matplotlib/common_charts/plot_scatters.py,sha256=ouypS
|
|
308
308
|
kevin_toolbox/patches/for_matplotlib/common_charts/plot_scatters_matrix.py,sha256=PTFYaLu_0w1T66p_PP0rK-q1oqNgek-Nto-ILWbawIc,4848
|
309
309
|
kevin_toolbox/patches/for_matplotlib/common_charts/utils/__init__.py,sha256=mI06j19Yk8-6ksAc_OjhXudse7gbkz1dS4-lvmj85FI,115
|
310
310
|
kevin_toolbox/patches/for_matplotlib/common_charts/utils/get_output_path.py,sha256=lHd5unN5nsu7Msqnct5cSn_6Ib3uZUaExpI7qvndE7U,614
|
311
|
-
kevin_toolbox/patches/for_matplotlib/common_charts/utils/save_plot.py,sha256=
|
311
|
+
kevin_toolbox/patches/for_matplotlib/common_charts/utils/save_plot.py,sha256=2yKtzGZOYl0YpVKl2YzuD52G5CpuRbR5YeXp6EktDFM,306
|
312
312
|
kevin_toolbox/patches/for_matplotlib/common_charts/utils/save_record.py,sha256=mZSVGn9om0Qzi2gGiWwlFDUSLu7RgSGtkae0T16UOSk,1332
|
313
313
|
kevin_toolbox/patches/for_numpy/__init__.py,sha256=SNjZGxTRBn-uzkyZi6Jcz-9juhhZKT8TI70qH-fhGGc,21
|
314
314
|
kevin_toolbox/patches/for_numpy/linalg/__init__.py,sha256=TH-M0Orrakyf9S9A8FiDf3zLHY24gP2SGGTuNmLhDP4,128
|
315
315
|
kevin_toolbox/patches/for_numpy/linalg/cos_similar.py,sha256=bFkfDwrW3maXq5i9ZABidKfg8ZdEdXfFgNzW_uygrM4,423
|
316
316
|
kevin_toolbox/patches/for_numpy/linalg/entropy.py,sha256=PSdwkzySvWF4h4Xi27w2kvLq5WAeM_ysLstPFNBMoX8,1080
|
317
317
|
kevin_toolbox/patches/for_numpy/linalg/normalize.py,sha256=7qstt__rwUkk3jRJOQoneBp9YdfhYQtWfh6PZoWbvaA,625
|
318
|
-
kevin_toolbox/patches/for_numpy/linalg/softmax.py,sha256=
|
318
|
+
kevin_toolbox/patches/for_numpy/linalg/softmax.py,sha256=JWYGLT18Yx9csm_svAe1mHtzLwaQhOah8ePFzJRZgaU,2285
|
319
319
|
kevin_toolbox/patches/for_numpy/random/__init__.py,sha256=SDFF7yiUrkSHE9f9quALFQd6bCF2Mr1Q0vznl7QBhyo,231
|
320
320
|
kevin_toolbox/patches/for_numpy/random/get_rng.py,sha256=QblrMKg4OFVy-C4A6rQ-zq26uDKzhMifKTFUlyW3Ksw,1999
|
321
321
|
kevin_toolbox/patches/for_numpy/random/get_rng_state.py,sha256=wceMn3LXx7Fbe2S5f5p6kkMEpNb6GYq3Y-DG9amuL5w,113
|
@@ -372,7 +372,7 @@ kevin_toolbox/patches/for_torch/nn/__init__.py,sha256=aJs3RMqRzQmd8KKDmQW9FxwCqS
|
|
372
372
|
kevin_toolbox/patches/for_torch/nn/lambda_layer.py,sha256=KUuLiX_Dr4bvRmpAaCW5QTDWDcnMPRnw0jg4NNXTFhM,223
|
373
373
|
kevin_toolbox/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
374
374
|
kevin_toolbox/utils/variable.py,sha256=PxUmp9w4CKKcKHjgdVNF_Iaw5gwPPOd4aY_Oe5F9U1M,133
|
375
|
-
kevin_toolbox_dev-1.4.
|
376
|
-
kevin_toolbox_dev-1.4.
|
377
|
-
kevin_toolbox_dev-1.4.
|
378
|
-
kevin_toolbox_dev-1.4.
|
375
|
+
kevin_toolbox_dev-1.4.9.dist-info/METADATA,sha256=Q66eIgYcla2f_LJor80E5ApSiVUBVqT7Wld_vYesMW8,3277
|
376
|
+
kevin_toolbox_dev-1.4.9.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
377
|
+
kevin_toolbox_dev-1.4.9.dist-info/top_level.txt,sha256=S5TeRGF-PwlhsaUEPTI-f2vWrpLmh3axpyI6v-Fi75o,14
|
378
|
+
kevin_toolbox_dev-1.4.9.dist-info/RECORD,,
|
@@ -1,86 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: kevin-toolbox-dev
|
3
|
-
Version: 1.4.8
|
4
|
-
Summary: 一个常用的工具代码包集合
|
5
|
-
Home-page: https://github.com/cantbeblank96/kevin_toolbox
|
6
|
-
Download-URL: https://github.com/username/your-package/archive/refs/tags/v1.0.0.tar.gz
|
7
|
-
Author: kevin hsu
|
8
|
-
Author-email: xukaiming1996@163.com
|
9
|
-
License: MIT
|
10
|
-
Keywords: mathematics,pytorch,numpy,machine-learning,algorithm
|
11
|
-
Platform: UNKNOWN
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
13
|
-
Classifier: Programming Language :: Python
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
15
|
-
Requires-Python: >=3.6
|
16
|
-
Description-Content-Type: text/markdown
|
17
|
-
Requires-Dist: torch (>=1.2.0)
|
18
|
-
Requires-Dist: numpy (>=1.19.0)
|
19
|
-
Provides-Extra: plot
|
20
|
-
Requires-Dist: matplotlib (>=3.0) ; extra == 'plot'
|
21
|
-
Provides-Extra: rest
|
22
|
-
Requires-Dist: pytest (>=6.2.5) ; extra == 'rest'
|
23
|
-
Requires-Dist: line-profiler (>=3.5) ; extra == 'rest'
|
24
|
-
|
25
|
-
# kevin_toolbox
|
26
|
-
|
27
|
-
一个通用的工具代码包集合
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
环境要求
|
32
|
-
|
33
|
-
```shell
|
34
|
-
numpy>=1.19
|
35
|
-
pytorch>=1.2
|
36
|
-
```
|
37
|
-
|
38
|
-
安装方法:
|
39
|
-
|
40
|
-
```shell
|
41
|
-
pip install kevin-toolbox --no-dependencies
|
42
|
-
```
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
[项目地址 Repo](https://github.com/cantbeblank96/kevin_toolbox)
|
47
|
-
|
48
|
-
[使用指南 User_Guide](./notes/User_Guide.md)
|
49
|
-
|
50
|
-
[免责声明 Disclaimer](./notes/Disclaimer.md)
|
51
|
-
|
52
|
-
[版本更新记录](./notes/Release_Record.md):
|
53
|
-
|
54
|
-
- v 1.4.8 (2025-03-06)【new feature】【refactor】
|
55
|
-
|
56
|
-
- 【new feature】network,新增网络模块。
|
57
|
-
- 该模块包含网络访问相关的函数:
|
58
|
-
- get_response(),获取 url 的响应。
|
59
|
-
- fetch_metadata(),从 URL/response 中获取文件名、后缀(扩展名)、大小等元信息。
|
60
|
-
- fetch_content(),从 URL/response 中获取内容。
|
61
|
-
- download_file(),下载文件。
|
62
|
-
- env_info
|
63
|
-
- modify Env_Vars_Parser.parse(),新增 default 参数用于支持解释失败时候返回默认值。
|
64
|
-
- computer_science.algorithm
|
65
|
-
- 【refactor】【new feature】decorator,从 developing 中将装饰器相关模块整合到 cs.algorithm 中。
|
66
|
-
- 该目录目前包含以下函数:
|
67
|
-
- retry(),在函数执行失败时,等待一定时间后重试多次。
|
68
|
-
- restore_original_work_path(),在运行函数 func 前备份当前工作目录,并在函数运行结束后还原到原始工作目录。
|
69
|
-
- registration
|
70
|
-
- 【new feature】add Serializer_for_Registry_Execution,用于对基于 Registry 中成员构建的执行过程进行序列化和反序列化操作。
|
71
|
-
- nested_dict_list.serializer
|
72
|
-
- modify write(),增加返回值,返回保存到的路径。
|
73
|
-
- patches.for_matplotlib
|
74
|
-
- 【new feature】add COMMON_CHARTS,增加该注册器用于管理 common_charts 模块中的方法。
|
75
|
-
- common_charts
|
76
|
-
- 为所有plot_xx函数增加了注释和测试用例。
|
77
|
-
- 为所有plot_xx函数增加以下参数:
|
78
|
-
- b_generate_record:是否保存函数参数为档案。
|
79
|
-
- 默认为 False,当设置为 True 时将会把函数参数保存成 [output_path].record.tar。
|
80
|
-
- 后续可以使用 plot_from_record() 函数或者 Serializer_for_Registry_Execution 读取该档案,并进行修改和重新绘制。
|
81
|
-
- 该参数仅在 output_dir 和 output_path 非 None 时起效。
|
82
|
-
- output_path:图片输出路径。
|
83
|
-
- 支持直接指定图片要保存的路径,在原有的通过 output_dir 和 title 自动生成路径的方式之外,提供了另一个指定的方式。
|
84
|
-
- 【new feature】add plot_from_record,从保存的档案 .record.tar 文件中恢复并绘制图像。
|
85
|
-
|
86
|
-
|
File without changes
|
File without changes
|