On 11/13/10 11:51 PM, William Stein wrote:


Other comments:

Jason Grout:
If we're now making a convention for the global sum function (i.e., try
calling the .sum() method first), I'm curious how many other objects
have a .sum() method?  Will this break things?

If you type "sum??" and read you'll find out that the sum method
already calls ".sum()" first:

     if hasattr(expression, 'sum'):
         return expression.sum(*args, **kwds)

I had to use __builtin__ above to get the genuine builtin Python sum
function, which is dog slow. The sum in Sage's global namespace
overrides the builtin python one and calls sum on the input object.
This has little overhead if the actual summing dominates:

I didn't realize (or had forgotten) that the sum already tries to call the .sum() method. In that case, my comment about calling ._sum_sage still stands (i.e., it's less likely to break 3rd party libraries), but is tempered by people not complaining already and breaking backwards compatibility at this point.



sage: v = vector(RDF,range(10^5))
sage: timeit('v.sum()', number=10^3)
1000 loops, best of 3: 116 盜 per loop
sage: timeit('sum(v)', number=10^3)
1000 loops, best of 3: 122 盜 per loop

If you try vectors with a smaller number of entries, e.g., a more
realistic maybe 20, then the time of doing the sum
in all cases is dominated by stupid overhead.  In the case of Sage's
RDF vector, the time is still pretty bad, since in fact the sum is
done by converting to numpy, and the numpy sum is itself very slow
(which may be surprising to people, but is true):


Actually, with RDF, the vector is stored as a numpy array, so there is no conversion. The overhead on our side (beyond the numpy overhead) is
in converting the numpy sum result back to an RDF element.

In numpy, the array is also stored as a C array of floats (doubles, actually), so I'm not sure where the extra numpy overhead is coming in. It would be interesting to peek at the numpy source and see.

Thanks,

Jason




--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to