#11734: sage_wraps should only read the sources of wrapped functions when
needed.
--------------------------+-------------------------------------------------
Reporter: SimonKing | Owner: jason
Type: defect | Status: needs_review
Priority: blocker | Milestone: sage-4.7.2
Component: misc | Keywords: sage_wraps sources gentoo
startuptime sd32
Work_issues: | Upstream: N/A
Reviewer: Simon King | Author: Julian Rueth
Merged: | Dependencies:
--------------------------+-------------------------------------------------
Comment(by SimonKing):
Replying to [comment:17 saraedum]:
> Anyway, I would leave the doctest in; probably we should add a comment,
describing this difference.
OK, please do!
> The speedup is actually a little bit mysterious. It occurs once you
remove a few ''sage_wraps'' decorators. Apparently python's
''inspect.ArgSpec'' does something smart once it gets called very often
(to speed up things?) which results in a slowdown in our case.
You removed a few sage_wraps for a test?
Actually I find the speedup not mysterious. The 10% are just with your
patch, i.e., I did not additionally remove sage_wraps. And the reason for
the speedup is clear: Python's `inspect.getargspec` is insufficient for
Sage. It can not deal with Cython functions, and of course it can not
understand the special wrappers in Sage:
{{{
sage: import inspect
sage: cython('cpdef f(a,b,c=None): pass')
sage: inspect.getargspec(f)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/mnt/local/king/SAGE/sage-4.7.2.alpha2/devel/sage-main/<ipython console>
in <module>()
/mnt/local/king/SAGE/sage-4.7.2.alpha2/local/lib/python/inspect.pyc in
getargspec(func)
801 func = func.im_func
802 if not isfunction(func):
--> 803 raise TypeError('arg is not a Python function')
804 args, varargs, varkw = getargs(func.func_code)
805 return ArgSpec(args, varargs, varkw, func.func_defaults)
TypeError: arg is not a Python function
}}}
and similarly
{{{
sage: P.<x,y,z> = QQ[]
sage: I = P*[x,y]
sage: inspect.getargspec(I.interreduced_basis)
ArgSpec(args=[], varargs='args', keywords='kwds', defaults=None)
sage: inspect.getargspec(I.groebner_basis)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/mnt/local/king/SAGE/sage-4.7.2.alpha2/devel/sage-main/<ipython console>
in <module>()
/mnt/local/king/SAGE/sage-4.7.2.alpha2/local/lib/python/inspect.pyc in
getargspec(func)
801 func = func.im_func
802 if not isfunction(func):
--> 803 raise TypeError('arg is not a Python function')
804 args, varargs, varkw = getargs(func.func_code)
805 return ArgSpec(args, varargs, varkw, func.func_defaults)
TypeError: arg is not a Python function
}}}
while the Sage autoinspection finds
{{{
sage: from sage.misc.sageinspect import sage_getargspec
sage: sage_getargspec(I.interreduced_basis)
ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None)
sage: sage_getargspec(I.groebner_basis)
ArgSpec(args=['self', 'algorithm', 'deg_bound', 'mult_bound', 'prot'],
varargs='args', keywords='kwds', defaults=('', None, None, False))
}}}
In the most difficult cases, `sage_getargspec` actually needs to read the
source (using `sage_getsourcelines`) and analyse the function definition.
That's why inspect.getargspec is faster (yet a lot less powerful) than
sage.misc.sageinspect.sage_getargspec.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11734#comment:18>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.