Skip to content

Commit

Permalink
Add checks for set_value to ensure arrays are right size
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Aug 28, 2024
1 parent 81b820b commit 09f4304
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PyStemmusScope/bmi/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ def set_value(self, name: str, src: np.ndarray) -> None:
"""
if self.state is None:
raise ValueError(NO_STATE_MSG)
if src.size != self.get_grid_size(self.get_var_grid(name)):
msg = f"Size of `src` and variable '{name}' grid size are not equal!"
raise ValueError(msg)
self.state = set_variable(self.state, name, src)

def set_value_at_indices(
Expand All @@ -433,6 +436,9 @@ def set_value_at_indices(
"""
if self.state is None:
raise ValueError(NO_STATE_MSG)
if inds.size != src.size:
msg = "Sizes of `inds` and `src` are not equal!"
raise ValueError(msg)
self.state = set_variable(self.state, name, src, inds)

### GRID INFO ###
Expand Down

0 comments on commit 09f4304

Please sign in to comment.