Skip to content

Commit

Permalink
Add some suggestions from coderabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
markriegler committed Feb 7, 2025
1 parent 5ecb75d commit 087d8d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions splinepy/microstructure/tiles/snappy.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,10 @@ def create_tile(
"""

for param in [a, b, c, r, contact_length]:
if not isinstance(param, float):
raise TypeError(f"Invalid Type, {param} is not float")
if not isinstance(param, (int, float)):
raise TypeError(
f"Invalid Type, {param} is neither int nor float"
)
if param < 0:
raise ValueError("Invalid parameter, must be > 0.")

Expand Down
7 changes: 5 additions & 2 deletions splinepy/microstructure/tiles/tile_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ def check_params(self, parameters):
parameters.ravel() < upper_bounds
)
if not _np.all(within_bounds):
out_of_bounds = parameters[
~within_bounds.reshape(parameters.shape)
]
raise ValueError(
f"The parameters {parameters} must be within the following bounds: "
+ f"lower: {lower_bounds} and upper: {upper_bounds}"
f"The following parameters are out of bounds: {out_of_bounds}. ",
f"Expected bounds: lower: {lower_bounds} and upper: {upper_bounds}",
)

return True
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def heps():
"""
Perturbation/step size for finite difference evaluation of derivative/sensitivity.
The value 1e-4 is arbitrary, but is a a compromise between:
The value 1e-5 is arbitrary, but is a a compromise between:
- Being small enough to ensure the finite difference calculation being accurate
enough
- Being large enough to avoid round-off error in floating-point arithmetic
"""
return 1e-5
Expand Down
4 changes: 2 additions & 2 deletions tests/test_microtiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def test_invalid_parameter_values(tile_class, big_perturbation):
with raises(ValueError) as exc_info_low:
tile_creator.create_tile(parameters=parameters_too_low)
# Check if the exception message calls TileBase.check_params()
assert "must be within the following bounds: lower: " in str(
assert "The following parameters are out of bounds: " in str(
exc_info_low.value
), (
f"Tile class {tile_class.__name__} must call TileBase.check_params() and raise",
Expand All @@ -435,7 +435,7 @@ def test_invalid_parameter_values(tile_class, big_perturbation):
with raises(ValueError) as exc_info_high:
tile_creator.create_tile(parameters=parameters_too_high)
# Check if the exception message calls TileBase.check_params()
assert "must be within the following bounds: lower: " in str(
assert "The following parameters are out of bounds: " in str(
exc_info_high.value
), (
f"Tile class {tile_class.__name__} must call TileBase.check_params() and raise",
Expand Down

0 comments on commit 087d8d1

Please sign in to comment.