Actually the fix I just posted in the last email was wrong. It should be:
sumsquares in sagex and python
system:sage
{{{id=0|
two = int(2)
def sumsquarespy(n):
return sum(i**two for i in xrange(1,n+1))
}}}
{{{id=1|
time v=[sumsquarespy(100) for _ in xrange(10000)]
///
CPU time: 0.46 s, Wall time: 0.46 s
}}}
{{{id=2|
%pyrex
# Next in pyrex.
def sumsquares(int n):
cdef int i, j
j = 0
for i from 1 <= i <= n:
j = j + i*i
return j
}}}
{{{id=3|
time v=[sumsquares(100) for _ in xrange(10000)]
///
CPU time: 0.02 s, Wall time: 0.02 s
}}}
{{{id=4|
}}}
On 7/28/07, William Stein <[EMAIL PROTECTED]> wrote:
> On 7/28/07, Neal Harris <[EMAIL PROTECTED]> wrote:
> >
> > Hi Everyone:
> >
> > I was trying to follow the example in 5.2.4 in the programming guide.
> > I entered the following in a cell in a SAGE notebook:
> >
> > %pyrex
> > two = int(2)
> > def sumsquarepy(n):
> > return sum(i**two for i in xrange(1, n+1))
> >
> > After evaluating that cell, I got the following error message:
>
> That's a strange mistake in the programming guide, which I'll
> fix for the next release. The correct input is:
>
> %pyrex
> two = int(2)
> def sumsquarespy(n):
> return sum([i**two for i in xrange(1,n+1)])
>
> See
>
> https://sage.math.washington.edu:8103/home/pub/1471/
>
> -- William
> >
> > Traceback (most recent call last): two = int(2)
> > File "/Applications/sage-2.7.1/local/lib/python2.5/site-packages/
> > sage/server/support.py", line 298, in sagex_import_all
> > create_local_c_file=create_local_c_file)
> > File "/Applications/sage-2.7.1/local/lib/python2.5/site-packages/
> > sage/server/support.py", line 279, in sagex_import
> > create_local_c_file=create_local_c_file)
> > File "/Applications/sage-2.7.1/local/lib/python2.5/site-packages/
> > sage/misc/sagex.py", line 219, in sagex
> > raise RuntimeError, "Error converting %s to C:\n%s\n%s"%(filename,
> > log, err)
> > RuntimeError: Error converting /Users/neal/sage_notebook/worksheets/
> > root/0/code/sage14.spyx to C:
> >
> >
> > Error converting Pyrex file to C:
> > ------------------------------------------------------------
> > ...
> > include "stdsage.pxi" # ctrl-c interrupt block support
> >
> > include "cdefs.pxi"
> > two = int(2)
> > def sumsquarepy(n):
> > return sum(i**two for i in xrange(1, n+1)) ^
> > ------------------------------------------------------------
> >
> > /Users/neal/.sage/temp/OK-Computer.local/28019/spyx/
> > _Users_neal_sage_notebook_worksheets_root_0_code_sage14_spyx/
> > _Users_neal_sage_notebook_worksheets_root_0_code_sage14_spyx_0.pyx:
> > 8:22: Expected ')'
> >
> > The file that it's complaining about exists.
> >
> > I really have no idea how to diagnose this problem, since I've only
> > just recently started playing with the notebook and pyrex. Any help
> > would be greatly appreciated!
> >
> > Neal
> >
> >
> > > >
> >
>
>
> --
> William Stein
> Associate Professor of Mathematics
> University of Washington
> http://www.williamstein.org
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://www.williamstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-forum
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---