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

Consolidated handling of single variables vs arrays of variables #250

Open
alhom opened this issue Jun 19, 2024 · 0 comments
Open

Consolidated handling of single variables vs arrays of variables #250

alhom opened this issue Jun 19, 2024 · 0 comments

Comments

@alhom
Copy link
Contributor

alhom commented Jun 19, 2024

The following pattern is repeated often, used to handle cases where both single cellids and lists of cellids are supported as function arguments. Vectorized operations are preferred for speed, so (often) single cellid arguments are expanded into numpy arrays to be able to handle the computations in vectorized form without duplicate code.

It might be possible to handle these cases with a function decorator-wrapper, and would simplify the code quite a bit (and help with handling e.g. several return paths).

      stack = True
      if not hasattr(cellid,"__len__"):
         cellid = np.atleast_1d(cellid)
         stack = False
      # .
      # .
      # .
      if stack:
         return AMR_count - 1 
      else:
         return (AMR_count - 1)[0]

Example:
Start:

stack = True

End:
if stack:

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

No branches or pull requests

1 participant