I did some quick profiling, and the primary culprit seems to be that 
T[0].change_ring(QQ) does two expensive echelonizing operations, each of 
which last about 37 seconds.  The specific function is 'echelon_form' in 
Matrix_rational_dense.

The short answer is that the the class FreeModule_submodule_field always 
has an echelonized basis.  I can't comment on whether this is a good 
idea/necessary or not.

As to why the command is faster when you do

sage: Matrix(T).change_ring(QQ).rows()[0] 

it's because this never creates a free module submodule.  Instead, after 
the matrix is created, the conversion of the matrix to QQ is done by 
calling Rational on each matrix entry.  This is extremely fast since 
Rational(0) = 0, and Rational(1) = 1.

When you do

sage: T[0].change_ring(QQ) 

it computes a basis for the vector space of degree 2000 and dimension 1000 
over GF(2), and then for loops over the basis elements casting each as a 
vector over QQ.  It then creates a free module from these converted basis 
elements and computes their span in the free module. This creates a 
submodule, and so calls the echelonizing function.



On Monday, November 25, 2013 3:07:24 PM UTC-5, Jeroen Demeyer wrote:
>
> Why does this take such a long time? 
>
> sage: M = random_matrix(ZZ,2000,1000) 
> sage: T = M.change_ring(GF(2)).left_kernel().basis() 
> sage: %time r = T[0].change_ring(QQ) 
> CPU times: user 73.49 s, sys: 0.33 s, total: 73.83 s 
> Wall time: 74.01 s 
>
> Especially compared to 
> sage: %time r2 = Matrix(T).change_ring(QQ).rows()[0] 
> CPU times: user 7.40 s, sys: 0.01 s, total: 7.41 s 
> Wall time: 7.40 s 
>
> Or even 
> sage: %time r3 = vector(QQ, T[0].list()) 
> CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s 
> Wall time: 0.01 s 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to