示例#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)]