#11943: The category graph should comply with Python's method resolution order
---------------------------+------------------------------------------------
Reporter: SimonKing | Owner: nthiery
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-4.7.3
Component: categories | Keywords: category graph, method resolution
order
Work_issues: | Upstream: N/A
Reviewer: | Author: Simon King
Merged: | Dependencies: #11900
---------------------------+------------------------------------------------
Comment(by SimonKing):
I found another detail that may fit here: `Category.is_subcategory`
contains the lines
{{{
assert(isinstance(c, Category))
if isinstance(self, JoinCategory):
for cat in self._super_categories:
if cat.is_subcategory(c):
return True
return False
}}}
First, I don't see why it should be needed to assert that c is a Category.
It seems like a waste of time to me.
Secondly, the loop does nothing more than to test the cat is in the set of
super categories of self. So, it can be safely erased. And it is a lot
faster. For example:
With my current patch, we have
{{{
sage: P.<x,y> = QQ[]
sage: C = CommutativeRings()
sage: P.category()
Join of Category of unique factorization domains and Category of
commutative algebras over Rational Field
sage: P in C
True
sage: %timeit P in C
625 loops, best of 3: 12.1 µs per loop
}}}
With my patch after deletion of the lines criticised above, we have
{{{
sage: P.<x,y> = QQ[]
sage: C = CommutativeRings()
sage: P.category()
Join of Category of unique factorization domains and Category of
commutative algebras over Rational Field
sage: P in C
True
sage: %timeit P in C
625 loops, best of 3: 6.39 µs per loop
}}}
So, my next patch version will remove these lines, provided that doc tests
pass.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11943#comment:15>
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.