Skip to content

Commit bc80fe6

Browse files
Copilotlachlangrose
andcommitted
Address code review comments: fix validation, spelling, scope, and mutable defaults
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
1 parent 6720103 commit bc80fe6

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

LoopStructural/interpolators/_discrete_interpolator.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, support, data={}, c=None, up_to_date=False):
6363
logger.info("Creating discrete interpolator with {} degrees of freedom".format(self.dof))
6464
self.type = InterpolatorType.BASE_DISCRETE
6565
self.apply_scaling_matrix = True
66-
self.add_ridge_regulatisation = True
66+
self.add_ridge_regularisation = True
6767
self.ridge_factor = 1e-8
6868
def set_nelements(self, nelements: int) -> int:
6969
return self.support.set_nelements(nelements)
@@ -588,7 +588,7 @@ def solve_system(
588588
self,
589589
solver: Optional[Union[Callable[[sparse.csr_matrix, np.ndarray], np.ndarray], str]] = None,
590590
tol: Optional[float] = None,
591-
solver_kwargs: dict = {},
591+
solver_kwargs: dict = None,
592592
) -> bool:
593593
"""
594594
Main entry point to run the solver and update the node value
@@ -608,15 +608,18 @@ def solve_system(
608608
True if the interpolation is run
609609
610610
"""
611+
if solver_kwargs is None:
612+
solver_kwargs = {}
611613
if not self._pre_solve():
612614
raise ValueError("Pre solve failed")
613615

616+
S = None # Initialize scaling matrix
614617
A, b = self.build_matrix()
615-
if self.add_ridge_regulatisation:
618+
if self.add_ridge_regularisation:
616619
ridge = sparse.eye(A.shape[1]) * self.ridge_factor
617620
A = sparse.vstack([A, ridge])
618621
b = np.hstack([b, np.zeros(A.shape[1])])
619-
logger.info("Adding ridge regularisation to interpolation matrix")
622+
logger.info("Adding ridge regularization to interpolation matrix")
620623
if self.apply_scaling_matrix:
621624
S = self.compute_column_scaling_matrix(A)
622625
A = A @ S
@@ -650,9 +653,6 @@ def solve_system(
650653

651654
elif solver == 'lsmr':
652655
logger.info("Solving using lsmr")
653-
# if 'atol' not in solver_kwargs:
654-
# if tol is not None:
655-
# solver_kwargs['atol'] = tol
656656
if 'btol' not in solver_kwargs:
657657
if tol is not None:
658658
solver_kwargs['btol'] = tol
@@ -718,7 +718,11 @@ def solve_system(
718718
# self._post_solve()
719719
# apply scaling matrix to solution
720720
if self.apply_scaling_matrix:
721-
self.c = S @ self.c
721+
if S is None:
722+
logger.error("Scaling matrix S is not defined; skipping scaling of solution.")
723+
self.up_to_date = False
724+
else:
725+
self.c = S @ self.c
722726
return self.up_to_date
723727

724728
def update(self) -> bool:

LoopStructural/modelling/features/builders/_fault_builder.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,12 @@ def fault_normal_vector(self, v):
141141
if v is None:
142142
self._fault_normal_vector = None
143143
else:
144-
if len(v.shape) != 1 or v.shape[0] != 3:
145-
raise ValueError("fault_normal_vector must be a 3 element array")
146-
if v.ndim != 1:
147-
v = v[0,:]
148-
if v.shape[0] != 3:
149-
raise ValueError("fault_normal_vector must be a 3 element array")
150144
arr = np.array(v, dtype=float)
145+
# If more than 1D, take the first row and then validate length
146+
if arr.ndim > 1:
147+
arr = arr[0]
148+
if arr.shape[0] != 3:
149+
raise ValueError("fault_normal_vector must be a 3 element array")
151150
norm = np.linalg.norm(arr)
152151
if norm == 0:
153152
raise ValueError("fault_normal_vector cannot be the zero vector")

0 commit comments

Comments
 (0)