-
Notifications
You must be signed in to change notification settings - Fork 49
Fix/qgis fixes #277
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
Fix/qgis fixes #277
Changes from all commits
8ab6bca
c049fa7
48823fe
23e0b21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,7 +62,9 @@ def __init__(self, support, data={}, c=None, up_to_date=False): | |||||||||||||||
| self.interpolation_weights = {} | ||||||||||||||||
| logger.info("Creating discrete interpolator with {} degrees of freedom".format(self.dof)) | ||||||||||||||||
| self.type = InterpolatorType.BASE_DISCRETE | ||||||||||||||||
|
|
||||||||||||||||
| self.apply_scaling_matrix = True | ||||||||||||||||
| self.add_ridge_regulatisation = True | ||||||||||||||||
| self.ridge_factor = 1e-8 | ||||||||||||||||
| def set_nelements(self, nelements: int) -> int: | ||||||||||||||||
| return self.support.set_nelements(nelements) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -511,6 +513,25 @@ def build_matrix(self): | |||||||||||||||
|
|
||||||||||||||||
| B = np.hstack(bs) | ||||||||||||||||
| return A, B | ||||||||||||||||
| def compute_column_scaling_matrix(self, A: sparse.csr_matrix) -> sparse.dia_matrix: | ||||||||||||||||
| """Compute column scaling matrix S for matrix A so that A @ S has columns with unit norm. | ||||||||||||||||
|
|
||||||||||||||||
| Parameters | ||||||||||||||||
| ---------- | ||||||||||||||||
| A : sparse.csr_matrix | ||||||||||||||||
| interpolation matrix | ||||||||||||||||
|
|
||||||||||||||||
| Returns | ||||||||||||||||
| ------- | ||||||||||||||||
| scipy.sparse.dia_matrix | ||||||||||||||||
| diagonal scaling matrix S | ||||||||||||||||
| """ | ||||||||||||||||
| col_norms = sparse.linalg.norm(A, axis=0) | ||||||||||||||||
| scaling_factors = np.ones(A.shape[1]) | ||||||||||||||||
| mask = col_norms > 0 | ||||||||||||||||
| scaling_factors[mask] = 1.0 / col_norms[mask] | ||||||||||||||||
| S = sparse.diags(scaling_factors) | ||||||||||||||||
| return S | ||||||||||||||||
|
|
||||||||||||||||
| def add_equality_block(self, A, B): | ||||||||||||||||
| if len(self.equal_constraints) > 0: | ||||||||||||||||
|
|
@@ -591,6 +612,15 @@ def solve_system( | |||||||||||||||
| raise ValueError("Pre solve failed") | ||||||||||||||||
|
|
||||||||||||||||
| A, b = self.build_matrix() | ||||||||||||||||
| if self.add_ridge_regulatisation: | ||||||||||||||||
| ridge = sparse.eye(A.shape[1]) * self.ridge_factor | ||||||||||||||||
| A = sparse.vstack([A, ridge]) | ||||||||||||||||
| b = np.hstack([b, np.zeros(A.shape[1])]) | ||||||||||||||||
| logger.info("Adding ridge regularisation to interpolation matrix") | ||||||||||||||||
|
||||||||||||||||
| logger.info("Adding ridge regularisation to interpolation matrix") | |
| logger.info("Adding ridge regularization to interpolation matrix") |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment appears to contain commented-out code.
| # if 'atol' not in solver_kwargs: | |
| # if tol is not None: | |
| # solver_kwargs['atol'] = tol |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expression mutates a default value.
This expression mutates a default value.
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable S is only defined when self.apply_scaling_matrix is True (line 621), but this code path can be reached through multiple solver branches (callable, cg, lsmr, admm, unknown solver) where S might not be in scope. If apply_scaling_matrix is False initially but somehow becomes True, or if an error path is taken, S will be undefined. The variable should be initialized to None at the start of the method, or this block should be moved inside the earlier if self.apply_scaling_matrix block.
| self.c = S @ self.c | |
| S = locals().get("S", None) | |
| if S is None: | |
| logger.error("Scaling matrix S is not defined; skipping scaling of solution.") | |
| self.up_to_date = False | |
| else: | |
| self.c = S @ self.c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'regulatisation' to 'regularisation'.