From: Oz N. T. <na...@gm...> - 2011-06-13 08:49:52
|
Hi *, I am trying to solve a simple sparse system and I get an unclear error. I have used the solvers before and never encoutered this error. Here is an example: In [505]: print A --------> print(A) 1.000000 --- --- --- --- --- 2.000000 --- --- --- --- --- 3.000000 --- --- --- --- --- 4.000000 --- --- --- --- --- 5.000000 In [506]: print b --------> print(b) [ 1. 2. 3. 4. 5.] In [507]: b Out[507]: array([ 1., 2., 3., 4., 5.]) In [508]: info, iter, relres = sp.itsolvers.bicgstab(A,b,x, tol, maxit) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/ozdeb/aeg-master/python book/richards flow/RichardsPython/<ipython console> in <module>() TypeError: matvec() takes exactly 2 arguments (3 given) Any help would be appreciated, Thanks in advance, Oz |
From: Dominique O. <dom...@gm...> - 2011-06-13 13:27:07
|
On Mon, Jun 13, 2011 at 8:43 AM, Oz Nahum Tiram <na...@gm...> wrote: > Hi *, > > I am trying to solve a simple sparse system and I get an unclear error. > I have used the solvers before and never encoutered this error. Here is an > example: > > In [505]: print A > --------> print(A) > 1.000000 --- --- --- --- > --- 2.000000 --- --- --- > --- --- 3.000000 --- --- > --- --- --- 4.000000 --- > --- --- --- --- 5.000000 > > In [506]: print b > --------> print(b) > [ 1. 2. 3. 4. 5.] > > In [507]: b > Out[507]: array([ 1., 2., 3., 4., 5.]) > > In [508]: info, iter, relres = sp.itsolvers.bicgstab(A,b,x, tol, maxit) > --------------------------------------------------------------------------- > TypeError Traceback (most recent call last) > > /home/ozdeb/aeg-master/python book/richards flow/RichardsPython/<ipython > console> in <module>() > > TypeError: matvec() takes exactly 2 arguments (3 given) > Hi Oz, What version of Pysparse are you using? Is this the Pysparse from Pypi or one from SVN? Thanks, -- Dominique |
From: Oz N. T. <na...@gm...> - 2011-06-13 13:30:54
|
Hi, Thanks for the answer - I should have mentioned such important info. I am using pysparse from the debian squeeze repositories... Cheers, Oz On Mon, Jun 13, 2011 at 3:01 PM, Dominique Orban <dom...@gm...>wrote: > On Mon, Jun 13, 2011 at 8:43 AM, Oz Nahum Tiram <na...@gm...> wrote: > >> Hi *, >> >> I am trying to solve a simple sparse system and I get an unclear error. >> I have used the solvers before and never encoutered this error. Here is an >> example: >> >> In [505]: print A >> --------> print(A) >> 1.000000 --- --- --- --- >> --- 2.000000 --- --- --- >> --- --- 3.000000 --- --- >> --- --- --- 4.000000 --- >> --- --- --- --- 5.000000 >> >> In [506]: print b >> --------> print(b) >> [ 1. 2. 3. 4. 5.] >> >> In [507]: b >> Out[507]: array([ 1., 2., 3., 4., 5.]) >> >> In [508]: info, iter, relres = sp.itsolvers.bicgstab(A,b,x, tol, maxit) >> >> --------------------------------------------------------------------------- >> TypeError Traceback (most recent call >> last) >> >> /home/ozdeb/aeg-master/python book/richards flow/RichardsPython/<ipython >> console> in <module>() >> >> TypeError: matvec() takes exactly 2 arguments (3 given) >> > > Hi Oz, > > What version of Pysparse are you using? Is this the Pysparse from Pypi or > one from SVN? > > Thanks, > > -- > Dominique > |
From: Dominique O. <dom...@gm...> - 2011-06-13 20:30:19
|
On Mon, Jun 13, 2011 at 1:30 PM, Oz Nahum Tiram <na...@gm...> wrote: > Hi, > Thanks for the answer - I should have mentioned such important info. > I am using pysparse from the debian squeeze repositories... > > Cheers, > > Oz > > > On Mon, Jun 13, 2011 at 3:01 PM, Dominique Orban < > dom...@gm...> wrote: > >> On Mon, Jun 13, 2011 at 8:43 AM, Oz Nahum Tiram <na...@gm...>wrote: >> >>> Hi *, >>> >>> I am trying to solve a simple sparse system and I get an unclear error. >>> I have used the solvers before and never encoutered this error. Here is >>> an example: >>> >>> In [505]: print A >>> --------> print(A) >>> 1.000000 --- --- --- --- >>> --- 2.000000 --- --- --- >>> --- --- 3.000000 --- --- >>> --- --- --- 4.000000 --- >>> --- --- --- --- 5.000000 >>> >>> In [506]: print b >>> --------> print(b) >>> [ 1. 2. 3. 4. 5.] >>> >>> In [507]: b >>> Out[507]: array([ 1., 2., 3., 4., 5.]) >>> >>> In [508]: info, iter, relres = sp.itsolvers.bicgstab(A,b,x, tol, maxit) >>> >>> --------------------------------------------------------------------------- >>> TypeError Traceback (most recent call >>> last) >>> >>> /home/ozdeb/aeg-master/python book/richards flow/RichardsPython/<ipython >>> console> in <module>() >>> >>> TypeError: matvec() takes exactly 2 arguments (3 given) >>> >> >> Hi Oz, >> >> What version of Pysparse are you using? Is this the Pysparse from Pypi or >> one from SVN? >> >> Thanks, >> >> -- >> Dominique > > Hi Oz, I presume your matrix A is an instance of pysparseMatrix. The solvers in the itsolvers module were originally designed for either ll_mat, csr_mat or sss_mat matrices. To fix the problem you can do info, iter, relres = sp.itsolvers.bicgstab(A.matrix, b, x, tol, maxit) I'll fix this in the next release. -- Dominique |
From: Dominique O. <dom...@gm...> - 2011-06-14 03:12:50
|
On Mon, Jun 13, 2011 at 10:41 PM, Oz Nahum Tiram <na...@gm...> wrote: > Thanks Dominique! > You where right, my matrix in this code was created so: > A=sp.pysparseMatrix.PysparseMatrix(size=numn) > > while in another code I created A so: > A = sp.spmatrix.ll_mat(m*n, m*n) > > I didn't notice this difference ... > > Your solution does work. Is it smarter to use one way or another ? > > One more thing, I thought of rewriting my code with the sparse modules from > scipy. > Which brought up the questions - > both codes are BSD, why is your code not there? > Are there differences in speed ? > Hi Oz, I just pushed improved wrappers for the iterative solvers to the 'suitesparse' branch of Pysparse (which is meant to become trunk in the near future). The wrappers are now more streamlined. For some reason, Bicgstab and Gmres were left out when we wrote those wrappers. I just added them. If you look in itsolvers_utils.py, you will see an example towards the bottom of the file. The wrappers accept both ll_mat and PysparseMatrix input. This is the better way to call the iterative solvers. There shouldn't be much of a difference in speed. What do you mean by "why is your code not there"? -- Dominique |
From: Oz N. T. <na...@gm...> - 2011-06-14 07:11:38
|
On Tue, Jun 14, 2011 at 5:12 AM, Dominique Orban <dom...@gm...> wrote: > > Hi Oz, > I just pushed improved wrappers for the iterative solvers to the 'suitesparse' branch of Pysparse (which is meant to become trunk in the near future). The wrappers are now more streamlined. For some reason, Bicgstab and Gmres were left out when we wrote those wrappers. I just added them. If you look in itsolvers_utils.py, you will see an example towards the bottom of the file. The wrappers accept both ll_mat and PysparseMatrix input. This is the better way to call the iterative solvers. There shouldn't be much of a difference in speed. > What do you mean by "why is your code not there"? > > -- > Dominique Hi Dominique, I looked at the code in itsolvers_utils.py, which uses the classes and objects concept. It is not unfamiliar for me to write code like that, but imho it adds a layer of complexity I prefer to avoid. What I meant in my question is from the two ways I used the matrices, is there some which gives better performance ? >What do you mean by "why is your code not there"? About code in scipy: it is good to have both projects, I just thought if you merge your code into scipy, it will reach bigger audiences. Thanks a lot for you answers, Oz |
From: Dominique O. <dom...@gm...> - 2011-06-14 13:26:14
|
On Tue, Jun 14, 2011 at 7:11 AM, Oz Nahum Tiram <na...@gm...> wrote: > On Tue, Jun 14, 2011 at 5:12 AM, Dominique Orban > <dom...@gm...> wrote: > > > > Hi Oz, > > I just pushed improved wrappers for the iterative solvers to the > 'suitesparse' branch of Pysparse (which is meant to become trunk in the near > future). The wrappers are now more streamlined. For some reason, Bicgstab > and Gmres were left out when we wrote those wrappers. I just added them. If > you look in itsolvers_utils.py, you will see an example towards the bottom > of the file. The wrappers accept both ll_mat and PysparseMatrix input. This > is the better way to call the iterative solvers. There shouldn't be much of > a difference in speed. > > What do you mean by "why is your code not there"? > > > > -- > > Dominique > > Hi Dominique, > I looked at the code in itsolvers_utils.py, which uses the classes and > objects concept. > It is not unfamiliar for me to write code like that, but imho it adds > a layer of complexity I prefer to avoid. > Complexity? In my view such classes offer more flexibility (e.g., you can subclass them) and are designed to make the user's life easier. For instance, now, they accept both ll_mat and PysparseMatrix input. I also moved arguments such as tol, itmax and K (the preconditioner) to the solve() method as that is where they belong. The old-style calling sequence is more C-like and less Python-like. In what way are they more complex to you? > What I meant in my question is from the two ways I used the matrices, > is there some which gives better performance ? > No, there should not be any performance hit when calling the solver. There may be a slight hit when you construct the matrix, but I would guess it is negligible and I've never bothered to measure it. >What do you mean by "why is your code not there"? > About code in scipy: it is good to have both projects, I just thought > if you merge your code into scipy, it will reach bigger audiences. > As you may know, Pysparse used to be part of Scipy several years ago. For some reason, the Scipy folks decided to write their own sparse matrix library. -- Dominique |
From: Jonathan G. <gu...@ni...> - 2011-06-14 13:44:04
|
On Jun 14, 2011, at 9:25 AM, Dominique Orban wrote: > As you may know, Pysparse used to be part of Scipy several years ago. For some reason, the Scipy folks decided to write their own sparse matrix library. I don't believe that's exactly true. In the course of refactoring their already existing sparse code several years ago (around 2005), the scipy developers imported Pysparse to see if there were things they could gain from Pysparse (Pysparse' LU solver is dramatically faster, for instance). I don't know that Pysparse was ultimately used much in that refactoring and I think it has subsequently been removed from the scipy codebase. I seem to recall that Roman indicated to us many years ago that he's not interested in merging pysparse into a larger suite like scipy; that he prefers individually maintained small packages to large monolithic systems. |
From: Dominique O. <dom...@gm...> - 2011-06-14 14:00:12
|
On Tue, Jun 14, 2011 at 1:43 PM, Jonathan Guyer <gu...@ni...> wrote: > > On Jun 14, 2011, at 9:25 AM, Dominique Orban wrote: > > > As you may know, Pysparse used to be part of Scipy several years ago. For > some reason, the Scipy folks decided to write their own sparse matrix > library. > > I don't believe that's exactly true. In the course of refactoring their > already existing sparse code several years ago (around 2005), the scipy > developers imported Pysparse to see if there were things they could gain > from Pysparse (Pysparse' LU solver is dramatically faster, for instance). I > don't know that Pysparse was ultimately used much in that refactoring and I > think it has subsequently been removed from the scipy codebase. > > I seem to recall that Roman indicated to us many years ago that he's not > interested in merging pysparse into a larger suite like scipy; that he > prefers individually maintained small packages to large monolithic systems. > Ok, thanks for clarifying this. -- Dominique |