def test_2x2_processors_4x4_operands(self):
        nprocs = 4

        # given
        P = [self.broker.add_servant(ProcessorI(), Cannon.ProcessorPrx) for i in range(nprocs)]
        loader = self.broker.add_servant(OperationsI(P), Cannon.OperationsPrx)

        A = M4(1,  2,  3,  4,
               5,  6,  7,  8,
               9, 10, 11, 12,
              13, 14, 15, 16)

        B = M4(17, 18, 19, 20,
               21, 22, 23, 24,
               25, 26, 27, 28,
               29, 30, 31, 32)

        # when
        C = loader.matrixMultiply(A, B)

        # then
        expected = M4(250,  260,  270,  280,
                      618,  644,  670,  696,
                      986, 1028, 1070, 1112,
                     1354, 1412, 1470, 1528)

        assert_that(C, is_(expected))
Пример #2
0
    def test_load_4x4_operands_in_2x2_processors(self):
        nprocs = 4

        # given
        A = M4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

        B = M4(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)

        procs = [Spy(Cannon.Processor) for i in range(nprocs)]
        frontend = FrontendI(procs)

        # when
        frontend.load_processors(A, B)

        # then
        A_blocks = [
            M2(1, 2, 5, 6),
            M2(3, 4, 7, 8),
            M2(11, 12, 15, 16),
            M2(9, 10, 13, 14)
        ]

        B_blocks = [
            M2(17, 18, 21, 22),
            M2(27, 28, 31, 32),
            M2(25, 26, 29, 30),
            M2(19, 20, 23, 24)
        ]

        for i in range(nprocs):
            assert_that(procs[i].injectA, called().with_args(A_blocks[i], 0))
            assert_that(procs[i].injectB, called().with_args(B_blocks[i], 0))
Пример #3
0
    def test_horizontal_shift_4x4_by_blocks_2x2(self):
        # given
        original = M4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

        # when
        actual = matrix_horizontal_shift(original, block_order=2)

        # then
        expected = M4(1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 9, 10, 15, 16, 13, 14)

        assert_that(actual, is_(expected))
Пример #4
0
    def test_join_4_4x4_blocks_in_8x8_matrix(self):
        # given
        A0 = M4(1, 2, 3, 4, 9, 10, 11, 12, 17, 18, 19, 20, 25, 26, 27, 28)

        A1 = M4(5, 6, 7, 8, 13, 14, 15, 16, 21, 22, 23, 24, 29, 30, 31, 32)

        A2 = M4(33, 34, 35, 36, 41, 42, 43, 44, 49, 50, 51, 52, 57, 58, 59, 60)

        A3 = M4(37, 38, 39, 40, 45, 46, 47, 48, 53, 54, 55, 56, 61, 62, 63, 64)

        # when
        actual = matrix_join(A0, A1, A2, A3)

        # then
        expected = M8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
                      17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
                      31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
                      45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
                      59, 60, 61, 62, 63, 64)

        assert_that(actual, is_(expected))
Пример #5
0
    def test_split_8x8_in_4_blocks(self):
        # given
        original = M8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
                      17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
                      31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
                      45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
                      59, 60, 61, 62, 63, 64)

        # when
        blocks = matrix_split(original, block_order=4)

        # then
        E00 = M4(1, 2, 3, 4, 9, 10, 11, 12, 17, 18, 19, 20, 25, 26, 27, 28)

        E01 = M4(5, 6, 7, 8, 13, 14, 15, 16, 21, 22, 23, 24, 29, 30, 31, 32)

        E10 = M4(33, 34, 35, 36, 41, 42, 43, 44, 49, 50, 51, 52, 57, 58, 59,
                 60)

        E11 = M4(37, 38, 39, 40, 45, 46, 47, 48, 53, 54, 55, 56, 61, 62, 63,
                 64)

        assert_that(blocks, is_([E00, E01, E10, E11]))
Пример #6
0
    def test_order_4_blocks_2x2(self):
        # given
        collector = CollectorI(order=2)
        collector.inject(0, M2(1, 2, 5, 6))
        collector.inject(1, M2(3, 4, 7, 8))
        collector.inject(2, M2(9, 10, 13, 14))

        # when
        collector.inject(3, M2(11, 12, 15, 16))

        # then
        expected = M4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

        assert_that(collector.get_result(), is_(expected))
Пример #7
0
    def test_join_4_2x2_blocks_in_4x4_matrix(self):
        # given
        A0 = M2(1, 2, 5, 6)

        A1 = M2(3, 4, 7, 8)

        A2 = M2(9, 10, 13, 14)

        A3 = M2(11, 12, 15, 16)

        # when
        actual = matrix_join(A0, A1, A2, A3)

        # then
        expected = M4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

        assert_that(actual, is_(expected))
Пример #8
0
    def test_split_4x4_in_4_blocks(self):
        # given
        original = M4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

        # when
        actual = matrix_split(original, block_order=2)

        # then
        E00 = M2(1, 2, 5, 6)

        E01 = M2(3, 4, 7, 8)

        E10 = M2(9, 10, 13, 14)

        E11 = M2(11, 12, 15, 16)

        assert_that(actual, is_([E00, E01, E10, E11]))
Пример #9
0
    def test_order_4_blocks_2x2(self):
        # given
        collector = CollectorI(order=2)
        collector.injectSubmatrix(M2(1, 2,
                                     5, 6), 0, 0)
        collector.injectSubmatrix(M2(3, 4,
                                     7, 8), 0, 1)
        collector.injectSubmatrix(M2(9, 10,
                                    13, 14), 1, 0)

        # when
        collector.injectSubmatrix(M2(11, 12,
                                     15, 16), 1, 1)

        # then
        expected = M4(1,  2,  3,  4,
                      5,  6,  7,  8,
                      9, 10, 11, 12,
                     13, 14, 15, 16)

        assert_that(collector.get_result(), is_(expected))