QR.conditional(QR[k, k] != 0.0, Qcompute(j, k, n, QR, Q)) return Q def get_r(QR, Rdiag): n = None # TODO: What is this supposed to be? c = QR.context() R = c.matrix(float, (n, n), 0.0) for (i, j) in getindices(n, n): if i < j: R[i, j] = QR[i, j] elif i == j: R[i, j] = Rdiag[i] return R if __name__ == "__main__": c = p.context() A = c.matrix(float, (100, 100)) p.randomize(A) QR, Rdiag = qr_decomp(A) Q = get_q(QR, Rdiag) R = get_r(QR, Rdiag) [v.write(p.stdout) for v in (QR, Rdiag, Q, R)] p.compute(c)
def get_u(LU): # m = LU.shape[0] # row n = LU.shape[1] # col c = LU.context() U = c.matrix(float, n, n) for (i, j) in zip(range(n), range(n)): if i <= j: U[i, j] = LU[i, j] else: U[i, j] = 0.0 return U if __name__ == "__main__": c = pnx.context() A = pnx.matrix(float, 100, 100) pnx.random(A) Bmat, LU = lu_decomp(A) L = get_l(LU) U = get_u(LU) [v.write(pnx.stdout) for v in [Bmat, LU, L, U]] pnx.compute(c)