def tsqr_hr(a): """Algorithm 6 from http://www.eecs.berkeley.edu/Pubs/TechRpts/2013/EECS-2013-175.pdf""" q, r_temp = tsqr(a) y, u, s = single.modified_lu(assemble(q)) s_full = np.diag(s) b = q.shape[1] y_top = y[:b, :b] t = -1 * np.dot(u, np.dot(s_full, np.linalg.inv(y_top).T)) r = np.dot(s_full, r_temp) return y, t, y_top, r
def test_modified_lu(d1, d2): print "testing modified_lu with d1 = " + str(d1) + ", d2 = " + str(d2) assert d1 >= d2 k = min(d1, d2) m = np.random.normal(size=(d1, d2)) q, r = np.linalg.qr(m) l, u, s = single.modified_lu(q) s_mat = np.zeros((d1, d2)) for i in range(len(s)): s_mat[i, i] = s[i] np.testing.assert_allclose(q - s_mat, np.dot(l, u)) # check that q - s = l * u np.testing.assert_allclose(np.triu(u), u) # check that u is upper triangular np.testing.assert_allclose(np.tril(l), l) # check that u is lower triangular