Ejemplo n.º 1
0
    def test_rel2abs_folded(self):
        ''' Get rel2abs with folded. '''
        nr = NodeRegion(dim=PhyDim2(4, 8),
                        origin=PhyDim2(1, 3),
                        type=NodeRegion.PROC,
                        wtot=3)
        # 67
        # 543
        # 012

        self.assertTupleEqual(nr.rel2abs(PhyDim2(1, 2)), (1 + 1, 5))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(2, 3)), (5 + 2, 5))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(0, 5)), (5 + 0, 3))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(3, 7)), (9 + 3, 4))

        self.assertSetEqual(
            set(
                nr.rel2abs(PhyDim2(h, w)) for h in range(nr.dim.h)
                for w in range(nr.dim.w)), set(nr.iter_node()))

        nr = NodeRegion(dim=PhyDim2(4, 8),
                        origin=PhyDim2(1, 3),
                        type=NodeRegion.PROC,
                        wtot=3,
                        wbeg=1)
        #   7
        # 456
        # 321
        #   0

        self.assertTupleEqual(nr.rel2abs(PhyDim2(2, 0)), (1 + 2, 3))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(1, 2)), (5 + 1, 2))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(2, 3)), (5 + 2, 1))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(0, 5)), (9 + 0, 2))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(3, 7)), (13 + 3, 3))

        self.assertSetEqual(
            set(
                nr.rel2abs(PhyDim2(h, w)) for h in range(nr.dim.h)
                for w in range(nr.dim.w)), set(nr.iter_node()))

        nr = NodeRegion(dim=PhyDim2(4, 8),
                        origin=PhyDim2(1, 3),
                        type=NodeRegion.PROC,
                        wtot=4,
                        wbeg=-2)
        #   76
        # 2345
        # 10

        self.assertTupleEqual(nr.rel2abs(PhyDim2(1, 1)), (1 + 1, 2))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(2, 3)), (5 + 2, 3))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(0, 5)), (5 + 0, 5))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(3, 7)), (9 + 3, 4))

        self.assertSetEqual(
            set(
                nr.rel2abs(PhyDim2(h, w)) for h in range(nr.dim.h)
                for w in range(nr.dim.w)), set(nr.iter_node()))
Ejemplo n.º 2
0
 def test_iter_node(self):
     ''' Get node iterator. '''
     nr = NodeRegion(dim=PhyDim2(4, 4),
                     origin=PhyDim2(1, 3),
                     type=NodeRegion.PROC)
     # No duplicates.
     self.assertEqual(len(set(nr.iter_node())), nr.dim.size())
     # All nodes is contained.
     for c in nr.iter_node():
         self.assertTrue(nr.contains_node(c))
Ejemplo n.º 3
0
    def test_rel2abs(self):
        ''' Get rel2abs. '''
        nr = NodeRegion(dim=PhyDim2(4, 4),
                        origin=PhyDim2(1, 3),
                        type=NodeRegion.PROC)

        self.assertTupleEqual(nr.rel2abs(PhyDim2(0, 3)), (1, 6))
        self.assertTupleEqual(nr.rel2abs(PhyDim2(2, 1)), (3, 4))

        self.assertSetEqual(
            set(
                nr.rel2abs(PhyDim2(h, w)) for h in range(nr.dim.h)
                for w in range(nr.dim.w)), set(nr.iter_node()))