I was benchmarking some code (in particular the density() method of matrices) and noticed code of the form

if not x.is_zero():

however, that's a lot slower than doing just

if x:

So, this makes me wonder: what is the reason for the is_zero() method? Are there classes where "x.is_zero()" is not the same as "not x"?

sage: L = list(GF(2)); timeit('[x for x in L if x]')
625 loops, best of 3: 245 ns per loop
sage: L = list(GF(2)); timeit('[x for x in L if x.is_zero()]')
625 loops, best of 3: 323 ns per loop

--
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 sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to