#6410: optimize creation of diagonal matrices
----------------------------+-----------------------------------------------
Reporter: was | Owner: was
Type: enhancement | Status: new
Priority: major | Milestone: sage-4.1
Component: linear algebra | Keywords:
Reviewer: | Author:
Merged: |
----------------------------+-----------------------------------------------
{{{
Actually there are two issues.
Sure, the determinant issue is fairly easily diagnosed. No wonder that an
n!
algorithm takes time. I'll try to look into this.
But it's not the only thing.
> sage: p=3
> sage: n=1000
> sage: K=GF(p)
> sage: KP.<x>=PolynomialRing(K)
> sage: time xI=diagonal_matrix([x for i in range(n)])
> CPU times: user 32.18 s, sys: 0.14 s, total: 32.33 s
> Wall time: 32.34 s
While in comparison, doing
M=matrix(KP,n)
for i in range(n): M[i,i]=x
returns instantly.
Tracing it down, it seems that when calling diagonal_matrix:
- The list is converted to a dictionary.
- Because a dense matrix was requested, this dictionary is in turn
converted
to a flat list of n^2 entries.
- The base __matrix_class constructor is called, and calls the parent ring
conversion routine for each entry.
I don't know whether it's reasonable or not to have a million coercions of
zero take thirty seconds total (quite possibly not), but in any case these
can be avoided.
I suggest the attached patch.
Emmanuel.Thome at gmail.com
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6410>
Sage <http://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
-~----------~----~----~----~------~----~------~--~---