On Saturday, August 24, 2013 6:03:52 AM UTC-7, David Loeffler wrote:
>
> There is a second problem, also, with the use of "verbose" in Cython
> code in the sage library. When "verbose" is called, the code for the
> verbosity mechanism decides whether to print the message based on the
> name of the module containing the calling function. Unfortunately this
> introspection mechanism doesn't work for Cython files.
Oh right, because you'll have to select emptystring or 'all' as verbose
filename (there is nothing to select on).
Looking at the implementation, by the way, there are things happening there
that are way worse. In all cases, 'cputime()' is returned. To give you an
idea of the cost:
sage: timeit('_=None')
625 loops, best of 3: 22.1 ns per loop
sage: timeit('_=cputime()')
625 loops, best of 3: 1.89 µs per loop
sage: timeit('_="%s,%s"%(2,3)')
625 loops, best of 3: 1.33 µs per loop
sage: timeit('_=get_verbose()')
625 loops, best of 3: 174 ns per loop
so just that is about as expensive as the string interpolation!
For example, in matrix_integer_dense._rational_kernel_iml (this code gets
normally used for computing the right kernel of a matrix with rational
coefficients) we have verbose commands, so for instance:
sage: set_verbose(1)
sage: M=matrix(Integers(),2,2,1)
sage: M._rational_kernel_iml()
verbose 1 (<module>) computing null space of 2 x 2 matrix using IML
verbose 1 (<module>) finished computing null space (time = 0.002)
[]
sage: timeit('M._rational_kernel_iml()')
625 loops, best of 3: 924 µs per loop
sage: set_verbose(0)
sage: timeit('M._rational_kernel_iml()')
625 loops, best of 3: 905 µs per loop
after commenting out the verbose statements entirely we get
sage: timeit('M._rational_kernel_iml()')
625 loops, best of 3: 877 µs per loop
so if you're computing with small matrices with rational coefficients, you
may well pay a measurable price to having verbose statements in the code.
This can be alleviated somewhat (and this already happens in parts of the
library) by writing something like
cdef int v = get_verbose()
if v>0:
time = verbose('computing null space of %s x %s matrix using
IML'%(self._nrows, self._ncols))
which yields (with verbose turned off):
sage: timeit('M._rational_kernel_iml()')
625 loops, best of 3: 884 µs per loop
which is a little more acceptable. Here, get_verbose() is a python routine
that accesses a python global variable. If we cythonize those and make it a
C global flag somewhere, we can provide superfast cython code to check the
flag, eliminating the penalty entirely (provided you don't put verbose
statements in REALLY tight loops)
--
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.