Example #1
0
 def test_make_zero(self):
     for n, m in itertools.combinations(range(2, 10), 2):
         mat = Matrix.make_random(n, m)
         zero_right = Matrix.make_zero(m, m)
         zero_left = Matrix.make_zero(n, m)
         utils.assert_matrices_almost_equal(mat @ zero_right, zero_left)
         utils.assert_matrices_almost_equal(zero_left.T @ mat, zero_right)
Example #2
0
 def test_make_identity(self):
     for n, m in itertools.combinations(range(2, 10), 2):
         mat = Matrix.make_random(n, m)
         eye_right = Matrix.make_identity(m, m)
         eye_left = Matrix.make_identity(n, n)
         utils.assert_matrices_almost_equal(mat @ eye_right, mat)
         utils.assert_matrices_almost_equal(eye_left @ mat, mat)
Example #3
0
 def test_getitem(self):
     for mat in utils.ALL_MATRICES:
         STOP = min(mat.num_rows, mat.num_columns)
         for start in range(0, STOP):
             for stop in range(start + 1, STOP + 1):
                 for step in range(1, stop):
                     m = mat[start:stop:step, start:stop:step]
                     self.assertIsInstance(m, Matrix)
                     if m.shape == mat.shape:
                         utils.assert_matrices_almost_equal(m, mat)
Example #4
0
 def test_subtraction(self):
     for mat1, mat2 in itertools.product(utils.ALL_MATRICES,
                                         utils.ALL_MATRICES):
         if mat1.shape == mat2.shape:
             utils.assert_matrices_almost_equal(
                 mat1 - mat2, matrix_ops.subtract(mat1, mat2))
Example #5
0
 def test_negation(self):
     for mat in utils.ALL_MATRICES:
         utils.assert_matrices_almost_equal(-mat, matrix_ops.scale(mat, -1))
Example #6
0
 def test_scalar_multiply(self):
     for k, mat in itertools.product(utils.ALL_SCALARS, utils.ALL_MATRICES):
         utils.assert_matrices_almost_equal(k * mat,
                                            matrix_ops.scale(mat, k))
Example #7
0
 def test_matmul(self):
     for mat1, mat2 in itertools.product(utils.ALL_MATRICES,
                                         utils.ALL_MATRICES):
         if mat1.num_columns == mat2.num_rows:
             utils.assert_matrices_almost_equal(
                 mat1 @ mat2, matrix_ops.matrix_multiply(mat1, mat2))
Example #8
0
 def test_transpose_multiplication(self):
     for m1, m2 in itertools.product(utils.ALL_MATRICES,
                                     utils.ALL_MATRICES):
         if m1.num_columns == m2.num_rows:
             utils.assert_matrices_almost_equal((m1 @ m2).T, m2.T @ m1.T)
Example #9
0
 def test_transponse_involution(self):
     for mat in utils.ALL_MATRICES:
         utils.assert_matrices_almost_equal(mat.T.T, mat)