#19319: iterator over pairs on diagonals a la Cantor pairing
-------------------------------------+-------------------------------------
Reporter: dkrenn | Owner:
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.9
Component: misc | Resolution:
Keywords: | Merged in:
Authors: Daniel Krenn | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/dkrenn/product_cantor_pairing | 70185c3a13f573cf1eacbec2eb2122082e6c375f
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by cheuberg):
I have an alternative implementation (pushed as
`u/cheuberg/product_cantor_pairing`):
{{{
from itertools import count
from sage.rings.infinity import infinity
A = iter(A)
B = iter(B)
max_A = infinity
max_B = infinity
cache_A = []
cache_B = []
for s in count():
if s <= max_A:
try:
cache_A.append(next(A))
except StopIteration:
max_A = s-1
if s <= max_B:
try:
cache_B.append(next(B))
except StopIteration:
max_B = s-1
if s > max_A + max_B or max_A < 0 or max_B < 0:
return
for i in range(max(0, s-max_B), min(s, max_A)+1):
yield cache_A[i], cache_B[s-i]
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/19319#comment:21>
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.