Marshall Hampton wrote: > I think the culprit is the "pi" in the srange, which gets Maxima too > involved (and maxima as called through sage is slow). This may > improve very soon as there is some work being done to shift basic > symbolic things like "pi" to a more python-based backend. > > Anyway for the moment you can avoid this by declaring your own numeric > pi. The fastest I could do this without using "fast_float" was: > > pts=[]; > number_of_points=500 > mypi = n(pi) > for t1 in srange(0, mypi, n(pi/sqrt(number_of_points))): > st1 = sin(t1) > ct1 = cos(t1) > for t2 in srange(0, 2*mypi, n(2*pi/sqrt(number_of_points))): > pts.append((st1*cos(t2), st1*sin(t2), ct1)) > show(point3d(pts)) > > ...taking the sin(t1) and cos(t1) calc out of the inner loop helps a > bit as well. That was much faster for me than your original code. >
Here's a version that's about 6x faster yet again by avoiding yet more calculations in the inner loop and using the python sin/cos instead of the sage sin/cos: pts=[]; number_of_points=500 twopi = 2*RR(pi) mystep = twopi/math.sqrt(number_of_points) mysin,mycos = math.sin,math.cos for t1 in srange(0, twopi/2, mystep/2): st1 = mysin(t1) ct1 = mycos(t1) for t2 in srange(0, twopi, mystep): pts.append((st1*mycos(t2), st1*mysin(t2), ct1)) Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ 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://www.sagemath.org -~----------~----~----~----~------~----~------~--~---