#6410: [with patch; needs work] optimize creation of diagonal matrices
------------------------------+---------------------------------------------
Reporter: was | Owner: was
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-4.2.1
Component: linear algebra | Keywords:
Work_issues: | Author: Emmanuel Thome
Reviewer: | Merged:
------------------------------+---------------------------------------------
Changes (by rbeezer):
* status: needs_review => needs_work
Comment:
It appears to me the slowdown results when a dense matrix has many entries
that need to be coerced. So for a diagonal matrix built as a dense
matrix, this means all of the off-diagonal entries need to be coerced.
But the behavior is caused more generally by {{{matrix()}}}. Consider the
following session:
{{{
sage: K=GF(3)
sage: KP.<x>=PolynomialRing(K)
sage: G={}; H={}
sage: for i in range(200):
....: for j in range(200):
....: H[(i,j)]=KP(1)
....: G[(i,j)]=1
....:
sage: timeit('matrix(KP,200,H,sparse=False)')
5 loops, best of 3: 136 ms per loop
sage: timeit('matrix(KP,200,G,sparse=False)')
5 loops, best of 3: 1.09 s per loop
}}}
This is with the patch applied. The only difference is the dictionary H
has the elements coerced, while the dictionary G does not. The timings
are nearly identical to pre-patch behavior.
It seems to me that in the patch, the line {{{A = self(0)}}} still causes
{{{n^2}}} coercions of the zero element in {{{__call__}}} (of which it is
a part)? I could very well be mistaken, but I can't see a method one can
use to semi-automatically coerce 0 once (and only once) and then fill a
dense matrix with that single coerced zero. Should the behavior of
{{{zero_matrix()}}} be changed, so it does not just use {{{__call__}}}?
Ina any event, this review is not for nought. The doctest has {{{sage;}}}
(w/ a semi-colon) and not a {{{sage:}}} (w/ a colon) so it seems to not
even be coming through in the documentation, and likely the test is not
run?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6410#comment:7>
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
-~----------~----~----~----~------~----~------~--~---