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

.random_element() stalls for Tuples #39534

Open
2 tasks done
maxale opened this issue Feb 15, 2025 · 1 comment
Open
2 tasks done

.random_element() stalls for Tuples #39534

maxale opened this issue Feb 15, 2025 · 1 comment

Comments

@maxale
Copy link
Contributor

maxale commented Feb 15, 2025

Steps To Reproduce

The following code does not produce a result:

sage: Tuples(range(3),30).random_element()

Expected Behavior

Generating a random tuple should be instantaneous. For the example given above it can be done along these lines:

sage: myrange = list(range(3))
sage: [choice(myrange) for _ in range(30)]

Actual Behavior

Call to .random_element() stalls.

Additional Information

No response

Environment

  • OS: Ubuntu 24.04.2 LTS
  • Sage Version: 10.6.beta5

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@DaveWitteMorris
Copy link
Member

i think the problem is that Tuples uses the generic implementation of __getitem__ that is defined for all enumerated sets: to find T[n], it goes through the tuples one at a time until the nth one is reached. (Technically, unrank is called directly, instead of __getitem__, because __getitem__ is basically a wrapper around unrank.) This should be easy to fix by providing Tuples with a custom unrank method that constructs T[n] directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants