numbox 0.2.7__py3-none-any.whl → 0.2.8__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 CHANGED
@@ -1 +1 @@
1
- __version__ = '0.2.7'
1
+ __version__ = '0.2.8'
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.8
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=QS1piWKz3Mys2vOiR2kTlrqfdbiwJYEfhOlgbh73Sg8,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
@@ -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.8.dist-info/LICENSE,sha256=YYgNvjH_p6-1NsdrIqGJnr1GUbZzA_8DxsP6vVfM6nY,1446
36
+ numbox-0.2.8.dist-info/METADATA,sha256=krcMK7v4WNgTrcuriQAWMASeaRod9KybPc57tRUE7w0,2935
37
+ numbox-0.2.8.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
38
+ numbox-0.2.8.dist-info/top_level.txt,sha256=A67jOkfqidCSYYm6ifjN_WZyIiR1B27fjxv6nNbPvjc,7
39
+ numbox-0.2.8.dist-info/RECORD,,
File without changes