def test_solve_multi_reduce(self): A = np.random.randn(100, 60) b = np.random.randn(100, 10) actual = QR(A, reduce=True).solve(b) expected = LA.lstsq(A, b, rcond=None)[0] self.assertTrue(np.allclose(actual, expected))
def test_solve_single_complete(self): A = np.random.randn(100, 60) b = np.random.randn(100) actual = QR(A, reduce=False).solve(b) expected = LA.lstsq(A, b, rcond=None)[0] self.assertTrue(np.allclose(actual, expected))
def test_householder_reduce(self): T = np.random.randn(100, 60) actual = QR(T, reduce=True).householder() expected = LA.qr(T, mode='reduced') self.assertTrue(np.allclose(actual[0]@actual[1], T)) self.assertTrue(all(np.allclose(a, e) for a, e in zip(actual, expected)))
def test_gram_schmidt_modified(self): T = np.random.randn(100, 60) actual = QR(T).gram_schmidt_modified() # enforce uniqueness for numpy version Q, R = LA.qr(T) D = create_diag(np.sign(diag(R))) Q = np.dot(Q, D) R = np.dot(D, R) expected = (Q, R) self.assertTrue(all(np.allclose(a, e) for a, e in zip(actual, expected)))
def test_householder_symmetric(self): T = np.random.randn(10, 10) Q, R = QR(T, reduce=False).householder() self.assertTrue(np.allclose(Q @ R, T))