Ejemplo n.º 1
0
    def test_simple(self):
        def matrix_mult_sample():
            A = Array.array([[1, 0], [0, 1]])
            B = Array.array([[1, 1], [1, 1]])
            C = dot(A, B)
            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)
Ejemplo n.º 2
0
    def test_multiple_nested(self):
        def matrix_mult_complex(A, B, C):
            return dot(dot(A, B), C)

        A = Array.rand(3, 3)
        B = Array.rand(3, 3)
        C = Array.rand(3, 3)

        expected = matrix_mult_complex(A, B, C)
        actual = dgemmify(matrix_mult_complex)(A, B, C)

        self._check(actual, expected)
Ejemplo n.º 3
0
    def test_transpose_on_call(self):

        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            C = dot(A.transpose(), B.transpose())

            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)
Ejemplo n.º 4
0
    def test_transpose_into_buffer(self):

        def matrix_mult_sample():

            B = Array.array([[10, 3], [7, 4]])

            # transposition
            A = Array.array([[1, 2], [3, 4]])
            A = Array.transpose(A)
            C = dot(B, A)
            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)
Ejemplo n.º 5
0
    def test_mid_update(self):

        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            M = Array.transpose(A)

            M = Array.array([[1, 1], [3, 0]])

            C = dot(M, B)
            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)
Ejemplo n.º 6
0
    def test_double_transpose(self):

        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            # double transposition
            M = Array.transpose(A)
            N = Array.transpose(B)

            C = dot(N, M)
            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)
Ejemplo n.º 7
0
    def test_after_update_double_in_place(self):

        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            A = Array.transpose(A)
            B = Array.transpose(B)

            C = dot(A, B)

            # the double transpose in place after the dot call
            A = Array.transpose(A)
            B = Array.transpose(B)

            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)
Ejemplo n.º 8
0
    def test_after_update_double(self):

        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            M = Array.transpose(A)
            N = Array.transpose(B)

            C = dot(M, N)

            # the double assignment after the dot call
            M = Array.array([[1, 1], [3, 0]])
            N = Array.array([[1, 0], [7, 0]])

            return C

        expected = matrix_mult_sample()
        actual = dgemmify(matrix_mult_sample)()

        self._check(actual, expected)