numbox 0.2.7__py3-none-any.whl → 0.2.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.
numbox/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.2.7'
1
+ __version__ = '0.2.9'
@@ -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
- if name in _specs_registry:
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
- _specs_registry[name] = spec_
36
+ registry[name] = spec_
35
37
  return spec_
36
38
 
37
39
 
@@ -47,6 +49,7 @@ class _Derived(NamedTuple):
47
49
  init_value: Any
48
50
  derive: Callable
49
51
  sources: Sequence[Union['Derived', End]]
52
+ registry: dict = None
50
53
  ty: Optional[type | Type] = None
51
54
 
52
55
 
@@ -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 | Sequence[SpecTy]):
135
+ def infer_end_and_derived_nodes(access_nodes: SpecTy | Sequence[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 = [_specs_registry[name] for name in all_inputs_.keys()]
138
- all_derived_lst = [_specs_registry[name] for name in all_derived_.keys()]
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(*access_nodes: SpecTy | Sequence[SpecTy], jit_options: Optional[dict] = None):
143
- all_inputs_, all_derived_ = infer_end_and_derived_nodes(access_nodes)
145
+ def make_graph(
146
+ *access_nodes: SpecTy | Sequence[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}
numbox/core/work/work.py CHANGED
@@ -166,6 +166,9 @@ def _call_derive(typingctx: Context, derive_ty: FunctionType, sources_ty: Tuple)
166
166
  return sig, codegen
167
167
 
168
168
 
169
+ _source_getter_registry = {}
170
+
171
+
169
172
  def _make_source_getter(source_ind):
170
173
  return f"""
171
174
  @intrinsic
@@ -182,8 +185,6 @@ def _get_source_{source_ind}(typingctx: Context, sources_ty: Tuple):
182
185
 
183
186
  def _make_calculate_code(num_sources):
184
187
  code_txt = StringIO()
185
- for source_ind_ in range(num_sources):
186
- code_txt.write(_make_source_getter(source_ind_))
187
188
  code_txt.write("""
188
189
  def _calculate_(work_):
189
190
  if work_.derived:
@@ -194,7 +195,8 @@ def _calculate_(work_):
194
195
  for source_ind_ in range(num_sources):
195
196
  code_txt.write(f"""
196
197
  source_{source_ind_} = _get_source_{source_ind_}(sources)
197
- source_{source_ind_}.calculate()""")
198
+ if not source_{source_ind_}.derived:
199
+ source_{source_ind_}.calculate()""")
198
200
  code_txt.write("""
199
201
  v = _call_derive(work_.derive, work_.sources)
200
202
  work_.derived = True
@@ -206,6 +208,15 @@ def _calculate_(work_):
206
208
  _calculate_registry = {}
207
209
 
208
210
 
211
+ def ensure_presence_of_source_getters_in_ns(num_sources_, ns_):
212
+ for source_i in range(num_sources_):
213
+ _source_getter = _source_getter_registry.get(source_i, None)
214
+ source_getter_code_txt = _make_source_getter(source_i)
215
+ source_getter_code = compile(source_getter_code_txt, getfile(_file_anchor), mode="exec")
216
+ exec(source_getter_code, ns_)
217
+ _source_getter_registry[source_i] = True
218
+
219
+
209
220
  @overload_method(WorkTypeClass, "calculate", strict=False, jit_options=default_jit_options)
210
221
  def ol_calculate(self_ty):
211
222
  derive_ty = self_ty.field_dict["derive"]
@@ -217,13 +228,15 @@ def ol_calculate(self_ty):
217
228
  sources_ty = self_ty.field_dict["sources"]
218
229
  num_sources = sources_ty.count
219
230
  _calculate = _calculate_registry.get(num_sources, None)
220
- if _calculate is None:
221
- code_txt = _make_calculate_code(num_sources)
222
- ns = getmodule(_file_anchor).__dict__
223
- code = compile(code_txt, getfile(_file_anchor), mode="exec")
224
- exec(code, ns)
225
- _calculate = ns["_calculate_"]
226
- _calculate_registry[num_sources] = _calculate
231
+ if _calculate is not None:
232
+ return _calculate
233
+ ns = getmodule(_file_anchor).__dict__
234
+ ensure_presence_of_source_getters_in_ns(num_sources, ns)
235
+ code_txt = _make_calculate_code(num_sources)
236
+ code = compile(code_txt, getfile(_file_anchor), mode="exec")
237
+ exec(code, ns)
238
+ _calculate = ns["_calculate_"]
239
+ _calculate_registry[num_sources] = _calculate
227
240
  return _calculate
228
241
 
229
242
 
@@ -246,8 +259,6 @@ def _cast_to_work_data(typingctx, work_ty, data_as_erased_ty: ErasedType):
246
259
 
247
260
  def _make_loader_code(num_sources):
248
261
  code_txt = StringIO()
249
- for source_ind_ in range(num_sources):
250
- code_txt.write(_make_source_getter(source_ind_))
251
262
  code_txt.write("""
252
263
  def _loader_(work_, data_):
253
264
  reset = False
@@ -282,20 +293,20 @@ def ol_load(work_ty, data_ty: DictType):
282
293
  sources_ty = work_ty.field_dict["sources"]
283
294
  num_sources = sources_ty.count
284
295
  _loader = _loader_registry.get(num_sources, None)
285
- if _loader is None:
286
- code_txt = _make_loader_code(num_sources)
287
- ns = getmodule(_file_anchor).__dict__
288
- code = compile(code_txt, getfile(_file_anchor), mode="exec")
289
- exec(code, ns)
290
- _loader = ns["_loader_"]
291
- _loader_registry[num_sources] = _loader
296
+ if _loader is not None:
297
+ return _loader
298
+ ns = getmodule(_file_anchor).__dict__
299
+ ensure_presence_of_source_getters_in_ns(num_sources, ns)
300
+ code_txt = _make_loader_code(num_sources)
301
+ code = compile(code_txt, getfile(_file_anchor), mode="exec")
302
+ exec(code, ns)
303
+ _loader = ns["_loader_"]
304
+ _loader_registry[num_sources] = _loader
292
305
  return _loader
293
306
 
294
307
 
295
308
  def _make_combine_code(num_sources):
296
309
  code_txt = StringIO()
297
- for source_ind_ in range(num_sources):
298
- code_txt.write(_make_source_getter(source_ind_))
299
310
  code_txt.write("""
300
311
  def _combine_(work_, data_, harvested_=None):
301
312
  if harvested_ is None:
@@ -331,13 +342,15 @@ def ol_combine(work_ty, data_ty: DictType, harvested_ty=NoneType):
331
342
  sources_ty = work_ty.field_dict["sources"]
332
343
  num_sources = sources_ty.count
333
344
  _combine = _combine_registry.get(num_sources, None)
334
- if _combine is None:
335
- code_txt = _make_combine_code(num_sources)
336
- ns = {**getmodule(_file_anchor).__dict__, **{"boolean": boolean, "Dict": Dict}}
337
- code = compile(code_txt, getfile(_file_anchor), mode="exec")
338
- exec(code, ns)
339
- _combine = ns["_combine_"]
340
- _combine_registry[num_sources] = _combine
345
+ if _combine is not None:
346
+ return _combine
347
+ ns = {**getmodule(_file_anchor).__dict__, **{"boolean": boolean, "Dict": Dict}}
348
+ ensure_presence_of_source_getters_in_ns(num_sources, ns)
349
+ code_txt = _make_combine_code(num_sources)
350
+ code = compile(code_txt, getfile(_file_anchor), mode="exec")
351
+ exec(code, ns)
352
+ _combine = ns["_combine_"]
353
+ _combine_registry[num_sources] = _combine
341
354
  return _combine
342
355
 
343
356
 
@@ -364,8 +377,6 @@ def ol_get_inputs_names(self_ty):
364
377
 
365
378
  def _make_inputs_vector_code(num_sources):
366
379
  code_txt = StringIO()
367
- for source_ind_ in range(num_sources):
368
- code_txt.write(_make_source_getter(source_ind_))
369
380
  code_txt.write("""
370
381
  def _inputs_vector_(work_):
371
382
  node = work_.node
@@ -399,13 +410,15 @@ def ol_make_inputs_vector(self_ty):
399
410
  return inputs_vector
400
411
  return _
401
412
  _inputs_vector = _inputs_vector_registry.get(num_sources, None)
402
- if _inputs_vector is None:
403
- code_txt = _make_inputs_vector_code(num_sources)
404
- ns = {**getmodule(_file_anchor).__dict__, **{"new": new}}
405
- code = compile(code_txt, getfile(_file_anchor), mode="exec")
406
- exec(code, ns)
407
- _inputs_vector = ns["_inputs_vector_"]
408
- _inputs_vector_registry[num_sources] = _inputs_vector
413
+ if _inputs_vector is not None:
414
+ return _inputs_vector
415
+ ns = {**getmodule(_file_anchor).__dict__, **{"new": new}}
416
+ ensure_presence_of_source_getters_in_ns(num_sources, ns)
417
+ code_txt = _make_inputs_vector_code(num_sources)
418
+ code = compile(code_txt, getfile(_file_anchor), mode="exec")
419
+ exec(code, ns)
420
+ _inputs_vector = ns["_inputs_vector_"]
421
+ _inputs_vector_registry[num_sources] = _inputs_vector
409
422
  return _inputs_vector
410
423
 
411
424
 
numbox/utils/timer.py CHANGED
@@ -9,13 +9,16 @@ logging.basicConfig(level=logging.WARNING)
9
9
  class Timer:
10
10
  times = {}
11
11
 
12
+ def __init__(self, precision=3):
13
+ self.precision = precision
14
+
12
15
  def __call__(self, func):
13
16
  def _(*args, **kws):
14
17
  t_start = perf_counter()
15
18
  res = func(*args, **kws)
16
19
  t_end = perf_counter()
17
20
  duration = t_end - t_start
18
- logger.warning(f"Execution of {func.__name__} took {duration:.3f}s")
21
+ logger.warning(f"Execution of {func.__name__} took {duration:.{self.precision}f}s")
19
22
  self.times[func.__name__] = duration
20
23
  return res
21
24
  return _
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: numbox
3
- Version: 0.2.7
3
+ Version: 0.2.9
4
4
  Author: Mikhail Goykhman
5
5
  License: MIT License (with Citation Clause)
6
6
 
@@ -34,8 +34,12 @@ Keywords: llvmlite,numba,numpy
34
34
  Requires-Python: >=3.9
35
35
  Description-Content-Type: text/markdown
36
36
  License-File: LICENSE
37
+ Requires-Dist: llvmlite==0.44.0
38
+ Requires-Dist: numba~=0.61.0
39
+ Requires-Dist: numpy~=2.1.3
37
40
  Provides-Extra: docs
38
41
  Requires-Dist: sphinx==8.1.3; extra == "docs"
42
+ Requires-Dist: sphinx-sitemap==2.7.2; extra == "docs"
39
43
  Requires-Dist: sphinx-rtd-theme; extra == "docs"
40
44
 
41
45
  # numbox
@@ -1,4 +1,4 @@
1
- numbox/__init__.py,sha256=e3cfQy_iVs9ILsymUalJnJu5D_dd7HuUVoVwKKurcL0,22
1
+ numbox/__init__.py,sha256=bd8hlxKMc0Fh_2w5GWfqBtuwa8uTepTMjT8w7F-EKvY,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,7 +15,7 @@ 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=U7hxopSwOc1ke1Hqup6xCliO7bqjq91zVX1SixYPxoM,6072
18
+ numbox/core/work/builder.py,sha256=jH9lIxpJcU-eJ8SMQe7TzV8xci7FQgK8ZOhFma0n5DI,6308
19
19
  numbox/core/work/combine_utils.py,sha256=qTVGke_ydzaTQ7o29DFjZWZzKjRNKb0L3yJMaR3TLII,2430
20
20
  numbox/core/work/explain.py,sha256=ESwvsTgfe0w7UnM13yyVpVDtfJyAK2A1sNdF3RNb-jU,1200
21
21
  numbox/core/work/loader_utils.py,sha256=g83mDWidZJ8oLWP3I3rK8aGISYOO2S-w6HDgtosCyck,1572
@@ -23,17 +23,17 @@ numbox/core/work/lowlevel_work_utils.py,sha256=TgRRcNfks0oaOXGXXr3ptafd_Xv_lpmH8
23
23
  numbox/core/work/node.py,sha256=CMolyoRQjG2A-pTQqZQ0kxKOYTKipWRC0mu8RWHuTUI,5096
24
24
  numbox/core/work/node_base.py,sha256=uI7asM2itQcHuOByXyJtqvrd4ovW6EXDRdHYp3JVHQ0,998
25
25
  numbox/core/work/print_tree.py,sha256=y2u7xmbHvpcA57y8PrGSqOunLNCqhgNXdVtXHqvy1M0,2340
26
- numbox/core/work/work.py,sha256=V_pYW0sqdYHh45ago3aMz0fG4U_UfsNLIcpBejn_ttU,14725
26
+ numbox/core/work/work.py,sha256=596flxydeHuEJ3oUhNz3PYPtA58nxERifvBCh8BWVug,15091
27
27
  numbox/core/work/work_utils.py,sha256=3q_nnBdzuxWWcdFpbRL2H0T9ZNkUgx1J1uhiZkX3YG4,1039
28
28
  numbox/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  numbox/utils/highlevel.py,sha256=0sUVGOFAzFaGycKrXloGySLjp5EAPaf1B0AcOT1dfbw,8326
30
30
  numbox/utils/lowlevel.py,sha256=ACpf8_HyOIsobPlZ31bapkEyuCsV5dojW3AFrcKykrw,10712
31
31
  numbox/utils/meminfo.py,sha256=ykFi8Vt0WcHI3ztgMwvpn6NqaflDSQGL8tjI01jrzm0,1759
32
32
  numbox/utils/standard.py,sha256=2fPrMlSXe2TG3CIfjJOT8LQkHEH86oOOj1AvwQkYCfA,450
33
- numbox/utils/timer.py,sha256=KkAkWOHQ72WtPjyiAzt_tF1q0DcOnCDkITTb85DvkUM,553
33
+ numbox/utils/timer.py,sha256=5_d690Fb3L2axJBRxtoB0qe23exBosNR4qu6cno4QfY,641
34
34
  numbox/utils/void_type.py,sha256=IkZsjNeAIShYJtvWbvERdHnl_mbF1rCRWiM3gp6II8U,404
35
- numbox-0.2.7.dist-info/LICENSE,sha256=YYgNvjH_p6-1NsdrIqGJnr1GUbZzA_8DxsP6vVfM6nY,1446
36
- numbox-0.2.7.dist-info/METADATA,sha256=J-Ash1idpJn-eUghPfVjNlVQhkbT0DHKa1D4K-A3ZTs,2792
37
- numbox-0.2.7.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
38
- numbox-0.2.7.dist-info/top_level.txt,sha256=A67jOkfqidCSYYm6ifjN_WZyIiR1B27fjxv6nNbPvjc,7
39
- numbox-0.2.7.dist-info/RECORD,,
35
+ numbox-0.2.9.dist-info/LICENSE,sha256=YYgNvjH_p6-1NsdrIqGJnr1GUbZzA_8DxsP6vVfM6nY,1446
36
+ numbox-0.2.9.dist-info/METADATA,sha256=s-0iSTOHKbHEyDL5u8DgOPcbgHSs1897HV9T3963x9E,2935
37
+ numbox-0.2.9.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
38
+ numbox-0.2.9.dist-info/top_level.txt,sha256=A67jOkfqidCSYYm6ifjN_WZyIiR1B27fjxv6nNbPvjc,7
39
+ numbox-0.2.9.dist-info/RECORD,,
File without changes