How to use the pythran.interval.Interval function in pythran

To help you get started, we’ve selected a few pythran 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 serge-sans-paille / pythran / pythran / interval.py View on Github external
>>> Interval(-1, 5) <= Interval(6, 7)
        Interval(low=1, high=1)
        >>> Interval(-1, 5) <= Interval(5, 7)
        Interval(low=1, high=1)

        >>> Interval(-1, 5) <= Interval(-16, -7)
        Interval(low=0, high=0)

        >>> Interval(1, 5) <= Interval(3, 7)
        Interval(low=0, high=1)

        """
        if self.high <= other.low:
            return Interval(1, 1)
        if self.low > other.high:
            return Interval(0, 0)
        return Interval(0, 1)
github serge-sans-paille / pythran / pythran / interval.py View on Github external
def union(self, other):
        if isinstance(other, Interval):
            return UNKNOWN_RANGE
        return IntervalTuple(x.union(y) for x, y in zip(self.values,
                                                        other.values))
github serge-sans-paille / pythran / pythran / interval.py View on Github external
def cmp_values(_):
    """ Return the range of a comparison value, i.e. [-1, 1]. """
    return Interval(-1, 1)
github serge-sans-paille / pythran / pythran / interval.py View on Github external
def widen(self, other):
        """ Widen current range. """
        if self.low < other.low:
            low = -float("inf")
        else:
            low = self.low
        if self.high > other.high:
            high = float("inf")
        else:
            high = self.high
        return Interval(low, high)
github serge-sans-paille / pythran / pythran / interval.py View on Github external
def __sub__(self, other):
        """
        Combiner for Subtraction operation.

        >>> Interval(1, 5) - Interval(-5, -4)
        Interval(low=5, high=10)
        """
        sl, sh, ol, oh = self.low, self.high, other.low, other.high

        if isinf(sl) and isinf(oh):
            return UNKNOWN_RANGE
        if isinf(sh) and isinf(ol):
            return UNKNOWN_RANGE

        return Interval(sl - oh, sh - ol)
github serge-sans-paille / pythran / pythran / interval.py View on Github external
def __mod__(range1, range2):
        """ Combiner for Modulo operation.

        >>> Interval(-1, 5) % Interval(1, 13)
        Interval(low=0, high=5)
        >>> Interval(-21, 5) % Interval(1, 13)
        Interval(low=0, high=13)
        """
        return Interval(0, min(range2.high,
                               max(abs(range1.high), abs(range1.low))))
github serge-sans-paille / pythran / pythran / interval.py View on Github external
>>> Interval(-1, 5) < Interval(6, 7)
        Interval(low=1, high=1)
        >>> Interval(-1, 5) < Interval(5, 7)
        Interval(low=0, high=1)

        >>> Interval(-1, 5) < Interval(-16, -7)
        Interval(low=0, high=0)

        >>> Interval(1, 5) < Interval(3, 7)
        Interval(low=0, high=1)

        """
        if self.high < other.low:
            return Interval(1, 1)
        if self.low > other.high:
            return Interval(0, 0)
        return Interval(0, 1)
github serge-sans-paille / pythran / pythran / interval.py View on Github external
Combiner for lower than or equal operation.

        >>> Interval(-1, 5) <= Interval(6, 7)
        Interval(low=1, high=1)
        >>> Interval(-1, 5) <= Interval(5, 7)
        Interval(low=1, high=1)

        >>> Interval(-1, 5) <= Interval(-16, -7)
        Interval(low=0, high=0)

        >>> Interval(1, 5) <= Interval(3, 7)
        Interval(low=0, high=1)

        """
        if self.high <= other.low:
            return Interval(1, 1)
        if self.low > other.high:
            return Interval(0, 0)
        return Interval(0, 1)
github serge-sans-paille / pythran / pythran / interval.py View on Github external
def positive_values(_):
    """ Return a positive range without upper bound. """
    return Interval(0, float("inf"))
github serge-sans-paille / pythran / pythran / interval.py View on Github external
Combiner for greater than or equal operation.

        >>> Interval(-5, 1) >= Interval(-7, -6)
        Interval(low=1, high=1)
        >>> Interval(-5, 1) >= Interval(-7, -5)
        Interval(low=1, high=1)

        >>> Interval(-1, 5) >= Interval(6, 7)
        Interval(low=0, high=0)

        >>> Interval(1, 5) >= Interval(3, 7)
        Interval(low=0, high=1)

        """
        if self.low >= other.high:
            return Interval(1, 1)
        if self.high < other.low:
            return Interval(0, 0)
        return Interval(0, 1)