forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sagemathgh-36308: using itertools.product more often
This replaces some uses of our `cartesian_product_iterator` by `itertools.product`, for better efficiency. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: sagemath#36308 Reported by: Frédéric Chapoton Reviewer(s): Marc Mezzarobba
- Loading branch information
Showing
17 changed files
with
51 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
tarball=configure-VERSION.tar.gz | ||
sha1=b2c2a31975aecc02df78e38082e915419c3354e6 | ||
md5=2441f31fbe9e5a3ca1f6070fcee5e42c | ||
cksum=4212643350 | ||
sha1=b6d662b1301c2ef342d28ffa22c6f09be4ead821 | ||
md5=e7ed474499cb651b218ef6ab4f1b3285 | ||
cksum=1633939417 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
f32860b2015ad42b5cb9c30a0af1351e597bf314 | ||
821c5f5d7e9ab1476094459252ae9b42de71cf98 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,23 +45,22 @@ | |
- Raghukul Raman <[email protected]> (2018): Added sieve algorithm | ||
""" | ||
|
||
#***************************************************************************** | ||
# **************************************************************************** | ||
# Copyright (C) 2010 William Stein, David Kohel, John Cremona, Charlie Turner | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# http://www.gnu.org/licenses/ | ||
#***************************************************************************** | ||
|
||
# https://www.gnu.org/licenses/ | ||
# **************************************************************************** | ||
from itertools import product | ||
|
||
from sage.arith.misc import gcd, next_prime, previous_prime, crt | ||
from sage.arith.srange import srange | ||
from sage.rings.integer_ring import ZZ | ||
from sage.rings.real_mpfr import RR | ||
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF | ||
from sage.misc.mrange import cartesian_product_iterator | ||
from sage.misc.misc_c import prod | ||
from sage.misc.mrange import xmrange | ||
from sage.schemes.generic.scheme import is_Scheme | ||
|
@@ -140,7 +139,7 @@ def enum_projective_rational_field(X, B): | |
n = X.codomain().ambient_space().ngens() | ||
zero = (0,) * n | ||
pts = [] | ||
for c in cartesian_product_iterator([srange(-B,B+1) for _ in range(n)]): | ||
for c in product(*[srange(-B, B + 1) for _ in range(n)]): | ||
if gcd(c) == 1 and c > zero: | ||
try: | ||
pts.append(X(c)) | ||
|
@@ -296,13 +295,13 @@ def enum_projective_finite_field(X): | |
elif not is_ProjectiveSpace(X.codomain().ambient_space()): | ||
raise TypeError("codomain must be projective space over a finite field") | ||
|
||
n = X.codomain().ambient_space().ngens()-1 | ||
n = X.codomain().ambient_space().ngens() - 1 | ||
F = X.value_ring() | ||
pts = [] | ||
for k in range(n+1): | ||
for c in cartesian_product_iterator([F for _ in range(k)]): | ||
for k in range(n + 1): | ||
for c in product(*[F for _ in range(k)]): | ||
try: | ||
pts.append(X(list(c)+[1]+[0]*(n-k))) | ||
pts.append(X(list(c) + [1] + [0] * (n - k))) | ||
except TypeError: | ||
pass | ||
pts.sort() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.