Skip to content

Commit 844c7d6

Browse files
author
Release Manager
committed
gh-39380: inline an inner function in random two-sphere (for speed) to avoid a function call, in order to get a little more speed ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #39380 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents e1447d3 + 35df246 commit 844c7d6

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/sage/graphs/generators/random.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -2320,21 +2320,16 @@ def RandomTriangulation(n, set_position=False, k=3, seed=None):
23202320

23212321
pattern = ['in', 'in', 'in', 'lf', 'in'] # 'partial closures'
23222322

2323-
def rotate_word_to_next_occurrence(word):
2324-
"""
2325-
Rotate ``word`` so that the given pattern occurs at the beginning.
2326-
2327-
If the given pattern is not found, return the empty list.
2328-
"""
2323+
# We greedily perform the replacements 'in1,in2,in3,lf,in3'->'in1,in3'.
2324+
while True:
2325+
# first we rotate the word to it starts with pattern
2326+
word2 = []
23292327
N = len(word)
23302328
for i in range(N):
23312329
if all(word[(i + j) % N][0] == pattern[j] for j in range(5)):
2332-
return word[i:] + word[:i]
2333-
return []
2330+
word2 = word[i:] + word[:i]
2331+
break
23342332

2335-
# We greedily perform the replacements 'in1,in2,in3,lf,in3'->'in1,in3'.
2336-
while True:
2337-
word2 = rotate_word_to_next_occurrence(word)
23382333
if len(word2) >= 5:
23392334
word = [word2[0]] + word2[4:]
23402335
in1, in2, in3 = (u[1] for u in word2[:3])

0 commit comments

Comments
 (0)