Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py3: fix all doctests in schemes/product_projective #27449

Closed
fchapoton opened this issue Mar 9, 2019 · 7 comments
Closed

py3: fix all doctests in schemes/product_projective #27449

fchapoton opened this issue Mar 9, 2019 · 7 comments

Comments

@fchapoton
Copy link
Contributor

by adding a missing __len__ method.

plus some light code cleanup.

Component: python3

Author: Frédéric Chapoton

Branch/Commit: 9440e0a

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/27449

@fchapoton fchapoton added this to the sage-8.7 milestone Mar 9, 2019
@fchapoton
Copy link
Contributor Author

Branch: u/chapoton/27449

@fchapoton
Copy link
Contributor Author

Commit: 9440e0a

@fchapoton
Copy link
Contributor Author

New commits:

9440e0apy3: fix all doctests in schemes/product_projective/*

@fchapoton
Copy link
Contributor Author

comment:2

green bot, please review

@tscrim
Copy link
Collaborator

tscrim commented Mar 9, 2019

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Mar 9, 2019

comment:3

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.

@vbraun
Copy link
Member

vbraun commented Mar 11, 2019

Changed branch from u/chapoton/27449 to 9440e0a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants