def random_V(d, mode='cpu'): V = np.random.uniform(0, 1, [d, d]) if mode == 'cpu': Q = np.linalg.qr(V, mode='complete')[0] return Q elif mode == 'gpu': import skcuda.linalg as LA import pycuda.gpuarray as gpuarray V = V.astype(np.float32) V_gpu = gpuarray.to_gpu(V) Q_gpu, R_gpu = LA.qr(V_gpu, mode='reduced', lib='cusolver') return Q_gpu
def test_qr_reduced_complex128(self): a = np.asarray(np.random.randn(9, 6) + 1j*np.random.randn(9, 6), np.complex64, order='F') a_gpu = gpuarray.to_gpu(a) q_gpu, r_gpu = linalg.qr(a_gpu, 'reduced') assert np.allclose(a, np.dot(q_gpu.get(), r_gpu.get()), atol=atol_float64)
def test_qr_reduced_float64(self): a = np.asarray(np.random.randn(5, 3), np.float32, order='F') a_gpu = gpuarray.to_gpu(a) q_gpu, r_gpu = linalg.qr(a_gpu, 'reduced') assert np.allclose(a, np.dot(q_gpu.get(), r_gpu.get()), atol=atol_float64)