From: Artur P. <art...@gm...> - 2008-06-17 09:33:02
|
Hi to you all, I hope someone can help me. I am trying to do the following with pysparse but I am having problems doing it. I have a dense vector, say: x = numpy.arange(0,10) and a sparse matrix: A = pysparse.spmatrix.ll_mat(10,10) What I wish to do is: x = x + A[:, 2] But this gives the following error: TypeError: unsupported operand type(s) for +: 'float' and 'll_mat' Then I tried like this: x = numpy.arange(0,10) A = pysparse.sparray.sparray((10,10)) With this it works ok but then, when I try to do a slice: A_reduced = A[0:5, 0:5] It gives an error: TypeError: unsupported operand type(s) for +: 'int' and 'slice' Anybody can give a help? Also, what is the main difference between spmatrix and sparray? Thanking in advance Best regards -artur palha |
From: Daniel W. <dan...@gm...> - 2008-06-17 15:09:18
|
On Tue, Jun 17, 2008 at 5:33 AM, Artur Palha <art...@gm...> wrote: > Hi to you all, I hope someone can help me. > > I am trying to do the following with pysparse but I am having problems doing it. > > I have a dense vector, say: > > x = numpy.arange(0,10) > > and a sparse matrix: > > A = pysparse.spmatrix.ll_mat(10,10) > > What I wish to do is: > > x = x + A[:, 2] > > But this gives the following error: > TypeError: unsupported operand type(s) for +: 'float' and 'll_mat' If I remember correctly, ll_mat would need to have the __iter__ method to work with numpy. numpy checks the type of ll_mat then looks for one of __getitem__, __iter__, __array__ or __add__. I don't think ll_mat has these. The code I use has a wrapper which makes pysparse more pythonic. You may prefer to use the wrapper if it suits your purposes. <http://matforge.org/fipy/browser/trunk/fipy/tools/pysparseMatrix.py> > > Then I tried like this: > > x = numpy.arange(0,10) > > A = pysparse.sparray.sparray((10,10)) > > With this it works ok but then, when I try to do a slice: > > A_reduced = A[0:5, 0:5] > > It gives an error: > TypeError: unsupported operand type(s) for +: 'int' and 'slice' Not sure about why this doesn't work. It was probably implemented and never tested properly. I don't believe it does anything useful anyway. > Anybody can give a help? > > Also, what is the main difference between spmatrix and sparray? I would avoid using sparray. You also might want to check out scipy as their sparse support is much better now. -- Daniel Wheeler |
From: Artur P. <art...@gm...> - 2008-06-20 10:50:05
|
Thank you for your help Daniel I have downloaded it but it is asking for more modules from your project. I will try to have a look and see if I can do something based on what you did. In the meantime I will also have a look a pyTrilinos. Thank you once again. -artur palha On Tue, Jun 17, 2008 at 11:33 AM, Artur Palha <art...@gm...> wrote: > Hi to you all, I hope someone can help me. > > I am trying to do the following with pysparse but I am having problems doing it. > > I have a dense vector, say: > > x = numpy.arange(0,10) > > and a sparse matrix: > > A = pysparse.spmatrix.ll_mat(10,10) > > What I wish to do is: > > x = x + A[:, 2] > > But this gives the following error: > TypeError: unsupported operand type(s) for +: 'float' and 'll_mat' > > Then I tried like this: > > x = numpy.arange(0,10) > > A = pysparse.sparray.sparray((10,10)) > > With this it works ok but then, when I try to do a slice: > > A_reduced = A[0:5, 0:5] > > It gives an error: > TypeError: unsupported operand type(s) for +: 'int' and 'slice' > > Anybody can give a help? > > Also, what is the main difference between spmatrix and sparray? > > Thanking in advance > > Best regards > > -artur palha > |
From: Daniel W. <dan...@gm...> - 2008-06-20 14:09:10
Attachments:
pysparseMatrix.py
|
On Fri, Jun 20, 2008 at 6:50 AM, Artur Palha <art...@gm...> wrote: > Thank you for your help Daniel No problem. > I have downloaded it but it is asking for more modules from your project. Yes. I realized that Dominique Orban created a version of this that works with pysparse alone. See attachment. It really needs to be integrated into pysparse properly. I just haven't had a chance yet. > I will try to have a look and see if I can do something based on what > you did. In the meantime I will also have a look a pyTrilinos. Try scipy as well. -- Daniel Wheeler |
From: Dominique O. <dom...@gm...> - 2008-06-21 13:04:54
Attachments:
sparseMatrix.py
|
Artur, On top of the file that Daniel sent, you also need sparseMatrix.py which you can download from the repository Daniel mentioned earlier. I also attach it below. Good luck, Dominique On Fri, Jun 20, 2008 at 10:09 AM, Daniel Wheeler <dan...@gm...> wrote: > On Fri, Jun 20, 2008 at 6:50 AM, Artur Palha <art...@gm...> wrote: >> Thank you for your help Daniel > > No problem. > >> I have downloaded it but it is asking for more modules from your project. > > Yes. I realized that Dominique Orban created a version of this that > works with pysparse alone. See attachment. It really needs to be > integrated into pysparse properly. I just haven't had a chance yet. > >> I will try to have a look and see if I can do something based on what >> you did. In the meantime I will also have a look a pyTrilinos. > > Try scipy as well. > > -- > Daniel Wheeler > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Pysparse-users mailing list > Pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysparse-users > > |
From: gorkiana m. <gor...@gm...> - 2008-06-23 09:15:08
|
Dominique, Yes, I noticed that, I also made some changes because it asked numerix which was inside Fipy. Thank you. But yet I could not use it. Nevertheless I managed to solve my problem during this weekend. Basically pysparse.spmatrix.ll_mat objects have two methods: keys() and values() With this two it is possible to do what I want. This is what I did: A = pysparse.spmatrix.ll_mat(10,10) # a 10 x 10 sparse matrix X = numpy.arange(0,10) # a dense vector of length 10 A[0,1] = 10; A[0,2] = 10; A[0,3] = 10 To add the first row of A to X one just needs to do the following: A_indices = numpy.array(A[0,:].keys())[:,1] # keys is a list of tuples, so converting to numpy.array yelds a matrix # the first column is the row index and the second column the column index # we just need the column index # we get a vector with the indices where A has nonzero values at row 0 A_values = numpy.array(A[0,:].values()) # the nonzero values of row 0 X[A_indices] = X[A_indices] + A_values Simple! Thank you very much Dominique and Daniel for your help. Probably I will have more looks at FiPy because I will have more problems for sure! -artur palha On Sat, Jun 21, 2008 at 2:58 PM, Dominique Orban <dom...@gm...> wrote: > Artur, > > On top of the file that Daniel sent, you also need sparseMatrix.py > which you can download from the repository Daniel mentioned earlier. I > also attach it below. > > Good luck, > Dominique > > On Fri, Jun 20, 2008 at 10:09 AM, Daniel Wheeler > <dan...@gm...> wrote: > > On Fri, Jun 20, 2008 at 6:50 AM, Artur Palha <art...@gm...> > wrote: > >> Thank you for your help Daniel > > > > No problem. > > > >> I have downloaded it but it is asking for more modules from your > project. > > > > Yes. I realized that Dominique Orban created a version of this that > > works with pysparse alone. See attachment. It really needs to be > > integrated into pysparse properly. I just haven't had a chance yet. > > > >> I will try to have a look and see if I can do something based on what > >> you did. In the meantime I will also have a look a pyTrilinos. > > > > Try scipy as well. > > > > -- > > Daniel Wheeler > > > > ------------------------------------------------------------------------- > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > http://sourceforge.net/services/buy/index.php > > _______________________________________________ > > Pysparse-users mailing list > > Pys...@li... > > https://lists.sourceforge.net/lists/listinfo/pysparse-users > > > > > |