This should mean that there is no caching happening. 

sage: timeit('list(random_matrix(GF(5),5,10).row_space())')
5 loops, best of 3: 1.04 s per loop
sage: timeit('list(free_mod_iter(random_matrix(GF(5),5,10).row_space()))')
25 loops, best of 3: 14.6 ms per loop

Yeah, this iterator is "stuck" on the first coordinate on infinite 
base_rings(). it should be possible to write a diagonal iterator using a 
queue.

The old iterator in FreeModule_generic __iter__ does not maintain any state 
as it goes along. It takes (r1,r2,r3) -> r1*v1 + r2*v2 + r3*v3 by calling 
linear_combination_of_basis on the r-vector. Inside it does tons of 
type-checking, also coerces into Sequence once for each r-vector (this 
explains why naive multiplication gets you x10).

At each step it increments one r_i (most of the time) and goes through the 
scalar multiplication (all but one r's are the same) and vector addition of 
the whole \sum r_i*v_i. Using yield such computations are not repeated, 
which gives you another ~ 10x speed-up.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to