(indices, maxlen)
return indices
Convert integer indices to slice if possible. It only converts increasing
    integer ranges with positive steps and valid starts and ends.
    Only convert valid ends so that invalid ranges will still raise
    an exception.

    Allows numpy to reuse the data array, because it defaults to copying
    if given indices.

    Parameters
    ----------
    indices : 1D sequence, slice or Ellipsis
Convert integer indices to slice if possible. It only converts increasing
    integer ranges with positive steps and valid starts and ends.
    Only convert valid ends so that invalid ranges will still raise
    an exception.
Convert integer indices to slice if possible . It only converts increasing integer ranges with positive steps and valid starts and ends . Only convert valid ends so that invalid ranges will still raise an exception .
def _optimize_indices(indices, maxlen):
    """
    Convert integer indices to slice if possible. It only converts increasing
    integer ranges with positive steps and valid starts and ends.
    Only convert valid ends so that invalid ranges will still raise
    an exception.

    Allows numpy to reuse the data array, because it defaults to copying
    if given indices.

    Parameters
    ----------
    indices : 1D sequence, slice or Ellipsis
    """
    if isinstance(indices, slice):
        return indices

    if indices is ...:
        return slice(None, None, 1)

    # a very common case for column selection
    if len(indices) == 1 and not isinstance(indices[0], bool):
        if indices[0] >= 0:
            return slice(indices[0], indices[0] + 1, 1)
        else:
            return slice(indices[0], indices[0] - 1, -1)

    if len(indices) >= 1:
        indices = np.asarray(indices)
        if indices.dtype != bool:
            begin = indices[0]
            end = indices[-1]
            steps = np.diff(indices) if len(indices) > 1 else np.array([1])
            step = steps[0]

            # continuous ranges with constant step and valid start and stop index can be slices
            if np.all(steps == step) and step > 0 and begin >= 0 and end < maxlen:
                return slice(begin, end + step, step)

    return indices
def _optimize_indices ( indices , maxlen ) : if isinstance ( indices , slice ) : return indices if indices is ... : return slice ( None , None , 1 ) # a very common case for column selection if len ( indices ) == 1 and not isinstance ( indices [ 0 ] , bool ) : if indices [ 0 ] >= 0 : return slice ( indices [ 0 ] , indices [ 0 ] + 1 , 1 ) else : return slice ( indices [ 0 ] , indices [ 0 ] - 1 , - 1 ) if len ( indices ) >= 1 : indices = np . asarray ( indices ) if indices . dtype != bool : begin = indices [ 0 ] end = indices [ - 1 ] steps = np . diff ( indices ) if len ( indices ) > 1 else np . array ( [ 1 ] ) step = steps [ 0 ] # continuous ranges with constant step and valid start and stop index can be slices if np . all ( steps == step ) and step > 0 and begin >= 0 and end < maxlen : return slice ( begin , end + step , step ) return indices