Skip to content

Commit 35df246

Browse files
committed
inline an inner function in random two-sphere (for speed)
1 parent 5188024 commit 35df246

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/sage/graphs/generators/random.py

Lines changed: 6 additions & 11 deletions
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)