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

sets used instead of lists when membership testing #3021

Merged

Conversation

shimwell
Copy link
Member

@shimwell shimwell commented Jun 2, 2024

Description

I think this will make nearly no difference on speed and we probably don't want to worry about the speed of python code. However I think sets are slightly quicker for membership checking compared to lists. Although they might be slower to create in the first place. Perhaps it makes sense to make these constants sets as they are used in the cv.checkvalue to check the user input is in the available options.

Also I noticed one defined constant that is not used _XS_SHAPES so I've removed that

Checklist

  • I have performed a self-review of my own code
  • I have followed the style guidelines for Python source files (if applicable)

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shimwell In most cases here, you are changing an object from a list [a, b, c] to a tuple (a, b, c) instead of a set {a, b, c}. For some cases (e.g., _SUBSHELLS), it will definitely need to be a list or a tuple because the object is indexed. For many other cases, a set would be preferred if all it is being used for is membership tests. Can you go through this PR again and use sets where they are appropriate?

openmc/filter.py Outdated Show resolved Hide resolved
openmc/arithmetic.py Outdated Show resolved Hide resolved
openmc/arithmetic.py Outdated Show resolved Hide resolved
openmc/filter.py Outdated Show resolved Hide resolved
openmc/mgxs_library.py Outdated Show resolved Hide resolved
openmc/mgxs_library.py Outdated Show resolved Hide resolved
openmc/mgxs_library.py Outdated Show resolved Hide resolved
openmc/mgxs_library.py Outdated Show resolved Hide resolved
openmc/plots.py Outdated Show resolved Hide resolved
openmc/plotter.py Outdated Show resolved Hide resolved
openmc/plotter.py Outdated Show resolved Hide resolved
openmc/plotter.py Outdated Show resolved Hide resolved
openmc/plotter.py Outdated Show resolved Hide resolved
openmc/search.py Outdated Show resolved Hide resolved
openmc/settings.py Outdated Show resolved Hide resolved
openmc/stats/univariate.py Outdated Show resolved Hide resolved
openmc/stats/univariate.py Outdated Show resolved Hide resolved
openmc/surface.py Outdated Show resolved Hide resolved
@shimwell
Copy link
Member Author

Sorry about this mess of a PR, I got mixed up with suggesting tuples for their immutability as I think gives us a bit more safety that using lists and suggesting using sets defined like this set() instead of {} and I forgot to add the set and ended up going for tuples.

I shall work through these corrections and see if we index them prior to committing them

@paulromano paulromano enabled auto-merge (squash) June 19, 2024 13:27
@paulromano paulromano merged commit 84f561c into openmc-dev:develop Jun 19, 2024
17 checks passed
church89 pushed a commit to openmsr/openmc that referenced this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants