예제 #1
0
 def test_diagonal_inverse_recovers_identity(self):
     M = Mat([2.0, 0.0], [0.0, 4.0])
     Minv = M.inv()
     assert Minv.__origin__ is M.__origin__
     assert type(Minv) is type(M)
     assert Minv * M == Mat([1.0, 0.0], [0.0, 1.0])
     assert M * Minv == Mat([1.0, 0.0], [0.0, 1.0])
예제 #2
0
 def test_diagonal_inverse_recovers_identity(self):
     M = Mat([2.0, 0.0], [0.0, 4.0])
     Minv = M.inv()
     assert Minv.__origin__ is M.__origin__
     assert type(Minv) is type(M)
     assert Minv * M == Mat([1.0, 0.0], [0.0, 1.0])
     assert M * Minv == Mat([1.0, 0.0], [0.0, 1.0])
예제 #3
0
    def __init__(self, matrix, vector):
        # Convert values
        if isinstance(matrix, Mat):
            matrix = matrix
        else:
            matrix = Mat(*matrix)

        # linearize inputs and save in the flat attribute
        self.shape = matrix.shape
        data = list(map(list, matrix))
        for x, L in zip(vector, data):
            L.append(x)
        self.flat = sum(data, [])
예제 #4
0
def test_withrow_matrix_middle():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [5, 6], [7, 8], [3, 4])
    M3 = M1.append_row(Mat([5, 6], [7, 8]), index=1)
    assert M2 == M3
예제 #5
0
def test_withcol_vec_middle():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 5, 2], [3, 6, 4])
    M3 = M1.append_col([5, 6], index=1)
    assert M2 == M3
예제 #6
0
def test_rows():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    assert list(M1.rows()) == [Vec(1, 2), Vec(3, 4), Vec(5, 6)]
예제 #7
0
def test_withrow_matrix():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [3, 4], [5, 6], [7, 8])
    M3 = M1.append_row(Mat([5, 6], [7, 8]))
    assert M2 == M3
예제 #8
0
def test_cols():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    assert list(M1.cols()) == [Vec(1, 3, 5), Vec(2, 4, 6)]
예제 #9
0
def test_swaprows():
    M1 = mMat([1, 2], [3, 4])
    M1.iswap_rows(0, 1)
    M2 = Mat([3, 4], [1, 2])
    assert M1 == M2
예제 #10
0
def test_withcol_vec():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2, 5], [3, 4, 6])
    M3 = M1.append_col([5, 6])
    assert M2 == M3
예제 #11
0
def test_transpose_sqr():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 3], [2, 4])
    assert M1.T == M2
    assert M1 == M2.T
예제 #12
0
def test_withrow_vec_middle():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [5, 6], [3, 4])
    M3 = M1.append_row([5, 6], index=1)
    assert M2 == M3
예제 #13
0
def test_withrow_matrix_middle():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [5, 6], [7, 8], [3, 4])
    M3 = M1.append_row(Mat([5, 6], [7, 8]), index=1)
    assert M2 == M3
예제 #14
0
def test_withrow_matrix():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [3, 4], [5, 6], [7, 8])
    M3 = M1.append_row(Mat([5, 6], [7, 8]))
    assert M2 == M3
예제 #15
0
def test_withrow_vec():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [3, 4], [5, 6])
    M3 = M1.append_row([5, 6])
    assert M2 == M3
예제 #16
0
def test_rows():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    assert list(M1.rows()) == [Vec(1, 2), Vec(3, 4), Vec(5, 6)]
예제 #17
0
def test_droppingcol():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    M2 = Mat([1], [3], [5])
    assert M1.drop_col(1) == (M2, Vec(2, 4, 6))
예제 #18
0
def test_withcol_vec_middle():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 5, 2], [3, 6, 4])
    M3 = M1.append_col([5, 6], index=1)
    assert M2 == M3
예제 #19
0
def test_selectcols():
    M1 = Mat([1, 2, 3], [4, 5, 6], [7, 8, 9])
    M2 = Mat([1, 3], [4, 6], [7, 9])
    assert M1.select_cols(0, 2) == M2
예제 #20
0
def test_droppingrow():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    M2 = Mat([1, 2], [5, 6])
    assert M1.drop_row(1) == (M2, Vec(3, 4))
예제 #21
0
def test_eig2():
    M1 = Mat([1, 0], [0, 2])
    assert M1.eigenpairs() == [(2.0, (0.0, 1.0)), (1.0, (1.0, 0.0))]
예제 #22
0
def test_droppingcol():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    M2 = Mat([1], [3], [5])
    assert M1.drop_col(1) == (M2, Vec(2, 4, 6))
예제 #23
0
def test_rowadd_sqr():
    M1 = mMat([1, 2], [3, 4])
    M1.isum_row(1, (1, 1))
    M2 = Mat([1, 2], [4, 5])
    assert M1 == M2
예제 #24
0
def test_selectrows():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    M2 = Mat([1, 2], [5, 6])
    assert M1.select_rows(0, 2) == M2
예제 #25
0
 def test_inverse_of_diagonal_matrix(self):
     M = Mat([2, 0], [0, 4])
     Minv = M.inv()
     assert Minv == Mat([0.5, 0], [0, 0.25])
예제 #26
0
def test_selectcols():
    M1 = Mat([1, 2, 3], [4, 5, 6], [7, 8, 9])
    M2 = Mat([1, 3], [4, 6], [7, 9])
    assert M1.select_cols(0, 2) == M2
예제 #27
0
def test_withrow_vec():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [3, 4], [5, 6])
    M3 = M1.append_row([5, 6])
    assert M2 == M3
예제 #28
0
def test_widthdiag():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([0, 2], [3, 0])
    assert M1.set_diag([0, 0]) == M2
    assert M1.drop_diag() == M2
예제 #29
0
def test_withrow_vec_middle():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2], [5, 6], [3, 4])
    M3 = M1.append_row([5, 6], index=1)
    assert M2 == M3
예제 #30
0
def test_eig2():
    M1 = Mat([1, 0], [0, 2])
    assert M1.eigenpairs() == [(2.0, (0.0, 1.0)),
                               (1.0, (1.0, 0.0))]
예제 #31
0
def test_withcol_vec():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([1, 2, 5], [3, 4, 6])
    M3 = M1.append_col([5, 6])
    assert M2 == M3
예제 #32
0
def test_det2():
    M1 = Mat([1, 0], [0, 2])
    M2 = Mat([1, 2], [3, 4])
    assert M1.det() == 2
    assert M2.det() == -2
예제 #33
0
def test_droppingrow():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    M2 = Mat([1, 2], [5, 6])
    assert M1.drop_row(1) == (M2, Vec(3, 4))
예제 #34
0
 def test_create_from_cols(self, M):
     cols = list(M.T)
     assert M == Mat.from_cols(cols)
예제 #35
0
def test_selectrows():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    M2 = Mat([1, 2], [5, 6])
    assert M1.select_rows(0, 2) == M2
예제 #36
0
 def test_create_from_rows(self, M):
     rows = list(M)
     assert M == Mat.from_rows(rows)
예제 #37
0
def test_transpose():
    M1 = Mat([1, 2, 3], [4, 5, 6])
    M2 = Mat([1, 4], [2, 5], [3, 6])
    assert M1.T == M2
    assert M1 == M2.T
예제 #38
0
 def test_create_from_cols(self, M):
     cols = list(M.T)
     assert M == Mat.from_cols(cols)
예제 #39
0
def test_widthdiag():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat([0, 2], [3, 0])
    assert M1.set_diag([0, 0]) == M2
    assert M1.drop_diag() == M2
예제 #40
0
def test_rowmul():
    M1 = mMat([1, 2], [3, 4])
    M1.imul_row(1, 2)
    M2 = Mat([1, 2], [6, 8])
    assert M1 == M2
예제 #41
0
def test_det2():
    M1 = Mat([1, 0], [0, 2])
    M2 = Mat([1, 2], [3, 4])
    assert M1.det() == 2
    assert M2.det() == -2
예제 #42
0
def test_fromrows_sqr():
    M1 = Mat([1, 2], [3, 4])
    M2 = Mat.from_rows([[1, 2], [3, 4]])
    assert M1 == M2
예제 #43
0
def test_colmul():
    M1 = mMat([1, 2], [3, 4])
    M1.imul_col(1, 2)
    M2 = Mat([1, 4], [3, 8])
    assert M1 == M2
예제 #44
0
def test_get_item():
    M1 = Mat([1, 2], [3, 4])
    assert M1[0] == [1, 2]
    assert M1[1] == [3, 4]
예제 #45
0
def test_coladd():
    M1 = mMat([1, 2], [3, 4])
    M1.isum_col(1, (1, 1))
    M2 = Mat([1, 3], [3, 5])
    assert M1 == M2
예제 #46
0
def test_flat2x2():
    M1 = Mat([1, 2], [3, 4])
    assert list(M1.flat) == [1, 2, 3, 4]
예제 #47
0
 def test_create_from_rows(self, M):
     rows = list(M)
     assert M == Mat.from_rows(rows)
예제 #48
0
def test_flat2x2_redo():
    M1 = Mat([1, 2], [3, 4])
    assert M1, Mat[2, 2].from_flat(M1.flat)
예제 #49
0
def test_swapcols():
    M1 = mMat([1, 2], [3, 4])
    M1.iswap_cols(0, 1)
    M2 = Mat([2, 1], [4, 3])
    assert M1 == M2
예제 #50
0
def test_cols():
    M1 = Mat([1, 2], [3, 4], [5, 6])
    assert list(M1.cols()) == [Vec(1, 3, 5), Vec(2, 4, 6)]