lmcinnes / umap

Uniform Manifold Approximation and Projection
BSD 3-Clause "New" or "Revised" License
7.44k stars 808 forks source link

"No conversion from array(float64, 2d, A) to array(float32, 2d, C) for 'knn_dists'" when calling .transform() in 0.4.0rc1 #324

Closed aparrish closed 4 years ago

aparrish commented 4 years ago

After installing umap-learn from (what looked to me like) the dev branch like so:

pip install https://github.com/lmcinnes/umap/archive/0.4dev.zip

I get a weird error apparently about the data type of some internal value. Example code with stack trace included below.

This code works fine for me (in the same environment) with 0.3.10 installed instead. Strangely, it also works when I install the 0.4dev_fix#306 branch (with the pip/github zip method mentioned above). But I couldn't decipher from looking at the compare interface if 0.4dev_fix#306 is actually newer than 0.4dev?

>>> import numpy as np
>>> import umap
>>> X = np.random.uniform(size=(10000, 100))
>>> mapper = umap.UMAP().fit(X)
>>> mapper.transform(X[:10])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/allison/tmp/umap-testing/env3/lib/python3.7/site-packages/umap/umap_.py", line 1972, in transform
    rows, cols, vals = compute_membership_strengths(indices, dists, sigmas, rhos)
  File "/Users/allison/tmp/umap-testing/env3/lib/python3.7/site-packages/numba/dispatcher.py", line 401, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/Users/allison/tmp/umap-testing/env3/lib/python3.7/site-packages/numba/dispatcher.py", line 344, in error_rewrite
    reraise(type(e), e, None)
  File "/Users/allison/tmp/umap-testing/env3/lib/python3.7/site-packages/numba/six.py", line 668, in reraise
    raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No conversion from array(float64, 2d, A) to array(float32, 2d, C) for 'knn_dists', defined at None

File "env3/lib/python3.7/site-packages/umap/umap_.py", line 440:
def compute_membership_strengths(knn_indices, knn_dists, sigmas, rhos):
    <source elided>
    """
    n_samples = knn_indices.shape[0]
    ^

This is in a fresh Python 3.7.0 venv (MacOS 10.14.6). My pip list:

Package      Version 
------------ --------
joblib       0.14.1  
llvmlite     0.30.0  
numba        0.46.0  
numpy        1.17.4  
pip          10.0.1  
scikit-learn 0.22    
scipy        1.3.3   
setuptools   39.0.1  
tbb          2019.0  
umap-learn   0.4.0rc1
lmcinnes commented 4 years ago

This is due to some signatures that got added recently for the numba compilation. This shouldn't be too hard to fix, and I'll try to get it done soon. Thanks for the report; I definitely missed this one. Sorry.

lmcinnes commented 4 years ago

It should work now if you rebuild from master. Let me know if this fixes the issue for you.

aparrish commented 4 years ago

Didn't fix it for me, unfortunately :( I took the liberty of poking in the code and making a pull request on 0.4dev which seems to work for me—see #327. (Disclaimer: I know my way around Python code but have no idea how any of the math in here works, so I'm not 100% sure that I didn't break anything!)

lmcinnes commented 4 years ago

I see you fixed it yourself. Thanks for that! It works fine (and there are tests that happily check that things still work). I'm definitely happy to have people who know their way around Python code working on this, so please feel welcome make more PRs.