From 35df246b90ddede5d4ad1ed3e15a5203ae14e89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 26 Jan 2025 13:41:36 +0100 Subject: [PATCH] inline an inner function in random two-sphere (for speed) --- src/sage/graphs/generators/random.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/sage/graphs/generators/random.py b/src/sage/graphs/generators/random.py index 821068763b3..76bd7bc50c4 100644 --- a/src/sage/graphs/generators/random.py +++ b/src/sage/graphs/generators/random.py @@ -2320,21 +2320,16 @@ def RandomTriangulation(n, set_position=False, k=3, seed=None): pattern = ['in', 'in', 'in', 'lf', 'in'] # 'partial closures' - def rotate_word_to_next_occurrence(word): - """ - Rotate ``word`` so that the given pattern occurs at the beginning. - - If the given pattern is not found, return the empty list. - """ + # We greedily perform the replacements 'in1,in2,in3,lf,in3'->'in1,in3'. + while True: + # first we rotate the word to it starts with pattern + word2 = [] N = len(word) for i in range(N): if all(word[(i + j) % N][0] == pattern[j] for j in range(5)): - return word[i:] + word[:i] - return [] + word2 = word[i:] + word[:i] + break - # We greedily perform the replacements 'in1,in2,in3,lf,in3'->'in1,in3'. - while True: - word2 = rotate_word_to_next_occurrence(word) if len(word2) >= 5: word = [word2[0]] + word2[4:] in1, in2, in3 = (u[1] for u in word2[:3])