Skip to content

sparse.as_coo does not work for N-by-1 np.matrix #199

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

Closed
gongliyu opened this issue Oct 16, 2018 · 1 comment
Closed

sparse.as_coo does not work for N-by-1 np.matrix #199

gongliyu opened this issue Oct 16, 2018 · 1 comment
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@gongliyu
Copy link
Contributor

When input a N-by-1 matrix of type np.matrix, sparse.as_coo throws an error. It correctly dispatchs to sparse.COO.from_numpy but can not handle it. Please see the following

In [1]: import scipy.sparse,sparse

In [2]: sp = scipy.sparse.random(10,1,0.5)

In [3]: mat = sp.argmax(1)

In [4]: sparse.as_coo(mat)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-5492fc8fff45> in <module>()
----> 1 sparse.as_coo(mat)

C:\Users\Liyu\Anaconda3\lib\site-packages\sparse\coo\core.py in as_coo(x, shape, fill_value)
   1749
   1750     if isinstance(x, np.ndarray):
-> 1751         return COO.from_numpy(x, fill_value=fill_value)
   1752
   1753     if isinstance(x, scipy.sparse.spmatrix):

C:\Users\Liyu\Anaconda3\lib\site-packages\sparse\coo\core.py in from_numpy(cls, x, fill_value)
    308             data = np.array(x, ndmin=1)
    309         return cls(coords, data, shape=x.shape, has_duplicates=False,
--> 310                    sorted=True, fill_value=fill_value)
    311
    312     def todense(self):

C:\Users\Liyu\Anaconda3\lib\site-packages\sparse\coo\core.py in __init__(self, coords, data, shape, has_duplicates, sorted, cache, fill_value)
    223                 msg = ('The data length does not match the coordinates '
    224                        'given.\nlen(data) = {}, but {} coords specified.')
--> 225                 raise ValueError(msg.format(len(data), self.coords.shape[1]))
    226             if len(self.shape) != self.coords.shape[0]:
    227                 msg = ("Shape specified by `shape` doesn't match the "

ValueError: The data length does not match the coordinates given.
len(data) = 1, but 0 coords specified.
@hameerabbasi
Copy link
Collaborator

This is now fixed and tested in master.

@hameerabbasi hameerabbasi added the bug Indicates an unexpected problem or unintended behavior label Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants