#11257: Avoid a coercion when computing an element to the power of 0
---------------------------+------------------------------------------------
Reporter: nborie | Owner: nborie
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-4.7.1
Component: performance | Keywords: coercion, element, power, zero
Work_issues: | Upstream: N/A
Reviewer: | Author: Nicolas Borie
Merged: | Dependencies:
---------------------------+------------------------------------------------
Changes (by nborie):
* status: needs_review => needs_work
Old description:
> In the generic structure of element, a coercion is called to compute an
> element z to the power of 0 : z^0
>
> The goal of this ticket is trying to replace all call of Parent(1) by
> Parent.one() to avoid the coercion. (and hope Sage is ready for a such
> change...)
>
> Before :
> {{{
> sage: K = CyclotomicField(46)
> sage: z = K.gen()
> sage: %prun z^0
> 11 function calls in 0.000 CPU seconds
>
> Ordered by: internal time
>
> ncalls tottime percall cumtime percall filename:lineno(function)
> 1 0.000 0.000 0.000 0.000
> number_field.py:4871(_coerce_non_number_field_element_in)
> 1 0.000 0.000 0.000 0.000 <string>:1(<module>)
> 1 0.000 0.000 0.000 0.000
> number_field.py:6702(_element_constructor_)
> 1 0.000 0.000 0.000 0.000
> number_field.py:4221(polynomial_ntl)
> 4 0.000 0.000 0.000 0.000 {isinstance}
> 1 0.000 0.000 0.000 0.000
> number_field.py:4210(absolute_polynomial_ntl)
> 1 0.000 0.000 0.000 0.000 gap.py:1299(is_GapElement)
> 1 0.000 0.000 0.000 0.000 {method 'disable' of
> '_lsprof.Profiler' objects}
>
> sage: %prun z^3
> 2 function calls in 0.000 CPU seconds
>
> Ordered by: internal time
>
> ncalls tottime percall cumtime percall filename:lineno(function)
> 1 0.000 0.000 0.000 0.000 <string>:1(<module>)
> 1 0.000 0.000 0.000 0.000 {method 'disable' of
> '_lsprof.Profiler' objects}
> }}}
>
> And for the speed :
> {{{
> sage: timeit('z^0')
> 625 loops, best of 3: 28 µs per loop
> sage: timeit('z^3')
> 625 loops, best of 3: 7.78 µs per loop
> }}}
>
> depends on #9065
New description:
In the generic structure of element, a coercion is called to compute an
element z to the power of 0 : z^0
The goal of this ticket is trying to replace all call of Parent(1) by
Parent.one() to avoid the coercion. (and hope Sage is ready for a such
change...)
Before :
{{{
sage: K = CyclotomicField(46)
sage: z = K.gen()
sage: %prun z^0
11 function calls in 0.000 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000
number_field.py:4871(_coerce_non_number_field_element_in)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000
number_field.py:6702(_element_constructor_)
1 0.000 0.000 0.000 0.000
number_field.py:4221(polynomial_ntl)
4 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000
number_field.py:4210(absolute_polynomial_ntl)
1 0.000 0.000 0.000 0.000 gap.py:1299(is_GapElement)
1 0.000 0.000 0.000 0.000 {method 'disable' of
'_lsprof.Profiler' objects}
sage: %prun z^3
2 function calls in 0.000 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of
'_lsprof.Profiler' objects}
}}}
And for the speed :
{{{
sage: timeit('z^0')
625 loops, best of 3: 28 µs per loop
sage: timeit('z^3')
625 loops, best of 3: 7.78 µs per loop
}}}
depends on #9065
depends on #9138
--
Comment:
There going to have a little conflict with #9138 and its second patch
trac9138_categories_for_more_rings.patch. As Simon make a better
categorifycation than me, I will place this patch after. I will also begin
the review of #9138, I won't probably review everything (It is not a small
patch), but I will give a list of what I review (according my skills).
Thanks very very much for #9138 (not an amazing task but it has to be
done!)
Cheers,
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11257#comment:14>
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.