QR STEP2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def qr_step2(A):
m, rank = A.shape
Q = np.identity(m)
M = A[rank - 1:, :]
n = M.shape[0]
for j in xrange(rank):
for i in xrange(n - 1, 0, -1):
givens2 = givens_2(M[0, j], M[i, j])
giv = givens(m, 0 + rank - 1, i + rank - 1, M[0, j], M[i, j])
M[[0, i], j:rank] = dot(givens2, M[[0, i], j:rank])
Q = dot(Q, giv)
return A[:rank, :rank].T, Q