numbox 0.2.4__py3-none-any.whl → 0.2.5__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 +32 -2
- numbox/core/work/explain.py +35 -0
- numbox/core/work/work.py +7 -3
- {numbox-0.2.4.dist-info → numbox-0.2.5.dist-info}/METADATA +1 -1
- {numbox-0.2.4.dist-info → numbox-0.2.5.dist-info}/RECORD +9 -8
- {numbox-0.2.4.dist-info → numbox-0.2.5.dist-info}/LICENSE +0 -0
- {numbox-0.2.4.dist-info → numbox-0.2.5.dist-info}/WHEEL +0 -0
- {numbox-0.2.4.dist-info → numbox-0.2.5.dist-info}/top_level.txt +0 -0
numbox/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.2.
|
|
1
|
+
__version__ = '0.2.5'
|
numbox/core/work/builder.py
CHANGED
|
@@ -15,13 +15,32 @@ def _file_anchor():
|
|
|
15
15
|
raise NotImplementedError
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
_nodes_names = set()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _End(NamedTuple):
|
|
19
22
|
name: str
|
|
20
23
|
init_value: Any
|
|
21
24
|
ty: Optional[type | Type] = None
|
|
22
25
|
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
def _new(cls, super_proxy, *args, **kwargs):
|
|
28
|
+
name = kwargs.get("name")
|
|
29
|
+
assert name, "`name` key-word argument has not been provided"
|
|
30
|
+
if name in _nodes_names:
|
|
31
|
+
raise ValueError(f"Node '{name}' has already been defined on this graph. Pick a different name.")
|
|
32
|
+
_nodes_names.add(name)
|
|
33
|
+
return super_proxy.__new__(cls, *args, **kwargs)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class End(_End):
|
|
37
|
+
__slots__ = ()
|
|
38
|
+
|
|
39
|
+
def __new__(cls, *args, **kwargs):
|
|
40
|
+
return _new(cls, super(), *args, **kwargs)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class _Derived(NamedTuple):
|
|
25
44
|
name: str
|
|
26
45
|
init_value: Any
|
|
27
46
|
derive: Callable
|
|
@@ -29,6 +48,13 @@ class Derived(NamedTuple):
|
|
|
29
48
|
ty: Optional[type | Type] = None
|
|
30
49
|
|
|
31
50
|
|
|
51
|
+
class Derived(_Derived):
|
|
52
|
+
__slots__ = ()
|
|
53
|
+
|
|
54
|
+
def __new__(cls, *args, **kwargs):
|
|
55
|
+
return _new(cls, super(), *args, **kwargs)
|
|
56
|
+
|
|
57
|
+
|
|
32
58
|
SpecTy = Derived | End
|
|
33
59
|
|
|
34
60
|
|
|
@@ -50,6 +76,9 @@ def get_ty(spec_):
|
|
|
50
76
|
return spec_.ty or typeof(spec_.init_value)
|
|
51
77
|
|
|
52
78
|
|
|
79
|
+
_derive_funcs = {}
|
|
80
|
+
|
|
81
|
+
|
|
53
82
|
def _derived_cres(ty, sources: Sequence[End], derive, jit_options=None):
|
|
54
83
|
jit_options = jit_options if jit_options is not None else {}
|
|
55
84
|
sources_ty = []
|
|
@@ -58,6 +87,7 @@ def _derived_cres(ty, sources: Sequence[End], derive, jit_options=None):
|
|
|
58
87
|
sources_ty.append(source_ty)
|
|
59
88
|
derive_sig = ty(*sources_ty)
|
|
60
89
|
derive_cres = cres(derive_sig, **jit_options)(derive)
|
|
90
|
+
_derive_funcs[id(derive_cres)] = derive
|
|
61
91
|
return derive_cres
|
|
62
92
|
|
|
63
93
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from inspect import getsource
|
|
2
|
+
from textwrap import indent
|
|
3
|
+
|
|
4
|
+
from numbox.core.work.builder import _derive_funcs
|
|
5
|
+
from numbox.core.work.work import Work
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_func_code(derive_func_p_):
|
|
9
|
+
derive_func_ = _derive_funcs.get(derive_func_p_)
|
|
10
|
+
return derive_func_.__name__, indent(getsource(derive_func_), " ")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _explain(work: Work, derivation_: list, derived_: set):
|
|
14
|
+
if work.name in derived_:
|
|
15
|
+
return
|
|
16
|
+
if len(work.sources) == 0:
|
|
17
|
+
derivation_.append(f"{work.name}: end node\n")
|
|
18
|
+
derived_.add(work.name)
|
|
19
|
+
return
|
|
20
|
+
inputs_names = []
|
|
21
|
+
for source in work.sources:
|
|
22
|
+
_explain(source, derivation_, derived_)
|
|
23
|
+
inputs_names.append(source.name)
|
|
24
|
+
derive_func_ptrs = work.derive
|
|
25
|
+
derive_func_name, derive_func_code = get_func_code(derive_func_ptrs[1])
|
|
26
|
+
derivation_.append(f"""{work.name}: {derive_func_name}({", ".join(inputs_names)})
|
|
27
|
+
|
|
28
|
+
{derive_func_code}""")
|
|
29
|
+
derived_.add(work.name)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def explain(work: Work):
|
|
33
|
+
derivation = []
|
|
34
|
+
_explain(work, derivation, set())
|
|
35
|
+
return "\n".join(derivation)
|
numbox/core/work/work.py
CHANGED
|
@@ -17,7 +17,7 @@ from numbox.core.work.lowlevel_work_utils import ll_make_work, WorkTypeClass
|
|
|
17
17
|
from numbox.core.work.node import NodeType
|
|
18
18
|
from numbox.core.work.node_base import NodeBase, NodeBaseType
|
|
19
19
|
from numbox.utils.lowlevel import (
|
|
20
|
-
extract_struct_member, _cast, is_not_null, get_func_p_from_func_struct, get_ll_func_sig
|
|
20
|
+
extract_struct_member, _cast, _get_func_tuple, is_not_null, get_func_p_from_func_struct, get_ll_func_sig
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
|
|
@@ -73,6 +73,11 @@ class Work(NodeBase):
|
|
|
73
73
|
def sources(self):
|
|
74
74
|
return self.sources
|
|
75
75
|
|
|
76
|
+
@property
|
|
77
|
+
@njit(**default_jit_options)
|
|
78
|
+
def derive(self):
|
|
79
|
+
return _get_func_tuple(self.derive)
|
|
80
|
+
|
|
76
81
|
@property
|
|
77
82
|
@njit(**default_jit_options)
|
|
78
83
|
def derived(self):
|
|
@@ -441,9 +446,8 @@ def ol_depends_on(self_ty, obj_ty):
|
|
|
441
446
|
node = self.as_node()
|
|
442
447
|
return name_ in node.all_inputs_names()
|
|
443
448
|
else:
|
|
444
|
-
assert isinstance(obj_ty, WorkTypeClass), f"Cannot handle {obj_ty}"
|
|
445
|
-
|
|
446
449
|
def _(self, obj_):
|
|
447
450
|
node = self.as_node()
|
|
448
451
|
return obj_.name in node.all_inputs_names()
|
|
452
|
+
assert isinstance(obj_ty, WorkTypeClass), f"Cannot handle {obj_ty}"
|
|
449
453
|
return _
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
numbox/__init__.py,sha256=
|
|
1
|
+
numbox/__init__.py,sha256=8f4ummWTPl6PtdE9DzSUgZhPjGioA_NDC-hDpqzB9qI,22
|
|
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,14 +15,15 @@ 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=kGYlEdLK40lxxu56e_S32s9YuQ6AuQnFegt5uQrUw5w,3889
|
|
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=tfrizyZuBy21zsoILELzQIj-wtYAuPitDqtVg7V1atw,5362
|
|
19
19
|
numbox/core/work/combine_utils.py,sha256=qTVGke_ydzaTQ7o29DFjZWZzKjRNKb0L3yJMaR3TLII,2430
|
|
20
|
+
numbox/core/work/explain.py,sha256=qEorYHRSe8P2MygodCYsz57UtWeRfaS27xHSw3hBgmo,1063
|
|
20
21
|
numbox/core/work/loader_utils.py,sha256=g83mDWidZJ8oLWP3I3rK8aGISYOO2S-w6HDgtosCyck,1572
|
|
21
22
|
numbox/core/work/lowlevel_work_utils.py,sha256=TgRRcNfks0oaOXGXXr3ptafd_Xv_lpmH8sjBrJ9bPuI,5748
|
|
22
23
|
numbox/core/work/node.py,sha256=CMolyoRQjG2A-pTQqZQ0kxKOYTKipWRC0mu8RWHuTUI,5096
|
|
23
24
|
numbox/core/work/node_base.py,sha256=uI7asM2itQcHuOByXyJtqvrd4ovW6EXDRdHYp3JVHQ0,998
|
|
24
25
|
numbox/core/work/print_tree.py,sha256=y2u7xmbHvpcA57y8PrGSqOunLNCqhgNXdVtXHqvy1M0,2340
|
|
25
|
-
numbox/core/work/work.py,sha256=
|
|
26
|
+
numbox/core/work/work.py,sha256=V_pYW0sqdYHh45ago3aMz0fG4U_UfsNLIcpBejn_ttU,14725
|
|
26
27
|
numbox/core/work/work_utils.py,sha256=3q_nnBdzuxWWcdFpbRL2H0T9ZNkUgx1J1uhiZkX3YG4,1039
|
|
27
28
|
numbox/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
29
|
numbox/utils/highlevel.py,sha256=gXYzLsFPKHQfGqaz-Z4DWcCQddv0dS6SKwIsM-_xjYg,1487
|
|
@@ -30,8 +31,8 @@ numbox/utils/lowlevel.py,sha256=ACpf8_HyOIsobPlZ31bapkEyuCsV5dojW3AFrcKykrw,1071
|
|
|
30
31
|
numbox/utils/meminfo.py,sha256=ykFi8Vt0WcHI3ztgMwvpn6NqaflDSQGL8tjI01jrzm0,1759
|
|
31
32
|
numbox/utils/timer.py,sha256=KkAkWOHQ72WtPjyiAzt_tF1q0DcOnCDkITTb85DvkUM,553
|
|
32
33
|
numbox/utils/void_type.py,sha256=IkZsjNeAIShYJtvWbvERdHnl_mbF1rCRWiM3gp6II8U,404
|
|
33
|
-
numbox-0.2.
|
|
34
|
-
numbox-0.2.
|
|
35
|
-
numbox-0.2.
|
|
36
|
-
numbox-0.2.
|
|
37
|
-
numbox-0.2.
|
|
34
|
+
numbox-0.2.5.dist-info/LICENSE,sha256=YYgNvjH_p6-1NsdrIqGJnr1GUbZzA_8DxsP6vVfM6nY,1446
|
|
35
|
+
numbox-0.2.5.dist-info/METADATA,sha256=kHcNZstr-whJ0XoJ6IcoXACjnAn33yjvJgdn4Ksx6sk,2792
|
|
36
|
+
numbox-0.2.5.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
37
|
+
numbox-0.2.5.dist-info/top_level.txt,sha256=A67jOkfqidCSYYm6ifjN_WZyIiR1B27fjxv6nNbPvjc,7
|
|
38
|
+
numbox-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|