How to use the larray.AxisCollection function in larray

To help you get started, we’ve selected a few larray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
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
        # has multiple axes) because all the non slice indexers MUST broadcast together to a single
        # "advanced indexer"

        # to determine where the "subspace" axes will be inserted, a scalar key counts as "advanced" indexing
        adv_axes_indices = [i for i, axis_key in enumerate(key)
github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
Whether or not to convert ranges to slices. Defaults to False.

    Returns
    -------
    raw_key: tuple
    res_axes: AxisCollection
    transposed_indices: tuple or None
    """

    if translate_key:
        key = self._translated_key(key)
    assert isinstance(key, tuple) and len(key) == self.ndim

    # scalar array
    if not self.ndim:
        return key, la.AxisCollection([]), None

    # transform ranges to slices if needed
    if collapse_slices:
        # isinstance(np.ndarray, collections.Sequence) is False but it behaves like one
        seq_types = (tuple, list, np.ndarray)
        # TODO: we should only do this if there are no Array key (with axes corresponding to the range)
        # otherwise we will be translating them back to a range afterwards
        key = [_range_to_slice(axis_key, len(axis)) if isinstance(axis_key, seq_types) else axis_key
               for axis_key, axis in zip(key, self)]

    # transform non-Array advanced keys (list and ndarray) to Array
    def to_la_ikey(axis, axis_key):
        # MONKEY PATCH CHANGED LINE
        if isinstance(axis_key, (int, long, np.integer, slice, la.Array)):
            return axis_key
        else: