[sage-devel] Re: Pyrex performance

2007-06-28 Thread Gonzalo Tornaria
On 6/28/07, Justin C. Walker <[EMAIL PROTECTED]> wrote: > def is_symmetric(self): > [...] > for i from 1 <= i < self._nrows: > for j from 0 <= j < self._ncols: > [ DO SOMETHING ] > def is_sym3(self): > [...] > for i in xrange(1,self._nrow

[sage-devel] Re: Pyrex performance

2007-06-28 Thread Nick Alexander
"Justin C. Walker" <[EMAIL PROTECTED]> writes: > if self[i,j] != self[j,i]: return False One more thought: this could be creating Python ints for i and j each repetition; optimized indexing might avoid that. Nick --~--~-~--~~~---~--~~ To post to

[sage-devel] Re: Pyrex performance

2007-06-28 Thread boothby
In the first one, you're checking all entries, not just upper-triangular ones. That'd account for a factor of 2 pretty well. On Thu, 28 Jun 2007, Justin C. Walker wrote: > > Hi, > > I tried the following, added to the Matrix class definition in matrix/ > matrix0.pyx: > > def is_symmetric(

[sage-devel] Re: Pyrex performance

2007-06-28 Thread Nick Alexander
Two comments, without a great deal of thought or justification. > if self[i,j] != self[j,i]: return False This could be getting compiled to a default Python object indexing, which is slow like molasses. You might want to check the generated C code and change it to use faster in

[sage-devel] Pyrex performance

2007-06-28 Thread Justin C. Walker
Hi, I tried the following, added to the Matrix class definition in matrix/ matrix0.pyx: def is_symmetric(self): """ Returns True if this is a symmetric matrix. """ if self._ncols != self._nrows: return False cdef int i,j for i from 1 <=

[sage-devel] Re: Matrix question

2007-06-28 Thread Justin C. Walker
On Jun 28, 2007, at 16:30 , David Roe wrote: > Sorry I didn't reply earlier. Not a problem. > Implementing an is_symmetric function for matrices sounds like a > good idea. > But I think it should go in the base class: something like That was my feeling as well. > def is_symmetric(self): >

[sage-devel] Re: flatten list command

2007-06-28 Thread William Stein
On 6/28/07, Hamptonio <[EMAIL PROTECTED]> wrote: > Whoops! - sorry about the misreporting on the GF(5) behavior. I was > playing around with lots of similar versions and I must have gotten > confused. > > That extra loop you deleted was put in to avoid errors on weird cases > like: flatten([[]]),

[sage-devel] Re: flatten list command

2007-06-28 Thread Hamptonio
Whoops! - sorry about the misreporting on the GF(5) behavior. I was playing around with lots of similar versions and I must have gotten confused. That extra loop you deleted was put in to avoid errors on weird cases like: flatten([[]]), which gives an "IndexError: list index out of range" if the

[sage-devel] Re: flatten list command

2007-06-28 Thread Nick Alexander
> I've incorporated this into SAGE as a patch. I like the final form. > [EMAIL PROTECTED]:~/d/sage/sage/misc$ hg export 5194 > # HG changeset patch > # User William Stein <[EMAIL PROTECTED]> > # Date 1183076918 25200 > # Node ID 25f23d18288895f46a6aaa2bd8ef147cde5e31f3 > # Parent 65b460226d81

[sage-devel] Re: request for comments: ZZ(ZZ(FOO).binary(),2) == FOO

2007-06-28 Thread Nick Alexander
Martin Albrecht <[EMAIL PROTECTED]> writes: > Hi there, > > I often come across the situation where I have to construct an integer from > its binary representation and vice versa. So far you do it in SAGE using > strings. I have attached a preliminary patch which allows the following code > to

[sage-devel] Re: flatten list command

2007-06-28 Thread William Stein
On 6/28/07, Hamptonio <[EMAIL PROTECTED]> wrote: > Interesting. I think I originally ripped mine off from one of [...] Hi, I've incorporated this into SAGE as a patch. The main things I did were add more examples and delete part of the function which I consider stupid. E.g., you wrote "flatten

[sage-devel] Re: Matrix question

2007-06-28 Thread William Stein
+1 -- I agree 100% with David Roe's response. On 6/28/07, David Roe <[EMAIL PROTECTED]> wrote: > Sorry I didn't reply earlier. > > Implementing an is_symmetric function for matrices sounds like a good idea. > But I think it should go in the base class: something like > > def is_symmetric(self): >

[sage-devel] Re: Matrix question

2007-06-28 Thread David Roe
Sorry I didn't reply earlier. Implementing an is_symmetric function for matrices sounds like a good idea. But I think it should go in the base class: something like def is_symmetric(self): if self.ncols != self.nrows: return False cdef int i, j: for i from 1 <= i < self.nrows:

[sage-devel] Re: request for comments: ZZ(ZZ(FOO).binary(),2) == FOO

2007-06-28 Thread David Harvey
On Jun 28, 2007, at 6:06 PM, Martin Albrecht wrote: > >> Hmmm I don't know if I like this. Well, I don't have any objections >> to such a method being available, but I prefer the name "binary" to >> have the current behaviour. It's more pythonic, like the hex >> function. > > But there is no b

[sage-devel] Re: request for comments: ZZ(ZZ(FOO).binary(),2) == FOO

2007-06-28 Thread Martin Albrecht
> Hmmm I don't know if I like this. Well, I don't have any objections > to such a method being available, but I prefer the name "binary" to > have the current behaviour. It's more pythonic, like the hex function. But there is no binary/bin function. I understand that __hex__ returns a string to

[sage-devel] Re: request for comments: ZZ(ZZ(FOO).binary(),2) == FOO

2007-06-28 Thread didier deshommes
On 6/29/07, David Harvey <[EMAIL PROTECTED]> wrote: > > > On Jun 28, 2007, at 5:04 PM, Martin Albrecht wrote: > > > Hi there, > > > > I often come across the situation where I have to construct an > > integer from > > its binary representation and vice versa. So far you do it in SAGE > > using > >

[sage-devel] Matrix question

2007-06-28 Thread Justin C. Walker
Hi, I ran into a glitch, using QuaternionAlgebraWithGramMatrix(field, matrix): - the code verifies that the second argument is a matrix with "isinstance(Matrix)", which blows up because 'Matrix' is not known. A simple 'import' fixes that. - then the code blows up because "is_sy

[sage-devel] Re: flatten list command

2007-06-28 Thread Hamptonio
Interesting. I think I originally ripped mine off from one of the comments at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363051 although I've tried to make mine more readable. The thread you linked to has the apparent winner of Ron Adams: def flatten(seq): s = [] while

[sage-devel] Re: request for comments: ZZ(ZZ(FOO).binary(),2) == FOO

2007-06-28 Thread David Harvey
On Jun 28, 2007, at 5:04 PM, Martin Albrecht wrote: > Hi there, > > I often come across the situation where I have to construct an > integer from > its binary representation and vice versa. So far you do it in SAGE > using > strings. I have attached a preliminary patch which allows the > f

[sage-devel] Re: flatten list command

2007-06-28 Thread boothby
There's a good discussion on the python mailing list regarding flatten: http://mail.python.org/pipermail/python-list/2005-July/330367.html particularly, it's got a number of different implementations, and benchmarks. On Thu, 28 Jun 2007, Hamptonio wrote: > > I often want to flatten nested lis

[sage-devel] request for comments: ZZ(ZZ(FOO).binary(),2) == FOO

2007-06-28 Thread Martin Albrecht
Hi there, I often come across the situation where I have to construct an integer from its binary representation and vice versa. So far you do it in SAGE using strings. I have attached a preliminary patch which allows the following code to work, i.e. I _replaced_ the binary() method (which retur

[sage-devel] Re: flatten list command

2007-06-28 Thread Hamptonio
To be honest I didn't give it much thought. This is modified from the simplest code I could find that did the job. flatten(GF(5)) does return [0,1,2,3,4], while flatten([GF(5)]) returns [Finite Field of size 5]. However, you can do: flatten([GF(5)],ltypes = (list, tuple, sage.rings.finite_fiel

[sage-devel] Re: flatten list command

2007-06-28 Thread Nick Alexander
> def flatten(in_list, ltypes=(list, tuple)): > ... > ltypes -- optional list of particular types to flatten Could you elaborate on the decisions made around iterators here? I can see that flatten([GF(5)]) could be tricky -- is it [GF(5)] or [0, 1, 2, 3, 4]? Nick --~--~-~--~---

[sage-devel] flatten list command

2007-06-28 Thread Hamptonio
I often want to flatten nested lists, and such a command (like Mathematica's Flatten) does not seem to be present in sage. I propose adding such a command into the misc.py. I am appending some candidate code below, and I will also put it on sage-trac (http:// www.sagemath.org:9002/sage_trac/tick

[sage-devel] Re: mixed volumes

2007-06-28 Thread Marshall Hampton
The most recent algorithm used in PHCpack is very fast and pretty sophisticated; I believe its fair to say its a descendent of the Emiris algorithm cited by Chuck Doran. I will go ahead and put it in the PHCpack interface I am reworking. My idea for the PHCpack interface is to have several diffe

[sage-devel] Re: sage trac login (and patch)

2007-06-28 Thread William Stein
Unfortunately for your patch, the SAGE notebook (and server) was almost completely rewritten during the last 2-3 weeks. In particular, server.py is no longer used, and the SAGE notebook uses the vastly more scalable twisted web2 networking framework. This new version will be released within a