lebedov / scikit-cuda

Python interface to GPU-powered libraries
http://scikit-cuda.readthedocs.org/
Other
986 stars 179 forks source link

qr, svd, ... fail without a warning if matrix is not in column-major order #229

Closed mrader1248 closed 5 years ago

mrader1248 commented 6 years ago

Several functions like qr, svd, ... from linalg require the matrix to be in column-major order. I am not sure if it is desirable that these functions fail silently if this is not the case. Wouldn't it be better if either the matrices are converted implicitly or at least something like a ValueError is raised?

nmerrill67 commented 6 years ago

From linalg.py line 393:

Since CUDA assumes that arrays are stored in column-major format, the input matrix is assumed to be transposed:

All cublas functions assume a fortran-ordered array. SVD simply assumes a transposed input matrix to remedy this. However, it may be nice to issue at least a warning, as the default pycuda gpu array is c-ordered.

lebedov commented 5 years ago

Since skcuda doesn't require that GPUArray arguments be created with order='F', I don't wish to generate extra warnings when they are C-ordered.

liaocs2008 commented 5 years ago

Hi, I tried to run the svd test as you indicate in the tutorial (https://scikit-cuda.readthedocs.io/en/latest/generated/skcuda.linalg.svd.html):

a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6) a = np.asarray(a, np.complex64) a_gpu = gpuarray.to_gpu(a) u_gpu, s_gpu, vh_gpu = linalg.svd(a_gpu, 'S', 'S') res = np.dot(vh_gpu.T.get(), np.dot(np.diag(s_gpu.get()), u_gpu.T.get())) np.allclose(a, res, 1e-4)

However it fails as following and seems related to this topic.

ValueError: CUSOLVER only supports a_gpu.shape[1] >= a_gpu.shape[0]

Could you help me with how to run a SVD example? My pycuda and skcuda versions are:

pycuda 2018.1.1 scikit-cuda 0.5.2

Thanks!

lebedov commented 5 years ago

@liaocs2008 As per NVIDIA's documentation for the CUSOLVER svd implementation, certain matrix shape are not supported by CUSOLVER (try decomposing a matrix with shape 6 x 9 and compare a to res.T). CULA does support decomposition of such shapes, but it is no longer easily obtainable.

Please open a new issue rather than appending comments to an existing one (especially if the latter has been closed) if you are not the original reporter.