Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error replicating the PCA example in Docs #305

Open
Feulo opened this issue Aug 5, 2020 · 1 comment
Open

Error replicating the PCA example in Docs #305

Feulo opened this issue Aug 5, 2020 · 1 comment

Comments

@Feulo
Copy link

Feulo commented Aug 5, 2020

Problem

I'm trying to replicate the PCA example in docs with the following code:

import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np
import skcuda.linalg as linalg
from skcuda.linalg import PCA as cuPCA
pca = cuPCA(n_components=4) # map the data to 4 dimensions
X = np.random.rand(1000,100) # 1000 samples of 100-dimensional data vectors
X_gpu = gpuarray.GPUArray((1000,100), np.float64) # note that order="F" or a transpose is necessary. fit_transform requires row-major matrices, and column-major is the default
X_gpu.set(X) # copy data to gpu
T_gpu = pca.fit_transform(X_gpu) # calculate the principal components
linalg.dot(T_gpu[:,0], T_gpu[:,1]) # show that the resulting eigenvectors are orthogonal

But I get the error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-aa2d786e8368> in <module>
      8 X_gpu = gpuarray.GPUArray((1000,100), np.float64, order="F") # note that order="F" or a transpose is necessary. fit_transform requires row-major matrices, and column-major is the default
      9 X_gpu.set(X) # copy data to gpu
---> 10 T_gpu = pca.fit_transform(X_gpu) # calculate the principal components
     11 linalg.dot(T_gpu[:,0], T_gpu[:,1]) # show that the resulting eigenvectors are orthogonal

/opt/conda/lib/python3.6/site-packages/scikit_cuda-0.5.4-py3.6.egg/skcuda/linalg.py in fit_transform(self, X_gpu, transposed_input)
    166             raise ValueError("Array must be 2D for PCA")
    167         if X_gpu.flags.f_contiguous:
--> 168             raise ValueError("Array must be c_contiguous. Please do NOT instantiate with "
    169                              "'order=\"F\"'")
    170         if transposed_input:

ValueError: Array must be c_contiguous. Please do NOT instantiate with 'order="F"'

And if I remove de order='F', the two vector are not orthogonal, the inner procdict result is always not zero.

Environment

  • OS platform: nvidia docker image (ubuntu 18.04) running on ubutu 18.04
  • Python version: Python 3.6.9 :: Anaconda, Inc.
  • CUDA version: 10.2
  • PyCUDA version: 2019.1.2
  • scikit-cuda version: 0.5.4 (cloned august 05, 2020)
@HarleyAppleChoi
Copy link

I get the same problem with google colab with the following spec:

!nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Wed_Jul_22_19:09:09_PDT_2020
Cuda compilation tools, release 11.0, V11.0.221
Build cuda_11.0_bu.TC445_37.28845127_0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants