Esempio n. 1
0
def test_backward_sub():
    q, r, s = map(lambda x: Tensor(x, rank=1), 'qrs')
    s_t = Transpose(s)
    delta = Tensor('delta', rank=0)
    eqn1 = r - s - q * delta
    eqn2 = s_t * r
    sol_dict, failed_var = backward_sub([eqn1, eqn2], [q, s], [r, delta])

    print sol_dict, failed_var

    sol_dict, failed_var = backward_sub([eqn1, eqn2], [q, s], [delta, r])
    print sol_dict, failed_var
Esempio n. 2
0
def test_backward_sub():
    q, r, s = map(lambda x: Tensor(x, rank=1), 'qrs')
    s_t = Transpose(s)
    delta = Tensor('delta', rank=0)
    eqn1 = r - s - q * delta
    eqn2 = s_t * r
    sol_dict, failed_var = backward_sub([eqn1, eqn2], [q, s], [r, delta])

    print sol_dict, failed_var

    sol_dict, failed_var = backward_sub([eqn1, eqn2], [q, s], [delta, r])
    print sol_dict, failed_var
Esempio n. 3
0
def test_overdetermined_back_sub():
    pi_1, pi_2, mu_12 = \
        map(lambda x: Tensor(x, rank=0),
            ['pi_1', 'pi_2', 'mu_12'])
    r_2, p_1, p_2 = \
        map(lambda x: Tensor(x, rank=1),
            ['r_2', 'p_1', 'p_2'])
    A = Tensor('A', rank=2)

    eqns = [ pi_2 - T(r_2) * A * r_2 + T(mu_12) * pi_1 * mu_12,
             p_2 - r_2 + p_1 * mu_12,
             pi_2 - T(p_2) * A * p_2,
            ]
    return backward_sub(eqns, [r_2, p_1, mu_12, A, pi_1], multiple_sols=True)
Esempio n. 4
0
def test_overdetermined_back_sub():
    pi_1, pi_2, mu_12 = \
        map(lambda x: Tensor(x, rank=0),
            ['pi_1', 'pi_2', 'mu_12'])
    r_2, p_1, p_2 = \
        map(lambda x: Tensor(x, rank=1),
            ['r_2', 'p_1', 'p_2'])
    A = Tensor('A', rank=2)

    eqns = [
        pi_2 - T(r_2) * A * r_2 + T(mu_12) * pi_1 * mu_12,
        p_2 - r_2 + p_1 * mu_12,
        pi_2 - T(p_2) * A * p_2,
    ]
    return backward_sub(eqns, [r_2, p_1, mu_12, A, pi_1], multiple_sols=True)
Esempio n. 5
0
def cg_demo_eqns():
    D_00, J_00, I_00, U_00, X_0 = map(lambda x: Tensor(x, rank=2),
                                      ["D_00", "J_00", "I_00", "U_00", "X_0"])
    j_10, u_01, u_02 = map(lambda x: Tensor(x, rank=1),
                           ["j_10", "u_01", "u_02"])
    delta_11, su_12 = map(lambda x: Tensor(x, rank=0), ["delta_11", "su_12"])
    cg_2 = [ \
          r_1 * T(j_10) - R_0 * (-J_00 + I_00) + A * P_0 * D_00,
          - r_1 - r_2 + delta_11 * A * p_1,
          P_0 * D_00 + x_1 * T(j_10) - X_0 * (-J_00 + I_00),
          - x_1 - x_2 + delta_11 * p_1,
          - R_0 + P_0 * (-U_00 + I_00),
          - r_1 - P_0 * u_01 + p_1,
          - r_2 - P_0 * u_02 - su_12 * p_1 + p_2,
          T(R_0) * r_2,
          (T(r_1) * r_2),
          T(r_2) * R_0,
          (T(r_2) * r_1),
          T(P_0) * A * p_2,
          (T(p_1) * A * p_2),
          - R_0 * (-J_00 + I_00) - r_1 * T(j_10) + A * P_0 * D_00,
          P_0 * D_00 - X_0 * (-J_00 + I_00) - x_1 * T(j_10),
          - R_0 + P_0 * (-U_00 + I_00),
          - r_1 - P_0 * u_01 + p_1,
          T(R_0) * r_1,
          T(r_1) * R_0,
          T(P_0) * A * p_1,
            ]
    cg_2 = [ \
            r_1 * T(j_10) - R_0 * (-J_00 + I_00) + A * P_0 * D_00,
    - r_1 - r_2 + delta_11 * A * p_1,
    P_0 * D_00 + x_1 * T(j_10) - X_0 * (-J_00 + I_00),
    - x_1 - x_2 + delta_11 * p_1,
    - R_0 + P_0 * (-U_00 + I_00),
    - r_1 - P_0 * u_01 + p_1,
    - r_2 - P_0 * u_02 - su_12 * p_1 + p_2,
    T(R_0) * r_2,
    (T(r_1) * r_2),
    T(r_2) * R_0,
    (T(r_2) * r_1),
    T(P_0) * A * p_2,
    (T(p_1) * A * p_2),
    - R_0 * (-J_00 + I_00) - r_1 * T(j_10) + A * P_0 * D_00,
    P_0 * D_00 - X_0 * (-J_00 + I_00) - x_1 * T(j_10),
    - R_0 + P_0 * (-U_00 + I_00),
    - r_1 - P_0 * u_01 + p_1,
    T(R_0) * r_1,
    T(r_1) * R_0,
    T(P_0) * A * p_1,
            ]
    knowns = set(
        [U_00, p_1, X_0, u_01, x_1, I_00, j_10, D_00, R_0, r_1, A, P_0, J_00])
    unknowns = [p_2, su_12, u_02, x_2, r_2, delta_11]
    unknowns1 = [r_2, delta_11, p_2, su_12, x_2, u_02]
    unknowns2 = [p_2, su_12, r_2, delta_11, x_2, u_02]
    print("Solving for CG-Demo updates.")
    #    sols = all_back_sub(cg_2, knowns, levels= -1)
    #    print "solve_vec_eqn(T(P_0)*A*r_2 + T(P_0)*A*P_0*u_02, u_02)"
    #    print solve_vec_eqn(T(P_0) * A * r_2 + T(P_0) * A * P_0 * u_02, u_02)
    #    print_sols(sols)
    sol = backward_sub(cg_2, knowns, unknowns1, False, False)
    print "Sol:", pprint.pformat(sol)
