facebookresearch / pysparnn

Approximate Nearest Neighbor Search for Sparse Data in Python!
Other
915 stars 146 forks source link

AttributeError: 'matrix' object has no attribute 'toarray' #8

Closed bhoomit closed 7 years ago

bhoomit commented 7 years ago
Traceback (most recent call last):
  File "/Users/Bhoomit/work/robin/pysparnn/tests/test_pysparnn.py", line 52, in test_veccosine
    return_distance=False)
  File "pysparnn/cluster_pruning.py", line 274, in search
    k_clusters=k_clusters))
  File "pysparnn/cluster_pruning.py", line 208, in _search
    max_distance=max_distance)
  File "pysparnn/matrix_distance.py", line 81, in nearest_search
    dist_matrix = self._distance(sparse_features)
  File "pysparnn/matrix_distance.py", line 182, in _distance
    return 1 - dprod.multiply(magnitude).toarray()
AttributeError: 'matrix' object has no attribute 'toarray'

I had to use return 1 - np.asarray(dprod.multiply(magnitude))

Am I doing something wrong? I'm using python 2.7 and virtualenv.

spencebeecher commented 7 years ago

Thanks for the feedback! For my own sanity, did you install with requirements.txt?

cd pysparnn pip install -r requirements.txt python setup.py install

I have noticed that the sparse matrix methods change a bit from version to version. If you have a patch that works on the latest versions of scipy/numpy I'd be happy to update the code!

bhoomit commented 7 years ago

I used requirements.txt. Will try once again. If it still doesn't work will send a PR.

bhoomit commented 7 years ago

@spencebeecher so I tried again and it worked, so may be I installed one of the modules without requirements.txt. Sorry my bad. I can still send PR with latest version of scipy/numpy.

spencebeecher commented 7 years ago

Would love that!