I'm very concerned about speed. Thank you for sharing your code.

On 2/3/07, Alec Mihailovs <[EMAIL PROTECTED]> wrote:
>
> From: "Timothy Clemans" <[EMAIL PROTECTED]>
> >
> > Wow! Now thats cool. I'm going to time test them. Thanks
>
> I had some trouble with copying and pasting your procedure in SAGE (because
> I use it in Windows through cygwin and rxvt with Unix line endings and my
> email has Windows line endings and convert it to Unix by creating a text
> file and then using dos2unix on it seemed to be too much trouble). So I
> modified your procedure to plain Python by changing ^ to ** in 2 places and
> changing the end line in it to return square.
>
> After that I did timing in IDLE using the print_timing decorator from
> http://www.daniweb.com/code/snippet368.html .
>
> It appears that Siamese_magic_square is about 4-5 times faster than
> magicsquare_normal_odd.
>
> Actually, if the time is important, it can be made even faster by changing
> the j range (that reduces the number of operations). In SAGE form that looks
> like
>
> def Siamese_magic_square(n):
>     return matrix([[j%n*n+(j+j-i)%n+1
>         for j in range(i+(1-n)/2,i+(n+1)/2)] for i in range(n)])
>
> That makes it about 6-7 times faster than magicsquare_normal_odd (in IDLE,
> without matrix - I didn't test that in SAGE and I don't know how the matrix
> construction works there - in particular, whether adding the size of the
> matrix would make it faster.)
>
> Alec Mihailovs
> http://mihailovs.com/Alec/
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to