def test_produit_house_matrix(epsilon):
    n = rd.randint(2,20)
    m = rd.randint(2,20)
    result = p1.generate_x_y(n)
    H = p1.determine_H (result[0],result[1])
    U = p1.determine_U (result[0],result[1])
    M = np.asmatrix(np.random.rand(n,m))
    M = 100 * M
    assert (np.allclose(p1.produit_house_matrix(U,M),H*M))
def forme_bidiagonale(A):
    taille = A.shape
    BD = A
    Qleft = np.asmatrix(np.eye(taille[0]))
    Qright = np.asmatrix(np.eye(taille[1]))
    l = taille[1]
    if (taille[0]<taille[1]):
        l = taille[0]
    for k in range (l):
        Q = determine_Q_k(BD[:,k],taille[0],k)
        BD = p1.produit_house_matrix (Q, BD)
        Qleft = p1.produit_house_matrix(Q,Qleft.T)
        Qleft = Qleft.T
        if k < (taille[1] - 2):
            P = determine_Q_k(BD[k,:].T,taille[1],k+1)
            BD = p1.produit_house_matrix(P, BD.T)
            BD = BD.T
            Qright = p1.produit_house_matrix(P,Qright)
    return (Qleft, BD, Qright)
def compare_time_produit_h(n):
    prod_h = np.asmatrix(np.zeros([n-2,1]))
    prod = np.asmatrix(np.zeros([n-2,1]))
    for i in range(0,n-2):
        result = p1.generate_x_y(i+2)
        H = p1.determine_H (result[0],result[1])
        U = p1.determine_U (result[0],result[1])
        M = np.asmatrix(np.random.rand((i+2),(i+2)))
        M = 100 * M
        start_time = time.time()
        A = p1.produit_house_matrix(U,M)
        prod_h[i] = time.time() - start_time
        start_time = time.time()
        A = H*M
        prod[i] = time.time() - start_time
    mp.plot(range(2,n),prod)
    PH = ["produit matrice Householder","produit matrice numpy"]
    mp.plot(range(2,n),prod_h)
    mp.legend(PH)
    pl.show()