How to use the larray.core.group._range_to_slice 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
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:
            # MONKEY PATCH CHANGED LINE
            assert isinstance(axis_key, (list, np.ndarray)), \
                "unsupported key type: {} ({})".format(axis_key, type(axis_key))
            res_axis = axis.subaxis(axis_key)
            # TODO: for perf reasons, we should bypass creating an actual Array by returning axes and key_data
            # but then we will need to implement a function similar to make_numpy_broadcastable which works on axes
            # and rawdata instead of arrays
            return la.Array(axis_key, res_axis)