#6484: sage.combinat.ranker improvements
-------------------------------------+-------------------------------------
Reporter: nthiery | Owner: nthiery
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.4
Component: combinatorics | Resolution:
Keywords: rank, unrank | Merged in:
Authors: Nicolas M. ThiƩry | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/nthiery/sage_combinat_ranker_improvements|
220cf7c58941afb5e775842da73e2291a800e0d9
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by vdelecroix):
You know that with `@cached_function` instead of a plain dictionary you
are building a 2-tuple containg a tuple enclosing the object and an empty
tuple?
{{{
sage: r = rank_from_list(range(10))
sage: r.get_cache()
{((0,), ()): 0,
((1,), ()): 1,
((2,), ()): 2,
((3,), ()): 3,
((4,), ()): 4,
((5,), ()): 5,
((6,), ()): 6,
((7,), ()): 7,
((8,), ()): 8,
((9,), ()): 9}
}}}
What is wrong with
{{{
def rank_from_list(l):
my_dict = {j:i for i,j in enumerate(l)}
def rank(i):
return my_dict[i]
}}}
It is not very clean, but at least cleaner. And also faster by the way.
Vincent
--
Ticket URL: <http://trac.sagemath.org/ticket/6484#comment:16>
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.