Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# transform slice keys to Array too IF they refer to axes present in advanced key (so that those axes
# broadcast together instead of being duplicated, which is not what we want)
def get_axes(value):
return value.axes if isinstance(value, la.Array) else la.AxisCollection([])
def slice_to_sequence(axis, axis_key):
if isinstance(axis_key, slice) and axis in la_key_axes:
# TODO: sequence assumes the axis in the la_key is in the same order. It will be easier to solve when
# make_numpy_broadcastable automatically aligns all arrays
start, stop, step = axis_key.indices(len(axis))
return la.sequence(axis.subaxis(axis_key), initial=start, inc=step)
else:
return axis_key
# XXX: can we avoid computing this twice? (here and in make_numpy_broadcastable)
la_key_axes = la.AxisCollection.union(*[get_axes(k) for k in key])
key = tuple(slice_to_sequence(axis, axis_key) for axis, axis_key in zip(self, key))
# start with the simple (slice) keys
# scalar keys are ignored since they do not produce any resulting axis
res_axes = la.AxisCollection([axis.subaxis(axis_key)
for axis, axis_key in zip(self, key)
if isinstance(axis_key, slice)])
transpose_indices = None
# if there are only simple keys, do not bother going via the "advanced indexing" code path
# MONKEY PATCH CHANGED LINE
if all(isinstance(axis_key, (int, long, np.integer, slice)) for axis_key in key):
bcasted_adv_keys = key
else:
# Now that we know advanced indexing comes into play, we need to compute were the subspace created by the
# advanced indexes will be inserted. Note that there is only ever a SINGLE combined subspace (even if it