Exemplo n.º 1
0
 def test_dot(d1, d2, d3):
     print "testing dot with d1 = " + str(d1) + ", d2 = " + str(d2) + ", d3 = " + str(d3)
     a = dist.random_normal([d1, d2])
     b = dist.random_normal([d2, d3])
     c = dist.dot(a, b)
     a_val = a.assemble()
     b_val = b.assemble()
     c_val = c.assemble()
     np.testing.assert_allclose(np.dot(a_val, b_val), c_val)
Exemplo n.º 2
0
 def test_dot(d1, d2, d3):
     print "testing dot with d1 = " + str(d1) + ", d2 = " + str(
         d2) + ", d3 = " + str(d3)
     a = dist.random_normal([d1, d2])
     b = dist.random_normal([d2, d3])
     c = dist.dot(a, b)
     a_val = a.assemble()
     b_val = b.assemble()
     c_val = c.assemble()
     np.testing.assert_allclose(np.dot(a_val, b_val), c_val)
Exemplo n.º 3
0
 def test_tsqr(d1, d2):
     print "testing tsqr with d1 = " + str(d1) + ", d2 = " + str(d2)
     a = dist.random_normal([d1, d2])
     q, r = dist.tsqr(a)
     a_val = a.assemble()
     q_val = q.assemble()
     np.testing.assert_allclose(np.dot(q_val, r), a_val) # check that a = q * r
     np.testing.assert_allclose(np.dot(q_val.T, q_val), np.eye(min(d1, d2)), atol=1e-6) # check that q.T * q = I
     np.testing.assert_allclose(np.triu(r), r) # check that r is upper triangular
Exemplo n.º 4
0
 def test_tsqr_hr(d1, d2):
     print "testing tsqr_hr with d1 = " + str(d1) + ", d2 = " + str(d2)
     a = dist.random_normal([d1, d2])
     a_val = a.assemble()
     y, t, y_top, r = dist.tsqr_hr(a)
     tall_eye = np.zeros((d1, min(d1, d2)))
     np.fill_diagonal(tall_eye, 1)
     q = tall_eye - np.dot(y, np.dot(t, y_top.T))
     np.testing.assert_allclose(np.dot(q.T, q), np.eye(min(d1, d2)), atol=1e-6) # check that q.T * q = I
     np.testing.assert_allclose(np.dot(q, r), a_val) # check that a = (I - y * t * y_top.T) * r
Exemplo n.º 5
0
 def test_tsqr_hr(d1, d2):
     print "testing tsqr_hr with d1 = " + str(d1) + ", d2 = " + str(d2)
     a = dist.random_normal([d1, d2])
     a_val = a.assemble()
     y, t, y_top, r = dist.tsqr_hr(a)
     tall_eye = np.zeros((d1, min(d1, d2)))
     np.fill_diagonal(tall_eye, 1)
     q = tall_eye - np.dot(y, np.dot(t, y_top.T))
     np.testing.assert_allclose(np.dot(q.T, q),
                                np.eye(min(d1, d2)),
                                atol=1e-6)  # check that q.T * q = I
     np.testing.assert_allclose(np.dot(
         q, r), a_val)  # check that a = (I - y * t * y_top.T) * r
Exemplo n.º 6
0
 def test_tsqr(d1, d2):
     print "testing tsqr with d1 = " + str(d1) + ", d2 = " + str(d2)
     a = dist.random_normal([d1, d2])
     q, r = dist.tsqr(a)
     a_val = a.assemble()
     q_val = q.assemble()
     np.testing.assert_allclose(np.dot(q_val, r),
                                a_val)  # check that a = q * r
     np.testing.assert_allclose(np.dot(q_val.T, q_val),
                                np.eye(min(d1, d2)),
                                atol=1e-6)  # check that q.T * q = I
     np.testing.assert_allclose(np.triu(r),
                                r)  # check that r is upper triangular
Exemplo n.º 7
0
 def test_qr(d1, d2):
     print "testing qr with d1 = " + str(d1) + ", d2 = " + str(d2)
     a = dist.random_normal([d1, d2])
     a_val = a.assemble()
     Ts, y_res, r_res = dist.qr(a)
     r_val = r_res.assemble()
     y_val = y_res.assemble()
     q = np.eye(d1)
     for i in range(min(a.num_blocks[0], a.num_blocks[1])):
         q = np.dot(q, np.eye(d1) - np.dot(y_val[:, (i * 10):((i + 1) * 10)], np.dot(Ts[i], y_val[:, (i * 10):((i + 1) * 10)].T)))
     q = q[:, :min(d1, d2)]
     np.testing.assert_allclose(np.triu(r_val), r_val) # check that r is upper triangular
     np.testing.assert_allclose(np.dot(q.T, q), np.eye(min(d1, d2)), atol=1e-6) # check that q.T * q = I
     np.testing.assert_allclose(np.dot(q, r_val), a_val) # check that a = q * r
Exemplo n.º 8
0
 def test_qr(d1, d2):
     print "testing qr with d1 = " + str(d1) + ", d2 = " + str(d2)
     a = dist.random_normal([d1, d2])
     a_val = a.assemble()
     Ts, y_res, r_res = dist.qr(a)
     r_val = r_res.assemble()
     y_val = y_res.assemble()
     q = np.eye(d1)
     for i in range(min(a.num_blocks[0], a.num_blocks[1])):
         q = np.dot(
             q,
             np.eye(d1) -
             np.dot(y_val[:, (i * 10):((i + 1) * 10)],
                    np.dot(Ts[i], y_val[:, (i * 10):((i + 1) * 10)].T)))
     q = q[:, :min(d1, d2)]
     np.testing.assert_allclose(np.triu(r_val),
                                r_val)  # check that r is upper triangular
     np.testing.assert_allclose(np.dot(q.T, q),
                                np.eye(min(d1, d2)),
                                atol=1e-6)  # check that q.T * q = I
     np.testing.assert_allclose(np.dot(q, r_val),
                                a_val)  # check that a = q * r