#10496: The default call method of maps does not do as promised by the
documentation
--------------------------+-------------------------------------------------
Reporter: SimonKing | Owner: robertwb
Type: defect | Status: needs_work
Priority: major | Milestone: sage-4.6.2
Component: coercion | Keywords: generic call map
Author: Simon King | Upstream: N/A
Reviewer: David Roe | Merged:
Work_issues: |
--------------------------+-------------------------------------------------
Comment(by SimonKing):
Replying to [comment:2 roed]:
> I think you need to add some fast pathways for common cases, such as `x`
actually lying in the domain.
Right, I'll do so. Note that I use `parent_c` (copied from
`sage.structure.parent`) in order to speed things up.
What common cases, apart from `parent_c(x) is self._domain`, do you have
in mind?
> Similarly, use `PY_TYPE_CHECK` in cython files, rather than
`isinstance`.
My patch introduces only one "isinstance", namely in the call method of
`Set_Python_class`. The updated patch (hopefully being submitted in an
hour or so) will use `PY_TYPE_CHECK` instead.
A propos: I was not aware of that Cython alternative to `is_instance`. Can
you point me to a documentation of these and similar `PY_...` Cython
functions?
I also found another way to speed the generic call method up: The current
implementation does
{{{
if len(args) == 0 and len(kwds) == 0:
return self._call_(x)
}}}
Using `timeit", I found that `if not(args) and not(kwds)` would be much
faster:
{{{
sage: args=tuple(ZZ.random_element() for i in range(3))
sage: kwds=dict((i,ZZ.random_element()) for i in range(3))
sage: args0=()
sage: kwds0={}
sage: timeit("if len(args)==0 and len(kwds)==0: a=2")
625 loops, best of 3: 3.37 µs per loop
sage: timeit("if len(args0)==0 and len(kwds)==0: a=2")
625 loops, best of 3: 6.76 µs per loop
sage: timeit("if len(args0)==0 and len(kwds0)==0: a=2")
625 loops, best of 3: 7.21 µs per loop
sage: timeit("if not args and not kwds: a=2")
625 loops, best of 3: 129 ns per loop
sage: timeit("if not args0 and not kwds: a=2")
625 loops, best of 3: 275 ns per loop
sage: timeit("if not args0 and not kwds0: a=2")
625 loops, best of 3: 597 ns per loop
}}}
So, I'll change the patch accordingly.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10496#comment:3>
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.