Esempio n. 6
0
def test_cyclic_solve():
    a, b = map(lambda x: Tensor(x, rank=0), 'ab')
    assert (backward_sub([a + b], [], [a, b]) == (None, b))
Esempio n. 7
0
def test_cyclic_solve ():
    a, b = map(lambda x: Tensor(x, rank=0), 'ab')
    assert(backward_sub([a + b], [], [a, b]) == (None, b))
Esempio n. 8
0
def cg_demo_eqns ():
    D_00, J_00, I_00, U_00, X_0 = map(lambda x: Tensor(x, rank=2),
                           ["D_00", "J_00", "I_00", "U_00", "X_0"])
    j_10, u_01, u_02 = map(lambda x: Tensor(x, rank=1),
                           ["j_10", "u_01", "u_02"])
    delta_11, su_12 = map(lambda x: Tensor(x, rank=0),
                          ["delta_11", "su_12"])
    cg_2 = [ \
          r_1 * T(j_10) - R_0 * (-J_00 + I_00) + A * P_0 * D_00,
          - r_1 - r_2 + delta_11 * A * p_1,
          P_0 * D_00 + x_1 * T(j_10) - X_0 * (-J_00 + I_00),
          - x_1 - x_2 + delta_11 * p_1,
          - R_0 + P_0 * (-U_00 + I_00),
          - r_1 - P_0 * u_01 + p_1,
          - r_2 - P_0 * u_02 - su_12 * p_1 + p_2,
          T(R_0) * r_2,
          (T(r_1) * r_2),
          T(r_2) * R_0,
          (T(r_2) * r_1),
          T(P_0) * A * p_2,
          (T(p_1) * A * p_2),
          - R_0 * (-J_00 + I_00) - r_1 * T(j_10) + A * P_0 * D_00,
          P_0 * D_00 - X_0 * (-J_00 + I_00) - x_1 * T(j_10),
          - R_0 + P_0 * (-U_00 + I_00),
          - r_1 - P_0 * u_01 + p_1,
          T(R_0) * r_1,
          T(r_1) * R_0,
          T(P_0) * A * p_1,
            ]
    cg_2 = [ \
            r_1 * T(j_10) - R_0 * (-J_00 + I_00) + A * P_0 * D_00,
    - r_1 - r_2 + delta_11 * A * p_1,
    P_0 * D_00 + x_1 * T(j_10) - X_0 * (-J_00 + I_00),
    - x_1 - x_2 + delta_11 * p_1,
    - R_0 + P_0 * (-U_00 + I_00),
    - r_1 - P_0 * u_01 + p_1,
    - r_2 - P_0 * u_02 - su_12 * p_1 + p_2,
    T(R_0) * r_2,
    (T(r_1) * r_2),
    T(r_2) * R_0,
    (T(r_2) * r_1),
    T(P_0) * A * p_2,
    (T(p_1) * A * p_2),
    - R_0 * (-J_00 + I_00) - r_1 * T(j_10) + A * P_0 * D_00,
    P_0 * D_00 - X_0 * (-J_00 + I_00) - x_1 * T(j_10),
    - R_0 + P_0 * (-U_00 + I_00),
    - r_1 - P_0 * u_01 + p_1,
    T(R_0) * r_1,
    T(r_1) * R_0,
    T(P_0) * A * p_1,
            ]
    knowns = set([U_00, p_1, X_0, u_01, x_1, I_00, j_10, D_00, R_0, r_1, A,
                  P_0, J_00 ])
    unknowns = [p_2, su_12, u_02, x_2, r_2, delta_11]
    unknowns1 = [r_2, delta_11, p_2, su_12, x_2, u_02]
    unknowns2 = [p_2, su_12, r_2, delta_11, x_2, u_02]
    print("Solving for CG-Demo updates.")
#    sols = all_back_sub(cg_2, knowns, levels= -1)
#    print "solve_vec_eqn(T(P_0)*A*r_2 + T(P_0)*A*P_0*u_02, u_02)"
#    print solve_vec_eqn(T(P_0) * A * r_2 + T(P_0) * A * P_0 * u_02, u_02)
#    print_sols(sols)
    sol = backward_sub(cg_2, knowns, unknowns1, False, False)
    print "Sol:", pprint.pformat(sol)