numbox 0.2.8__py3-none-any.whl → 0.2.10__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.
Potentially problematic release.
This version of numbox might be problematic. Click here for more details.
- numbox/__init__.py +1 -1
- numbox/core/work/builder.py +23 -15
- numbox/core/work/builder_utils.py +40 -0
- numbox/core/work/lowlevel_work_utils.py +5 -5
- numbox/core/work/work.py +0 -1
- numbox/utils/highlevel.py +1 -0
- {numbox-0.2.8.dist-info → numbox-0.2.10.dist-info}/METADATA +1 -1
- {numbox-0.2.8.dist-info → numbox-0.2.10.dist-info}/RECORD +11 -10
- {numbox-0.2.8.dist-info → numbox-0.2.10.dist-info}/LICENSE +0 -0
- {numbox-0.2.8.dist-info → numbox-0.2.10.dist-info}/WHEEL +0 -0
- {numbox-0.2.8.dist-info → numbox-0.2.10.dist-info}/top_level.txt +0 -0
numbox/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.2.
|
|
1
|
+
__version__ = '0.2.10'
|
numbox/core/work/builder.py
CHANGED
|
@@ -5,7 +5,7 @@ from io import StringIO
|
|
|
5
5
|
from itertools import chain
|
|
6
6
|
from numba import njit, typeof
|
|
7
7
|
from numba.core.types import Type
|
|
8
|
-
from typing import Any, Callable, Dict, NamedTuple, Optional, Sequence, Union
|
|
8
|
+
from typing import Any, Callable, Dict, NamedTuple, Optional, Sequence, Tuple as PyTuple, Union
|
|
9
9
|
|
|
10
10
|
from numbox.core.configurations import default_jit_options
|
|
11
11
|
from numbox.core.work.lowlevel_work_utils import ll_make_work
|
|
@@ -22,16 +22,18 @@ _specs_registry = dict()
|
|
|
22
22
|
class _End(NamedTuple):
|
|
23
23
|
name: str
|
|
24
24
|
init_value: Any
|
|
25
|
+
registry: dict = None
|
|
25
26
|
ty: Optional[type | Type] = None
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
def _new(cls, super_proxy, *args, **kwargs):
|
|
29
30
|
name = kwargs.get("name")
|
|
30
31
|
assert name, "`name` key-word argument has not been provided"
|
|
31
|
-
|
|
32
|
+
registry = kwargs.get("registry", _specs_registry)
|
|
33
|
+
if name in registry:
|
|
32
34
|
raise ValueError(f"Node '{name}' has already been defined on this graph. Pick a different name.")
|
|
33
35
|
spec_ = super_proxy.__new__(cls, *args, **kwargs)
|
|
34
|
-
|
|
36
|
+
registry[name] = spec_
|
|
35
37
|
return spec_
|
|
36
38
|
|
|
37
39
|
|
|
@@ -46,7 +48,8 @@ class _Derived(NamedTuple):
|
|
|
46
48
|
name: str
|
|
47
49
|
init_value: Any
|
|
48
50
|
derive: Callable
|
|
49
|
-
sources: Sequence[Union['Derived', End]]
|
|
51
|
+
sources: Sequence[Union['Derived', End]] = ()
|
|
52
|
+
registry: dict = None
|
|
50
53
|
ty: Optional[type | Type] = None
|
|
51
54
|
|
|
52
55
|
|
|
@@ -99,7 +102,7 @@ def _derived_line(
|
|
|
99
102
|
name_ = derived_.name
|
|
100
103
|
init_ = derived_.init_value
|
|
101
104
|
sources_ = ", ".join([s.name for s in derived_.sources])
|
|
102
|
-
sources_ = sources_ + ", " if "," not in sources_ else sources_
|
|
105
|
+
sources_ = sources_ + ", " if sources_ and "," not in sources_ else sources_
|
|
103
106
|
ty_ = get_ty(derived_)
|
|
104
107
|
derive_func = derived_.derive
|
|
105
108
|
derive_hashes.append(sha256(getsource(derive_func).encode("utf-8")).hexdigest())
|
|
@@ -118,29 +121,35 @@ def code_block_hash(code_txt: str):
|
|
|
118
121
|
return sha256(code_txt.encode("utf-8")).hexdigest()
|
|
119
122
|
|
|
120
123
|
|
|
121
|
-
def _infer_end_and_derived_nodes(spec: SpecTy, all_inputs_: Dict[str, Type], all_derived_: Dict[str, Type]):
|
|
124
|
+
def _infer_end_and_derived_nodes(spec: SpecTy, all_inputs_: Dict[str, Type], all_derived_: Dict[str, Type], registry):
|
|
122
125
|
if spec.name in all_inputs_ or spec.name in all_derived_:
|
|
123
126
|
return
|
|
124
127
|
if isinstance(spec, End):
|
|
125
128
|
all_inputs_[spec.name] = get_ty(spec)
|
|
126
129
|
return
|
|
127
130
|
for source in spec.sources:
|
|
128
|
-
_infer_end_and_derived_nodes(source, all_inputs_, all_derived_)
|
|
131
|
+
_infer_end_and_derived_nodes(source, all_inputs_, all_derived_, registry)
|
|
129
132
|
all_derived_[spec.name] = get_ty(spec)
|
|
130
133
|
|
|
131
134
|
|
|
132
|
-
def infer_end_and_derived_nodes(access_nodes: SpecTy
|
|
135
|
+
def infer_end_and_derived_nodes(access_nodes: PyTuple[SpecTy, ...], registry):
|
|
133
136
|
all_inputs_ = dict()
|
|
134
137
|
all_derived_ = dict()
|
|
135
138
|
for access_node in access_nodes:
|
|
136
|
-
_infer_end_and_derived_nodes(access_node, all_inputs_, all_derived_)
|
|
137
|
-
all_inputs_lst = [
|
|
138
|
-
all_derived_lst = [
|
|
139
|
+
_infer_end_and_derived_nodes(access_node, all_inputs_, all_derived_, registry)
|
|
140
|
+
all_inputs_lst = [registry[name] for name in all_inputs_.keys()]
|
|
141
|
+
all_derived_lst = [registry[name] for name in all_derived_.keys()]
|
|
139
142
|
return all_inputs_lst, all_derived_lst
|
|
140
143
|
|
|
141
144
|
|
|
142
|
-
def make_graph(
|
|
143
|
-
|
|
145
|
+
def make_graph(
|
|
146
|
+
*access_nodes: SpecTy,
|
|
147
|
+
registry: Optional[dict] = None,
|
|
148
|
+
jit_options: Optional[dict] = None
|
|
149
|
+
):
|
|
150
|
+
if registry is None:
|
|
151
|
+
registry = _specs_registry
|
|
152
|
+
all_inputs_, all_derived_ = infer_end_and_derived_nodes(access_nodes, registry)
|
|
144
153
|
if jit_options is None:
|
|
145
154
|
jit_options = {}
|
|
146
155
|
jit_options = {**default_jit_options, **jit_options}
|
|
@@ -161,8 +170,7 @@ def make_graph(*access_nodes: SpecTy | Sequence[SpecTy], jit_options: Optional[d
|
|
|
161
170
|
hash_str = f"code_block = {code_txt.getvalue()} initializers = {list(initializers.values())} derive_hashes = {derive_hashes}" # noqa: E501
|
|
162
171
|
hash_ = code_block_hash(hash_str)
|
|
163
172
|
access_nodes_names = [n.name for n in access_nodes]
|
|
164
|
-
tup_ = ", ".join(access_nodes_names)
|
|
165
|
-
tup_ = tup_ + ", " if ", " not in tup_ else tup_
|
|
173
|
+
tup_ = ", ".join(access_nodes_names) + ","
|
|
166
174
|
code_txt.write(f"""\n\taccess_tuple = ({tup_})""")
|
|
167
175
|
code_txt.write("\n\treturn access_tuple")
|
|
168
176
|
code_txt = code_txt.getvalue()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import NamedTuple, Tuple
|
|
2
|
+
|
|
3
|
+
from numbox.core.work.builder import SpecTy, End
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _infer_sources_dependencies(spec: SpecTy, sources_dependencies_):
|
|
7
|
+
if isinstance(spec, End):
|
|
8
|
+
return
|
|
9
|
+
for source in spec.sources:
|
|
10
|
+
spec_dependencies = sources_dependencies_.setdefault(spec.name, set())
|
|
11
|
+
sources_dependencies_.setdefault(source.name, set()).add(spec.name)
|
|
12
|
+
sources_dependencies_[source.name] |= spec_dependencies
|
|
13
|
+
_infer_sources_dependencies(source, sources_dependencies_)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def infer_sources_dependencies(access_nodes: NamedTuple | Tuple):
|
|
17
|
+
"""
|
|
18
|
+
For all nodes names accessible from the given `access_nodes`,
|
|
19
|
+
return dictionary of all nodes names that depend on each of the
|
|
20
|
+
nodes in the accessible graph. For instance::
|
|
21
|
+
|
|
22
|
+
m1 -- m2 -- m3 -- m5
|
|
23
|
+
|
|
|
24
|
+
m4
|
|
25
|
+
|
|
26
|
+
will return::
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
"m1": set(),
|
|
30
|
+
"m2": {"m1"},
|
|
31
|
+
"m3": {"m1", "m2"},
|
|
32
|
+
"m4": {"m1"},
|
|
33
|
+
"m5": {"m1", "m2", "m3"}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
"""
|
|
37
|
+
sources_dependencies_ = {}
|
|
38
|
+
for access_node in access_nodes:
|
|
39
|
+
_infer_sources_dependencies(access_node, sources_dependencies_)
|
|
40
|
+
return sources_dependencies_
|
|
@@ -106,16 +106,16 @@ def ensure_work_boxing():
|
|
|
106
106
|
@intrinsic(prefer_literal=False)
|
|
107
107
|
def ll_make_work(typingctx, name_ty, data_ty, sources_ty, derive_ty, data_ty_ref: TypeRef = NoneType):
|
|
108
108
|
"""
|
|
109
|
-
Purely intrinsic work constructor
|
|
110
|
-
`numbox.core.work.work.Work`.
|
|
109
|
+
Purely intrinsic work constructor.
|
|
111
110
|
|
|
112
111
|
Substantially more efficient in memory use, cache disk space, and
|
|
113
112
|
compilation time for inlining multiple `Work` instantiations inside
|
|
114
113
|
jitted context (e.g., in large-graph applications).
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
Alternative `make_work`-like constructors with `inline="always"`
|
|
116
|
+
might save memory and cache disk space demand (when the inlining
|
|
117
|
+
directive is actually heeded by numba engine) but significantly
|
|
118
|
+
lengthen the compilation time.
|
|
119
119
|
"""
|
|
120
120
|
if data_ty_ref != NoneType:
|
|
121
121
|
data_ty = data_ty_ref.instance_type
|
numbox/core/work/work.py
CHANGED
|
@@ -210,7 +210,6 @@ _calculate_registry = {}
|
|
|
210
210
|
|
|
211
211
|
def ensure_presence_of_source_getters_in_ns(num_sources_, ns_):
|
|
212
212
|
for source_i in range(num_sources_):
|
|
213
|
-
_source_getter = _source_getter_registry.get(source_i, None)
|
|
214
213
|
source_getter_code_txt = _make_source_getter(source_i)
|
|
215
214
|
source_getter_code = compile(source_getter_code_txt, getfile(_file_anchor), mode="exec")
|
|
216
215
|
exec(source_getter_code, ns_)
|
numbox/utils/highlevel.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
numbox/__init__.py,sha256=
|
|
1
|
+
numbox/__init__.py,sha256=JYwb-C-8s4xwnUp2y3_Hp7caBJyciFJh6lKJs_WcehM,23
|
|
2
2
|
numbox/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
numbox/core/configurations.py,sha256=0bCmxXL-QMwtvyIDhpXLeT-1KJMf_QpH0wLuEvYLGxQ,68
|
|
4
4
|
numbox/core/any/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -15,25 +15,26 @@ numbox/core/bindings/utils.py,sha256=aRtN8oUYBk9vgoUGaUJosGx0Za-vvCNwwbZg_g_-LRs
|
|
|
15
15
|
numbox/core/proxy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
numbox/core/proxy/proxy.py,sha256=Wt7yzswDmeQXt0yjcTcnLi2coneowSHWXy_IFpZZJMU,3612
|
|
17
17
|
numbox/core/work/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
numbox/core/work/builder.py,sha256=
|
|
18
|
+
numbox/core/work/builder.py,sha256=d0DRwJoyskp-6tYQyV1VE-v9eX99qJbQJ_FdAFrjuiE,6273
|
|
19
|
+
numbox/core/work/builder_utils.py,sha256=z8au1x10AwnzQ0_MAbQ6DnKTp3u9HeYZ1jyfkUMYjVg,1213
|
|
19
20
|
numbox/core/work/combine_utils.py,sha256=qTVGke_ydzaTQ7o29DFjZWZzKjRNKb0L3yJMaR3TLII,2430
|
|
20
21
|
numbox/core/work/explain.py,sha256=ESwvsTgfe0w7UnM13yyVpVDtfJyAK2A1sNdF3RNb-jU,1200
|
|
21
22
|
numbox/core/work/loader_utils.py,sha256=g83mDWidZJ8oLWP3I3rK8aGISYOO2S-w6HDgtosCyck,1572
|
|
22
|
-
numbox/core/work/lowlevel_work_utils.py,sha256=
|
|
23
|
+
numbox/core/work/lowlevel_work_utils.py,sha256=ouQ9u-wb8N-x2p93H6_72_9AzYxBOvigeU79i7S9qu0,5752
|
|
23
24
|
numbox/core/work/node.py,sha256=CMolyoRQjG2A-pTQqZQ0kxKOYTKipWRC0mu8RWHuTUI,5096
|
|
24
25
|
numbox/core/work/node_base.py,sha256=uI7asM2itQcHuOByXyJtqvrd4ovW6EXDRdHYp3JVHQ0,998
|
|
25
26
|
numbox/core/work/print_tree.py,sha256=y2u7xmbHvpcA57y8PrGSqOunLNCqhgNXdVtXHqvy1M0,2340
|
|
26
|
-
numbox/core/work/work.py,sha256=
|
|
27
|
+
numbox/core/work/work.py,sha256=yISGKbXsut5ZSbRT2h6uMAAFsKDQ__fcX27HuI6ydhA,15022
|
|
27
28
|
numbox/core/work/work_utils.py,sha256=3q_nnBdzuxWWcdFpbRL2H0T9ZNkUgx1J1uhiZkX3YG4,1039
|
|
28
29
|
numbox/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
-
numbox/utils/highlevel.py,sha256=
|
|
30
|
+
numbox/utils/highlevel.py,sha256=3dEdIbk0OJcBmuWdbuwG-0v80U19sSYMIxOR8qslGsQ,8360
|
|
30
31
|
numbox/utils/lowlevel.py,sha256=ACpf8_HyOIsobPlZ31bapkEyuCsV5dojW3AFrcKykrw,10712
|
|
31
32
|
numbox/utils/meminfo.py,sha256=ykFi8Vt0WcHI3ztgMwvpn6NqaflDSQGL8tjI01jrzm0,1759
|
|
32
33
|
numbox/utils/standard.py,sha256=2fPrMlSXe2TG3CIfjJOT8LQkHEH86oOOj1AvwQkYCfA,450
|
|
33
34
|
numbox/utils/timer.py,sha256=5_d690Fb3L2axJBRxtoB0qe23exBosNR4qu6cno4QfY,641
|
|
34
35
|
numbox/utils/void_type.py,sha256=IkZsjNeAIShYJtvWbvERdHnl_mbF1rCRWiM3gp6II8U,404
|
|
35
|
-
numbox-0.2.
|
|
36
|
-
numbox-0.2.
|
|
37
|
-
numbox-0.2.
|
|
38
|
-
numbox-0.2.
|
|
39
|
-
numbox-0.2.
|
|
36
|
+
numbox-0.2.10.dist-info/LICENSE,sha256=YYgNvjH_p6-1NsdrIqGJnr1GUbZzA_8DxsP6vVfM6nY,1446
|
|
37
|
+
numbox-0.2.10.dist-info/METADATA,sha256=VYLHTb3Nzvg7thEEQ3fCKHCxmp3cjXlNEk3OZWxETfI,2936
|
|
38
|
+
numbox-0.2.10.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
39
|
+
numbox-0.2.10.dist-info/top_level.txt,sha256=A67jOkfqidCSYYm6ifjN_WZyIiR1B27fjxv6nNbPvjc,7
|
|
40
|
+
numbox-0.2.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|