Class: QgsMatrixSolver¶
Contains utility functions for solving matrix operations.
This utility class is designed to solve systems of linear equations in
the form Ax = b using LU decomposition.
Note
In situations where many linear systems need to be solved sequentially this class
supports a preallocation strategy. By constructing the solver initially with a maximumDimension
(where maximumDimension is N for the largest N × N matrix to solve),
all backend memory is allocated upfront. Subsequent calls to solve() using a specified dimension
create zero-allocation views into this memory block. This guarantees that no heap
allocations occur during calculations.
Warning
This class requires a QGIS build with the GSL library enabled. See isAvailable() to determine
if the current system supports its functionality.
Added in version 4.4.
List of all members, including inherited members
Constructor
Methods
Returns the maximum dimension supported by this solver. |
|
Sets a value in the preallocated right-hand-side vector b. |
|
Sets the value for row, column in the preallocated matrix A. |
|
Solves the system |
Static Methods
Returns |
- class qgis.core.QgsMatrixSolver[source]¶
Bases:
object- __init__(maximumDimension: int)¶
Constructor for QgsMatrixSolver, pre-allocated to solve matrices with the specified
maximumDimension.- Parameters:
maximumDimension (int) – The dimension
Nfor the largestN × NmatrixAto solve with this object. (E.g. 4 if a4 × 4matrix is the largestAto solve.)
- static isAvailable() bool[source]¶
Returns
Trueif the matrix solver functionality is available on the current system.- Return type:
bool
- maximumDimension(self) int[source]¶
Returns the maximum dimension supported by this solver.
- Return type:
int
- setRightHandSide(self, row: int, value: float)[source]¶
Sets a value in the preallocated right-hand-side vector
b.- Parameters:
row (int) – The row index (0-based)
value (float) – The value to insert
- Raises:
QgsNotSupportedException – for QGIS builds without GSL support.
IndexError – if the row index is out of bounds.
- setValue(self, row: int, column: int, value: float)[source]¶
Sets the
valueforrow,columnin the preallocated matrixA.- Parameters:
row (int) – The row index (0-based)
column (int) – The column index (0-based)
value (float) – The value to insert
- Raises:
QgsNotSupportedException – for QGIS builds without GSL support.
IndexError – if the row or column index is out of bounds.
- solve(self, dimension: int, method: Qgis.LinearMatrixMethod = Qgis.LinearMatrixMethod.Lu)[source]¶
Solves the system
Ax = bfor a specific active dimension.- Parameters:
dimension (int) – The dimension
Nfor theN × Nsub-matrix to solve.method (Qgis.LinearMatrixMethod = Qgis.LinearMatrixMethod.Lu) – Solving strategy to use
- Return type:
(bool, list[float])
- Returns:
Trueon success,Falseif the matrix is singular and could not be solved.result: Solution vector
x
- Raises:
QgsNotSupportedException – for QGIS builds without GSL support.
QgsInvalidArgumentException – for invalid
dimensionvalues