MCPcopy Create free account
hub / github.com/PyTables/PyTables / _compute

Function _compute

bench/evaluate.py:28–79  ·  view source on GitHub ↗

Compute the `function` over the `arguments` and put the outcome in `result`

(result, function, arguments, start=None, stop=None, step=None)

Source from the content-addressed store, hash-verified

26
27
28def _compute(result, function, arguments, start=None, stop=None, step=None):
29 """Compute the `function` over the `arguments` and put the outcome in
30 `result`"""
31 arg0 = arguments[0]
32 if hasattr(arg0, "maindim"):
33 maindim = arg0.maindim
34 (start, stop, step) = arg0._process_range_read(start, stop, step)
35 nrowsinbuf = arg0.nrowsinbuf
36 print("nrowsinbuf-->", nrowsinbuf)
37 else:
38 maindim = 0
39 (start, stop, step) = (0, len(arg0), 1)
40 nrowsinbuf = len(arg0)
41 shape = list(arg0.shape)
42 shape[maindim] = len(range(start, stop, step))
43
44 # The slices parameter for arg0.__getitem__
45 slices = [slice(0, dim, 1) for dim in arg0.shape]
46
47 # This is a hack to prevent doing unnecessary conversions
48 # when copying buffers
49 if hasattr(arg0, "maindim"):
50 for arg in arguments:
51 arg._v_convert = False
52
53 # Start the computation itself
54 for start2 in range(start, stop, step * nrowsinbuf):
55 # Save the records on disk
56 stop2 = start2 + step * nrowsinbuf
57 if stop2 > stop:
58 stop2 = stop
59 # Set the proper slice in the main dimension
60 slices[maindim] = slice(start2, stop2, step)
61 start3 = (start2 - start) / step
62 stop3 = start3 + nrowsinbuf
63 if stop3 > shape[maindim]:
64 stop3 = shape[maindim]
65 # Compute the slice to be filled in destination
66 sl = []
67 for i in range(maindim):
68 sl.append(slice(None, None, None))
69 sl.append(slice(start3, stop3, None))
70 # Get the values for computing the buffer
71 values = [arg.__getitem__(tuple(slices)) for arg in arguments]
72 result[tuple(sl)] = function(*values)
73
74 # Activate the conversion again (default)
75 if hasattr(arg0, "maindim"):
76 for arg in arguments:
77 arg._v_convert = True
78
79 return result
80
81
82def evaluate(ex, out=None, local_dict=None, global_dict=None, **kwargs):

Callers 1

evaluateFunction · 0.85

Calls 3

_process_range_readMethod · 0.80
appendMethod · 0.45
__getitem__Method · 0.45

Tested by

no test coverage detected