On Monday, September 8, 2014 9:47:51 AM UTC+1, Martin Raum wrote:

> For Python, because there is no inlining, I thought of a little hack. To 
> trigger citations call

sage.citation.cite(bib.libsingular)
>
Now, if citation is enabled, then cite = _cite(*bibs), and if not then cite 
> = def _cite_pass(*bibs): pass
>

Changing the definition of sage.citation.cite inside the module at runtime 
is going to break code that uses the "from sage.citation import cite" 
statement, as it will have already imported the old definition. I also 
think that its not necessary, checking a cdef bool is again basically free 
compared to the cost of a new Python stack frame. And if that is a problem 
then you should have used Cython for your function anyways. 

sage: cython("""
cdef bint sage_citation_enabled = False
cpdef cite():
    if sage_citation_enabled:
        raise NotImplementedError()
""")
sage: timeit('cite()', number=10000000)
10000000 loops, best of 3: 30.6 ns per loop

sage: cython("""
cpdef empty():
    pass
""")
sage: timeit('empty()', number=10000000)
10000000 loops, best of 3: 31 ns per loop

sage: def add_with_citation(a, b):
....:     cite()
....:     return a + b
....: 
sage: def add(a, b):
....:     return a + b
....: 
sage: P.<x,y,z>=QQ[]
sage: f = x * y + z
sage: timeit('add(f, x)')
625 loops, best of 3: 1.2 µs per loop
sage: timeit('add_with_citation(f, x)')
625 loops, best of 3: 1.25 µs 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 http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to