#12239: Better conversion to/from ECL bignums
-----------------------------+----------------------------------------------
   Reporter:  nbruin         |          Owner:  was            
       Type:  enhancement    |         Status:  positive_review
   Priority:  minor          |      Milestone:  sage-4.8       
  Component:  interfaces     |       Keywords:  ecl, maxima    
Work_issues:                 |       Upstream:  N/A            
   Reviewer:  Burcin Erocal  |         Author:  Nils Bruin     
     Merged:                 |   Dependencies:                 
-----------------------------+----------------------------------------------
Changes (by newvalueoldvalue):

  * keywords:  => ecl, maxima
  * reviewer:  => Burcin Erocal
  * status:  needs_review => positive_review
  * author:  => Nils Bruin


Old description:

> Previously, python <-> ECL conversion of bigints went via (decimal!)
> string representation. This ticket fixes this. Timings before:
> {{{
> sage: from sage.libs.ecl import *
> sage: i = 10^(10^5)
> sage: o = EclObject(i)
> sage: timeit('EclObject(i)')
> 5 loops, best of 3: 331 ms per loop
> sage: timeit('o.python()')
> 25 loops, best of 3: 18.6 ms per loop
> }}}
> after:
> {{{
> sage: timeit('EclObject(i)')
> 625 loops, best of 3: 44.2 µs per loop
> sage: timeit('o.python()')
> 625 loops, best of 3: 4.49 µs per loop
> }}}
> These conversions will benefit symbolic routines that call maxima via the
> binary interface (integrate, limit, sum) but obviously not the ones that
> use all-string conversion. Most symbolic work does not involve large
> integers anyway.
>
> NOTE: Current implementation copies the bitstring twice for python ->
> ECL. In principle this could be avoided but needs reaching into ECL's
> internals. The "ecl_big_register" routines are exported, but the other
> routines are "static". This is because there are some subtleties with how
> ECL avoids GMPs memory reallocation to step in. Therefore, the present
> solution is probably the safest. Should this ever become a bottleneck, we
> can reconsider.

New description:

 Previously, python <-> ECL conversion of bigints went via (decimal!)
 string representation. This ticket fixes this. Timings before:
 {{{
 sage: from sage.libs.ecl import *
 sage: i = 10^(10^5)
 sage: o = EclObject(i)
 sage: timeit('EclObject(i)')
 5 loops, best of 3: 331 ms per loop
 sage: timeit('o.python()')
 25 loops, best of 3: 18.6 ms per loop
 }}}
 after:
 {{{
 sage: timeit('EclObject(i)')
 625 loops, best of 3: 44.2 µs per loop
 sage: timeit('o.python()')
 625 loops, best of 3: 4.49 µs per loop
 }}}
 These conversions will benefit symbolic routines that call maxima via the
 binary interface (integrate, limit, sum) but obviously not the ones that
 use all-string conversion. Most symbolic work does not involve large
 integers anyway.

 NOTE: Current implementation copies the bitstring twice for python -> ECL.
 In principle this could be avoided but needs reaching into ECL's
 internals. The "ecl_big_register" routines are exported, but the other
 routines are "static". This is because there are some subtleties with how
 ECL avoids GMPs memory reallocation to step in. Therefore, the present
 solution is probably the safest. Should this ever become a bottleneck, we
 can reconsider.

 Apply attachment:trac_12239-ecl_bignum.patch

--

Comment:

 Patch looks good. Applies cleanly to 4.8.alpha4. Tests pass on symbolics
 related files (`sage/{symbolics,functions,calculus}` etc.). Positive
 review.

 I attached a new patch which also removes the comments that refer to the
 previous string conversion code and say that this can be done more
 efficiently.

 Apply attachment:trac_12239-ecl_bignum.patch only.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12239#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
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.

Reply via email to