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

sparse matrix add() fail #1

Open
benureau opened this issue Sep 6, 2015 · 3 comments
Open

sparse matrix add() fail #1

benureau opened this issue Sep 6, 2015 · 3 comments
Labels

Comments

@benureau
Copy link
Collaborator

benureau commented Sep 6, 2015

add() on a sparse matrix fails.

$ python test_voc.py
.E
======================================================================
ERROR: test_add_coherent (__main__.TestAdd)
Test that all implementations are coherent
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_voc.py", line 59, in test_add_coherent
    v.add(3, 4, 1)
  File "/Users/fabien/research/enc/coda/naminggamesal/lib/ngvoc/__init__.py", line 32, in mod_fun
    ans = tempfun(obj_self, *args)
  File "/Users/fabien/research/enc/coda/naminggamesal/lib/ngvoc/matrix.py", line 77, in add
    self._content[m,w] = val
  File "/Users/fabien/.pyenv/versions/2.7.6/lib/python2.7/site-packages/scipy/sparse/lil.py", line 286, in __setitem__
    i, j, x, self.dtype)
  File "_csparsetools.pyx", line 102, in scipy.sparse._csparsetools.lil_insert (scipy/sparse/_csparsetools.c:3424)
KeyError: dtype('float16')

----------------------------------------------------------------------

It seems due to this line:

self._content=np.matrix(np.zeros((self._M,self._W),dtype=np.float16))

Is there a reason to use 'float16' explicitly ?

@benureau benureau added the bug label Sep 6, 2015
@benureau benureau changed the title test_voc.py fail sparse matrix add() fail Sep 6, 2015
@wschuell
Copy link
Collaborator

wschuell commented Sep 6, 2015

I put float16 data type so that it would take less memory, as required level of precision is really low (but shouldn't be just integer or binary, for future use of scores per associations). The reason is that databases would take several times less memory.
I think this problem has been solved in latest numpy versions, as i don't get this error.

@benureau
Copy link
Collaborator Author

benureau commented Sep 6, 2015

Fails for me on both 1.9.0 et 1.9.2. Python version 2.7.6 on OS.X:

Python 2.7.6 (default, Mar 10 2014, 20:11:44)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin

@benureau
Copy link
Collaborator Author

benureau commented Sep 6, 2015

Was wrong, this line is the culprit:

self._content=sparse.lil_matrix((self._M,self._W),dtype=np.float16)

Changing it to:

        self._content=sparse.lil_matrix((self._M,self._W))

solves the problem.

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

No branches or pull requests

2 participants