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

Numpy issues #33

Open
carversh opened this issue Apr 11, 2023 · 7 comments
Open

Numpy issues #33

carversh opened this issue Apr 11, 2023 · 7 comments

Comments

@carversh
Copy link

Hi I'm running the following and getting an error. It seems to be an issue with numpy although I am using version 1.22.3:

import spams
import pandas as pd
import numpy as np

# load X input (genes by droplets/cells matrix)
X = np.load('matrix.npy')

params = {
    'K' : 15, # learns a dictionary with K modules/atoms
    'lambda1' : 0.15, 
    'lambda2':0,
    'mode':2,
    'modeD': 0,
    'numThreads' : 4, 
    'batchsize' : 400, # batchsize to learn the code
    'iter' : 15,
    'verbose':True,
    # 'gamma1': # (optional parameter for modeD >= 1),
    # 'gamma2': # (optional parameter for modeD = 2),
}

# dictionary initialization
D_init = np.random.randn(X.shape[0], params['K'])
params['D'] = D_init # dictionary initialization, if None, dictionary is initialized with random elements from the training set

#(D, model) = 
#D = spams.trainDL(np.asfortranarray(X), return_model = False, **params)
#(D,model) = spams.trainDL(X, return_model = True, lambda1=0.15, **params)
(D,model) = spams.trainDL(X, return_model = True,  **params)

And getting the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/site-packages/spams/spams.py", line 2026, in trainDL
    return __allTrainDL(X, return_model, model, False, D, None, None, numThreads, 0.000001, True, False, batchsize, K, lambda1, lambda2, lambda3, iter, t0, mode, regul, posAlpha, posD, expand, modeD, whiten, clean, verbose, gamma1, gamma2, rho, iter_updateD, stochastic_deprecated, modeParam, batch, log_deprecated, logName)
  File "/site-packages/spams/spams.py", line 1868, in __allTrainDL
    x = spams_wrap.alltrainDL(
  File "/site-packages/spams_wrap/spams_wrap.py", line 313, in alltrainDL
    return _spams_wrap.alltrainDL(*args)
RuntimeError: matrix arg 10 must be a 2d double Fortran Array
@carversh
Copy link
Author

When I convert X to a fortran array, this still produces an error

@carversh
Copy link
Author

Sometimes the code runs and sometimes it doesn't

@samuelstjean
Copy link
Collaborator

I hit something similar because sometimes the type that is used is compiler, platform and python version dependent for an int type. Although here it seems caused by a float/double thing, but could be related.

@carversh
Copy link
Author

Thanks for your response. Would you mind recommending a python and numpy version that prevents this from happening?

@carversh
Copy link
Author

You recommend this:
numpy>=1.12
Pillow>=6.0
scipy>=1.0
setuptools>=46.1

But this still gives me issues

@samuelstjean
Copy link
Collaborator

Well in this case the functions are probably all overloaded, so I don't think it would happen unless you are on some strange architecture nobody else was using. I would check the dtype of your float arrays, I'm not sure you can mix float and double in the same function call for example, just one or the other type for all of your inputs.

@samuelstjean
Copy link
Collaborator

I guess this was also related to #34? If so we'll just close it since it was just a bug in how the function is called.

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

3 participants
@samuelstjean @carversh and others