def test_lu_arbitrary(self):
     a_sym = tests.generate_pos_dif(1000, -1000, 1000)
     assert_array_almost_equal(lu_block_slow.lu_block(a_sym, 42)[0], sp.lu(a_sym)[1], decimal=12)
     assert_array_almost_equal(lu_block_slow.lu_block(a_sym, 42)[1], sp.lu(a_sym)[2], decimal=8)
Example #2
0
    U = np.zeros((m, m))
    for k in range(0, m, r):
        PLU = lu_partial(A[k:, k:k+r])
        small_P = PLU[0]
        small_P_t = invert_array(small_P)
        P[k:] = permute_array(small_P, P[k:])
        L[k:, k:k+r] = PLU[1]
        U[k:k+r, k:k+r] = PLU[2][:r, :r]
        L[k:, :k] = permute_rows(small_P_t, L[k:, :k])
        A[k:, k:] = permute_rows(small_P_t, A[k:, k:])
        U[k:k+r, k+r:] = row_substitution(L[k:k+r, k:k+r], A[k:k+r, k+r:])
        A[k+r:, k+r:] -= np.dot(L[k+r:, k:k+r], U[k:k+r, k+r:])
    return P_to_Pmatrix(P), L, U

rand_int_matrix = np.random.randint(-1000, 1000, size=(6, 6))
a_sym = tests.generate_pos_dif(4, -1000, 1000)
#print sp.lu(rand_int_matrix[:, 2:])[0]
#print sp.lu(rand_int_matrix[2:, :])[0]

matrix = np.array([[-874, -965, 18, -71],
                   [230, -457, -817, -508],
                   [570, -781, -109, -751],
                   [-4, -497, -630, 230]])

matrix2 = np.array([[11, 12, 13, 14],
                    [21, 22, 23, 24],
                    [31, 32, 33, 34],
                    [41, 42, 43, 44]])

plal = np.array([[0, 1, 0, 0],
                 [0, 0, 0, 1],