Opened 20 months ago
Closed 20 months ago
#27449 closed enhancement (fixed)
py3: fix all doctests in schemes/product_projective
Reported by: | chapoton | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.7 |
Component: | python3 | Keywords: | |
Cc: | Merged in: | ||
Authors: | Frédéric Chapoton | Reviewers: | Travis Scrimshaw |
Report Upstream: | N/A | Work issues: | |
Branch: | 9440e0a (Commits) | Commit: | 9440e0a567a9aac62dd853c9e102b5128488d757 |
Dependencies: | Stopgaps: |
Description
by adding a missing __len__
method.
plus some light code cleanup.
Change History (5)
comment:1 Changed 20 months ago by
- Branch set to u/chapoton/27449
- Commit set to 9440e0a567a9aac62dd853c9e102b5128488d757
- Status changed from new to needs_review
comment:2 Changed 20 months ago by
green bot, please review
comment:3 Changed 20 months ago by
- Reviewers set to Travis Scrimshaw
It turns out that it is actually faster to do a yield
statement in Python2 than give a generator object back for a single list:
sage: def gen(n): ....: return (x for x in range(n)) sage: def it(n): ....: for x in range(n): ....: yield x sage: %timeit len(list(gen(5))) 1000000 loops, best of 3: 1.15 µs per loop sage: %timeit len(list(it(5))) 1000000 loops, best of 3: 1.05 µs per loop sage: %timeit len(list(gen(100))) 100000 loops, best of 3: 5.18 µs per loop sage: %timeit len(list(it(100))) 100000 loops, best of 3: 4.64 µs per loop sage: %timeit len(list(gen(10000))) 1000 loops, best of 3: 402 µs per loop sage: %timeit len(list(it(10000))) 1000 loops, best of 3: 385 µs per loop
For a double, there ends up being not much noticable difference:
sage: def gen(n): ....: return (x*y for x in range(n) for y in range(n)) sage: def it(n): ....: for x in range(n): ....: for y in range(n): ....: yield x*y sage: %timeit len(list(gen(5))) 100000 loops, best of 3: 3.56 µs per loop sage: %timeit len(list(it(5))) 100000 loops, best of 3: 3.41 µs per loop sage: %timeit len(list(gen(100))) 1000 loops, best of 3: 530 µs per loop sage: %timeit len(list(it(100))) 1000 loops, best of 3: 534 µs per loop
I am not saying that anything needs to be changed (I actually like the simplicity of returning the generator), just pointing out some timings (this probably does not need to be super optimized anyways).
So LGTM.
comment:4 Changed 20 months ago by
- Status changed from needs_review to positive_review
comment:5 Changed 20 months ago by
- Branch changed from u/chapoton/27449 to 9440e0a567a9aac62dd853c9e102b5128488d757
- Resolution set to fixed
- Status changed from positive_review to closed
Note: See
TracTickets for help on using
tickets.
New commits:
py3: fix all doctests in schemes/product_projective/*