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

inline an inner function in random two-sphere (for speed) #39380

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/sage/graphs/generators/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Loading