From: Dominique O. <dom...@gm...> - 2010-02-27 11:09:45
|
On Fri, Feb 26, 2010 at 11:30 PM, Rob Speer <rs...@mi...> wrote: > It's hard to tell from the Web, but it sounds like the right thing to > do when I encounter unexpected behavior in PySparse is to e-mail this > list, right? > > I'm trying to assign to a slice of an ll_mat from another matrix. If > this other matrix is also an ll_mat, this works fine. However, it acts > very strange if the other matrix is a standard NumPy ndarray: > > ---------- > In [1]: from pysparse.spmatrix import * > > In [2]: sq = ll_mat(5,5) > > In [3]: sq > Out[3]: <ll_mat object at 0x1d26bf0> > > In [4]: print sq > ------> print(sq) > ll_mat(general, [5,5]): > -------- -------- -------- -------- -------- > -------- -------- -------- -------- -------- > -------- -------- -------- -------- -------- > -------- -------- -------- -------- -------- > -------- -------- -------- -------- -------- > > In [6]: import numpy as np > > In [7]: sq[:,:] = np.arange(25).reshape((5,5)) > In LHS=RHS, RHS has shape (2,27483600), LHS has shape (5,5) > --------------------------------------------------------------------------- > ValueError Traceback (most recent call last) > > /Users/rspeer/python/src/pysparse/<ipython console> in <module>() > > ValueError: Matrix shapes are different > ----------- > > There seems to be no other straightforward way to convert a small > dense matrix to a sparse one, either. Am I missing how to do this, or > is this a bug that should be fixed? Rob, Yes, e-mailing this list is the right thing to do. Welcome to Pysparse! Indeed, Pysparse expects the right-hand side of an assignment to be a ll_mat object. Currently, you can't assign from a dense matrix or easily convert a dense matrix to a ll_mat object. I agree that this functionality would be useful. I might not have a chance to code that before a few weeks though. If anyone wants to have a stab at it, I can get them started. -- Dominique |