2009/6/25 Emmanuel Thomé <[email protected]>:
>
> 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.

Thanks!! I've made this trac #6410:

http://trac.sagemath.org/sage_trac/ticket/6410

By the way, I think

        371                     i,j = ij
        372                     A[i,j] = y

can be replaced by

        371                     A[ij] = y

William

--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to