Return True if values of an array are uniformly spaced and sorted.

    >>> is_uniform_spaced(range(5))
    True
    >>> is_uniform_spaced([-4, 0, 100])
    False

    kwargs are additional arguments to ``np.isclose``
540452
def is_uniform_spaced(arr, **kwargs) -> bool:
    
    arr = np.array(arr, dtype=float)
    diffs = np.diff(arr)
    return bool(np.isclose(diffs.min(), diffs.max(), **kwargs))
361105
def check_bounds(self, addr):
        
        def is_boolean_array(arr):
            return hasattr(arr, 'dtype') and arr.dtype == bool

        def check_axis(x, size):
            if isinstance(x, (int, long, numpy.integer)):
                lower = upper = x
            elif isinstance(x, slice):
                lower = x.start or 0
                upper = min(x.stop or size - 1, size - 1)  # slices are allowed to go past the bounds
            elif isinstance(x, collections.Sized):
                if is_boolean_array(x):
                    lower = 0
                    upper = x.size - 1
                else:
                    if len(x) == 0:
                        raise ValueError("Empty address component (address was %s)" % str(addr))
                    if hasattr(x, "min"):
                        lower = x.min()
                    else:
                        lower = min(x)
                    if hasattr(x, "max"):
                        upper = x.max()
                    else:
                        upper = max(x)
            else:
                raise TypeError("Invalid array address: %s (element of type %s)" % (str(addr), type(x)))
            if (lower < -size) or (upper >= size):
                raise IndexError("Index out of bounds")
        full_addr = self._full_address(addr)
        if isinstance(addr, numpy.ndarray) and addr.dtype == bool:
            if len(addr.shape) > len(self._shape):
                raise IndexError("Too many indices for array")
            for xmax, size in zip(addr.shape, self._shape):
                upper = xmax - 1
                if upper >= size:
                    raise IndexError("Index out of bounds")
        else:
            for i, size in zip(full_addr, self._shape):
                check_axis(i, size)
918860
def is_bin_subset(sub, sup) -> bool:
    
    sub = make_bin_array(sub)
    sup = make_bin_array(sup)

    for row in sub:
        if not (row == sup).all(axis=1).any():
            # TODO: Enable also approximate equality
            return False
    return True
240422
def uniform(self, key, min_value=0., max_value=1.):
        """"""
        return min_value + self._random(key) * (max_value - min_value)
339580
def _has_sorted_sa_indices(s_indices, a_indices):
    
    L = len(s_indices)
    for i in range(L-1):
        if s_indices[i] > s_indices[i+1]:
            return False
        if s_indices[i] == s_indices[i+1]:
            if a_indices[i] >= a_indices[i+1]:
                return False
    return True
20892
def _confirm_constant(a):
    """"""
    a = np.asanyarray(a)
    return np.isclose(a, 1.0).all(axis=0).any()
472253
def rand_bool(p:float, size:Optional[List[int]]=None)->BoolOrTensor:
    ""
    return uniform(0,1,size)<p
676339
def are_in_interval(s, l, r, border = 'included'):
        
        return numpy.all([IntensityRangeStandardization.is_in_interval(x, l, r, border) for x in s])
621723
def spaced_indexes(len_, n, trunc=False):
    

    if n is None:
        return np.arange(len_)
    all_indexes = np.arange(len_)
    if trunc:
        n = min(len_, n)
    if n == 0:
        return np.empty(0)
    stride = len_ // n
    try:
        indexes = all_indexes[0:-1:stride]
    except ValueError:
        raise ValueError('cannot slice list of len_=%r into n=%r parts' % (len_, n))
    return indexes
837002
def is_regular(self):
        
        if self.size <= 1:
            return False
        return numpy.isclose(numpy.diff(self.value, n=2), 0).all()
902744
def uniform(low:Number, high:Number=None, size:Optional[List[int]]=None)->FloatOrTensor:
    ""
    if high is None: high=low
    return random.uniform(low,high) if size is None else torch.FloatTensor(*listify(size)).uniform_(low,high)
147486
def _is_contiguous(positions):
    """"""
    previous = positions[0]
    for current in positions[1:]:
        if current != previous + 1:
            return False
        previous = current
    return True
898791
def safe_range(*args):
    
    rng = range(*args)
    if len(rng) > MAX_RANGE:
        raise OverflowError('range too big, maximum size for range is %d' %
                            MAX_RANGE)
    return rng
25787
def benchmark_is_constant():
    
    # WINNER!
    def is_const1(x):
        """This is the version in Pyramid 0.6.2.

        Parameters
        ----------
        x : np.ndarray
            This is the array.
        """
        return (x == x[0]).all()

    def is_const2(x):
        """This should ostensibly only take O(N) rather than O(2N) like
        its predecessor. But we'll see...

        Parameters
        ----------
        x : np.ndarray
            This is the array.
        """
        return np.unique(x).shape[0] == 1

    x = np.random.choice(np.arange(10), 1000000, replace=True)
    _do_time(is_const1, 25, x)
    _do_time(is_const2, 25, x)
853323
def is_coord_subset(subset, superset, atol=1e-8):
    
    c1 = np.array(subset)
    c2 = np.array(superset)
    is_close = np.all(np.abs(c1[:, None, :] - c2[None, :, :]) < atol, axis=-1)
    any_close = np.any(is_close, axis=-1)
    return np.all(any_close)
341757
def is_regular(self):
        

        """
        warn = False
        msg = 'The given matrix'

        # check symmetry
        if np.abs(self.A - self.A.T).sum() > 0:
            warn = True
            msg = '{} is not symmetric,'.format(msg)

        # check parallel edged
        if self.A.max(axis=None) > 1:
            warn = True
            msg = '{} has parallel edges,'.format(msg)

        # check that d is d-regular
        if np.min(self.d) != np.max(self.d):
            warn = True
            msg = '{} is not d-regular,'.format(msg)

        # check that g doesn't contain any self-loop
        if self.A.diagonal().any():
            warn = True
            msg = '{} has self loop.'.format(msg)

        if warn:
            self.logger.warning('{}.'.format(msg[:-1]))
474293
def is_array(self, data_type):
    '''
    '''

    # Split off any brackets
    data_type = data_type.split('[')[0].strip()

    return data_type.lower() in self.array_types