예제 #1
0
파일: test_ir.py 프로젝트: yuriyi/devito
    def test_intervals_intersection(self):
        nullx = NullInterval(x)

        # All nulls
        assert nullx.intersection(nullx) == nullx

        nully = NullInterval(y)
        ix = Interval(x, -2, 2)
        iy = Interval(y, -2, 2)

        # Mixed nulls and defined
        assert nullx.intersection(ix) == nullx
        assert nullx.intersection(iy) == nullx
        assert nullx.intersection(iy) != nully
        assert nully.intersection(iy) == nully

        ix2 = Interval(x, -8, -3)
        ix3 = Interval(x, 3, 4)

        # All defined disjoint
        assert ix.intersection(ix2) == nullx
        assert ix.intersection(ix3) == nullx
        assert ix2.intersection(ix3) == nullx
        assert ix.intersection(iy) == nullx
        assert iy.intersection(ix) == nully

        ix4 = Interval(x, 1, 4)
        ix5 = Interval(x, -3, 0)

        # All defined overlapping
        assert ix.intersection(ix4) == Interval(x, 1, 2)
        assert ix.intersection(ix5) == Interval(x, -2, 0)
예제 #2
0
파일: test_ir.py 프로젝트: opesci/devito
    def test_intervals_intersection(self):
        nullx = NullInterval(x)

        # All nulls
        assert nullx.intersection(nullx) == nullx

        nully = NullInterval(y)
        ix = Interval(x, -2, 2)
        iy = Interval(y, -2, 2)

        # Mixed nulls and defined
        assert nullx.intersection(ix) == nullx
        assert nullx.intersection(iy) == nullx
        assert nullx.intersection(iy) != nully
        assert nully.intersection(iy) == nully

        ix2 = Interval(x, -8, -3)
        ix3 = Interval(x, 3, 4)

        # All defined disjoint
        assert ix.intersection(ix2) == nullx
        assert ix.intersection(ix3) == nullx
        assert ix2.intersection(ix3) == nullx
        assert ix.intersection(iy) == nullx
        assert iy.intersection(ix) == nully

        ix4 = Interval(x, 1, 4)
        ix5 = Interval(x, -3, 0)

        # All defined overlapping
        assert ix.intersection(ix4) == Interval(x, 1, 2)
        assert ix.intersection(ix5) == Interval(x, -2, 0)
예제 #3
0
    def test_intervals_intersection(self, x, y):
        nullx = NullInterval(x)

        # All nulls
        assert nullx.intersection(nullx) == nullx

        nully = NullInterval(y)
        ix = Interval(x, -2, 2)
        iy = Interval(y, -2, 2)

        # Mixed nulls and defined
        assert nullx.intersection(ix) == nullx
        assert nullx.intersection(iy) == nullx
        assert nullx.intersection(iy) != nully
        assert nully.intersection(iy) == nully

        ix2 = Interval(x, -8, -3)
        ix3 = Interval(x, 3, 4)

        assert ix.intersection(ix2) == Interval(x, -2, -3)
        assert ix.intersection(ix3) == Interval(x, 3, 2)
        assert ix2.intersection(ix3) == Interval(x, 3, -3)
        assert ix.intersection(iy) == nullx
        assert iy.intersection(ix) == nully

        ix4 = Interval(x, 1, 4)
        ix5 = Interval(x, -3, 0)

        assert ix.intersection(ix4) == Interval(x, 1, 2)
        assert ix.intersection(ix5) == Interval(x, -2, 0)

        # Mixed symbolic and non-symbolic
        c = Constant(name='c')
        ix6 = Interval(x, c, c + 4)
        ix7 = Interval(x, c - 1, c + 5)

        assert ix6.intersection(ix7) == Interval(x, c, c + 4)
        assert ix7.intersection(ix6) == Interval(x, c, c + 4)

        # Symbolic with properties
        s = Scalar(name='s', nonnegative=True)
        ix8 = Interval(x, s - 2, s + 2)
        ix9 = Interval(x, s - 1, s + 1)

        assert ix.intersection(ix8) == Interval(x, s - 2, 2)
        assert ix8.intersection(ix) == Interval(x, s - 2, 2)
        assert ix8.intersection(ix9) == Interval(x, s - 1, s + 1)
        assert ix9.intersection(ix8) == Interval(x, s - 1, s + 1)