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

__init__

Methods

maximumDimension

Returns the maximum dimension supported by this solver.

setRightHandSide

Sets a value in the preallocated right-hand-side vector b.

setValue

Sets the value for row, column in the preallocated matrix A.

solve

Solves the system Ax = b for a specific active dimension.

Static Methods

isAvailable

Returns True if the matrix solver functionality is available on the current system.

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 N for the largest N × N matrix A to solve with this object. (E.g. 4 if a 4 × 4 matrix is the largest A to solve.)

static isAvailable() bool[source]

Returns True if 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:
setValue(self, row: int, column: int, value: float)[source]

Sets the value for row, column in the preallocated matrix A.

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 = b for a specific active dimension.

Parameters:
  • dimension (int) – The dimension N for the N × N sub-matrix to solve.

  • method (Qgis.LinearMatrixMethod = Qgis.LinearMatrixMethod.Lu) – Solving strategy to use

Return type:

(bool, list[float])

Returns:

  • True on success, False if the matrix is singular and could not be solved.

  • result: Solution vector x

Raises: