#16296: Speed improvements for categories with axioms
-------------------------------------+-------------------------------------
       Reporter:  SimonKing          |        Owner:
           Type:  enhancement        |       Status:  new
       Priority:  major              |    Milestone:  sage-6.3
      Component:  categories         |   Resolution:
       Keywords:  cython             |    Merged in:
  performance categories             |    Reviewers:
        Authors:                     |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:                     |  d7f8250a1defbad2c5f3acb89d8f152a45d53523
  u/SimonKing/ticket/16296           |     Stopgaps:
   Dependencies:  #10963, #15801,    |
  #16309                             |
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 I switched `sage.categories.category` and
 `sage.categories.category_with_axiom` back to Python. Instead, I created a
 module with helper functions. Fortunately, `_sort_uniq` is a static
 method, and thus it is no problem to replace it with a cpdef function
 imported from the helper module.

 The current timings:
 {{{
 sage: from sage.categories.category_with_axiom import canonicalize_axioms,
 all_axioms
 sage: canonicalize_axioms(all_axioms, ["Commutative", "Connected",
 "Commutative", "WithBasis", "Finite"])
 ('Finite', 'Connected', 'WithBasis', 'Commutative')
 sage: %timeit canonicalize_axioms(all_axioms, L)
 100000 loops, best of 3: 3.83 µs per loop
 sage: L = [Coalgebras(QQ), Sets().Finite(), Algebras(ZZ),
 SimplicialComplexes()]
 sage: %timeit Category._sort(L)
 100000 loops, best of 3: 6.25 µs per loop
 sage: %timeit Category._sort_uniq(L)
 100000 loops, best of 3: 15.9 µs per loop
 sage: %timeit Category.join(L)
 10000 loops, best of 3: 816 µs per loop
 }}}
 Note: Since I want to keep `all_axioms` in
 `sage.categories.category_with_axiom`, I need to provide it to
 `canonicalize_axioms` (now defined in the helper module) as an argument.

 __Evaluation__

 - `canonicalize_axioms` is still fast, and so is (almost) `_sort_uniq`.
 - I kept `_sort` in for now, but it isn't used, and I'd simply remove it.
 - The join is now slow again, since it is Python.

 __Concerning join__

 Perhaps one could create another helper function for the join. It is
 static, hence, a cpdef function won't be a problem. However, it uses a
 cache. This cache should be local to `sage.categories.category.Category`,
 but when defining the `join` in the helper module, we'd like to have
 cython-speed access to it. OTOH, we could define the cache in the helper
 module, and then assign it as an attribute to `Category`, if we think that
 the cache is needed outside of the helper.

--
Ticket URL: <http://trac.sagemath.org/ticket/16296#comment:41>
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 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-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to