Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _evaluate(self, *args):
indices = []
for arg in args:
if type(arg) == awkward.JaggedArray:
raise Exception('JaggedArray in inputs')
if self._dimension == 1:
indices.append(np.clip(np.searchsorted(self._axes, args[0], side='right') - 1, 0, self._values.shape[0] - 1))
else:
for dim in range(self._dimension):
indices.append(np.clip(np.searchsorted(self._axes[dim], args[dim], side='right') - 1,
0, self._values.shape[len(self._axes) - dim - 1] - 1))
indices.reverse()
return numba_apply_1d(self._values[tuple(indices)], args[self._feval_dim])
""" uncertainties = f(args) """
bin_vals = {argname: args[self._dim_args[argname]] for argname in self._dim_order}
eval_vals = {argname: args[self._eval_args[argname]] for argname in self._eval_vars}
# lookup the bins that we care about
dim1_name = self._dim_order[0]
dim1_indices = np.clip(np.searchsorted(self._bins[dim1_name],
bin_vals[dim1_name],
side='right') - 1,
0, self._bins[dim1_name].size - 2)
# get clamp values and clip the inputs
outs = np.ones(shape=(args[0].size, 2), dtype=np.float)
for i in np.unique(dim1_indices):
mask = np.where(dim1_indices == i)
vals = np.clip(eval_vals[self._eval_vars[0]][mask],
self._eval_knots[0], self._eval_knots[-1])
outs[:, 0][mask] += self._eval_ups[i](vals)
outs[:, 1][mask] -= self._eval_downs[i](vals)
return outs
def index(self, identifier):
"""Index of a identifer or label
Parameters
----------
identifier : float or Interval or np.ndarray
The identifier(s) to lookup. Supports vectorized
calls when a numpy 1D array of numbers is passed.
Returns an integer corresponding to the index in the axis where the histogram would be filled.
The integer range includes flow bins: ``0 = underflow, n+1 = overflow, n+2 = nanflow``
"""
if (isinstance(identifier, np.ndarray) and len(identifier.shape) == 1) or isinstance(identifier, numbers.Number):
if self._uniform:
idx = np.clip(np.floor((identifier - self._lo) * self._bins / (self._hi - self._lo)) + 1, 0, self._bins + 1)
if isinstance(idx, np.ndarray):
idx[np.isnan(idx)] = self.size - 1
idx = idx.astype(int)
elif np.isnan(idx):
idx = self.size - 1
else:
idx = int(idx)
return idx
else:
return np.searchsorted(self._bins, identifier, side='right')
elif isinstance(identifier, Interval):
if identifier.nan():
return self.size - 1
for idx, interval in enumerate(self._intervals):
if interval._lo <= identifier._lo and interval._hi >= identifier._hi:
return idx