#5093: [with patch, needs review] rewrite fast_float to support more datatypes
------------------------------+---------------------------------------------
Reporter: cwitty | Owner: cwitty
Type: defect | Status: assigned
Priority: major | Milestone: sage-feature
Component: basic arithmetic | Keywords:
------------------------------+---------------------------------------------
Comment(by cwitty):
OK, I've put up a new patch which I think is ready for review. The big
feature here is support for multiple types -- we get accelerated
evaluation over {{{RealField(k)}}} as well as RDF, and even the
unaccelerated Python-object evaluator (which calls {{{PyNumber_Add}}} and
friends) is still faster than the evaluators for multivariate and
univariate polynomials over QQ.
We're also typically somewhat faster than the old fast_float, but often
not by a lot. (In the three benchmarks below, the speed gain ranges from
2% faster to more than 2x as fast.) There's still a lot of optimization I
can do.
Here are the benchmark details:
{{{
sage: set_random_seed(0)
sage: K.<x,y,z> = QQ[]
sage: p = K.random_element(10, 20)
sage: p_rr = p.change_ring(RR)
sage: p_rdf = p.change_ring(RDF)
sage: fp_old = fast_float(p, x, y, z, old=True)
sage: fp_rdf = fast_callable(p, domain=RDF)
sage: fp_rr = fast_callable(p, domain=RR)
sage: fp_any = fast_callable(p)
sage:
sage: timeit('p(1,2,3)')
625 loops, best of 3: 369 µs per loop
sage: timeit('fp_any(1,2,3)')
625 loops, best of 3: 115 µs per loop
sage:
sage: timeit('p(1.0,2.0,3.0)')
625 loops, best of 3: 460 µs per loop
sage: timeit('p_rr(1.0,2.0,3.0)')
625 loops, best of 3: 341 µs per loop
sage: timeit('fp_rr(1.0,2.0,3.0)')
625 loops, best of 3: 121 µs per loop
sage:
sage: timeit('p(1.0r,2.0r,3.0r)')
625 loops, best of 3: 334 µs per loop
sage: timeit('p_rdf(1.0r,2.0r,3.0r)')
625 loops, best of 3: 101 µs per loop
sage: timeit('fp_old(1.0r,2.0r,3.0r)')
625 loops, best of 3: 4.27 µs per loop
sage: timeit('fp_rdf(1.0r,2.0r,3.0r)')
625 loops, best of 3: 4.18 µs per loop
sage:
sage: set_random_seed(0)
sage: K.<x> = QQ[]
sage: p = K.random_element(20)
sage: p_rr = p.change_ring(RR)
sage: p_rdf = p.change_ring(RDF)
sage: fp_old = fast_float(p, x, old=True)
sage: fp_rdf = fast_callable(p, domain=RDF)
sage: fp_rr = fast_callable(p, domain=RR)
sage: fp_any = fast_callable(p)
sage:
sage: timeit('p(2)')
625 loops, best of 3: 53.3 µs per loop
sage: timeit('fp_any(2)')
625 loops, best of 3: 37 µs per loop
sage:
sage: timeit('p(2.0)')
625 loops, best of 3: 54.9 µs per loop
sage: timeit('p_rr(2.0)')
625 loops, best of 3: 5.76 µs per loop
sage: timeit('fp_rr(2.0)')
625 loops, best of 3: 7.8 µs per loop
sage:
sage: timeit('p(2.0r)')
625 loops, best of 3: 153 µs per loop
sage: timeit('p_rdf(2.0r)')
625 loops, best of 3: 20.6 µs per loop
sage: timeit('fp_old(2.0r)')
625 loops, best of 3: 973 ns per loop
sage: timeit('fp_rdf(2.0r)')
625 loops, best of 3: 403 ns per loop
sage:
sage: var('x,y,z')
(x, y, z)
sage: v = sin(sqrt(x*x + y^3) + z/4) * (x+y+z^5)
sage: fv_old = fast_float(v, x, y, z, old=True)
sage: fv_rdf = fast_callable(v, domain=RDF)
sage: fv_rr = fast_callable(v, domain=RR)
sage: fv_any = fast_callable(v)
sage:
sage: timeit('v(x=1.0,y=2.0,z=3.0)')
625 loops, best of 3: 438 µs per loop
sage: timeit('fv_rr(1.0,2.0,3.0)')
625 loops, best of 3: 35.5 µs per loop
sage:
sage: timeit('v(x=2.0r,y=2.0r,z=3.0r)')
625 loops, best of 3: 400 µs per loop
sage: timeit('fv_old(1.0r,2.0r,3.0r)')
625 loops, best of 3: 680 ns per loop
sage: timeit('fv_rdf(1.0r,2.0r,3.0r)')
625 loops, best of 3: 544 ns per loop
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5093#comment:3>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
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-trac?hl=en
-~----------~----~----~----~------~----~------~--~---