QGIS API Documentation 4.3.0-Master (d3b565c628d)
Loading...
Searching...
No Matches
qgsmatrixsolver.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmatrixsolver.h
3 ----------------------
4 begin : August 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgis.h"
17#include "qgis_core.h"
18#include "qgis_sip.h"
19
20#include <QObject>
21
22#ifndef QGSMATRIXSOLVER_H
23#define QGSMATRIXSOLVER_H
24
44class CORE_EXPORT QgsMatrixSolver
45{
46 public:
50 static bool isAvailable();
51
58 explicit QgsMatrixSolver( int maximumDimension );
59
61
62#ifndef SIP_RUN
63 QgsMatrixSolver( const QgsMatrixSolver & ) = delete;
65#endif
66
70 int maximumDimension() const;
71
72#ifndef SIP_RUN
84 void setValue( int row, int column, double value );
85#else
86 // clang-format off
87
98 void setValue( int row, int column, double value );
99 % MethodCode
100 const int maximumDimension = sipCpp->maximumDimension();
102 {
103 PyErr_SetString( sipException_QgsNotSupportedException, "QgsMatrixSolver requires a QGIS build with GSL support enabled" );
104 sipIsErr = 1;
105 }
106 else if ( a0 < 0 || a0 >= maximumDimension )
107 {
108 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
109 sipIsErr = 1;
110 }
111 else if ( a1 < 0 || a1 >= maximumDimension )
112 {
113 PyErr_SetString( PyExc_IndexError, QByteArray::number( a1 ) );
114 sipIsErr = 1;
115 }
116 else
117 {
118 sipCpp->setValue( a0, a1, a2 );
119 }
120 % End
121// clang-format on
122#endif
123
124#ifndef SIP_RUN
135 void setRightHandSide( int row, double value );
136#else
137 // clang-format off
138
146 void setRightHandSide( int row, double value ) SIP_THROW( QgsNotSupportedException );
147 % MethodCode
148 const int maximumDimension = sipCpp->maximumDimension();
150 {
151 PyErr_SetString( sipException_QgsNotSupportedException, "QgsMatrixSolver requires a QGIS build with GSL support enabled" );
152 sipIsErr = 1;
153 }
154 else if ( a0 < 0 || a0 >= maximumDimension )
155 {
156 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
157 sipIsErr = 1;
158 }
159 else
160 {
161 sipCpp->setRightHandSide( a0, a1 );
162 }
163 % End
164 // clang-format on
165#endif
166
179 bool solve( int dimension, QVector<double> &result SIP_OUT, Qgis::LinearMatrixMethod method = Qgis::LinearMatrixMethod::Lu ) SIP_THROW( QgsNotSupportedException, QgsInvalidArgumentException );
180
181 private:
182#ifdef SIP_RUN
183 QgsMatrixSolver( const QgsMatrixSolver & );
184#endif
185
186 bool solveLu( int dimension, QVector<double> &result, bool retainOriginalMatrices );
187 bool solveSvd( int dimension, QVector<double> &result, bool retainOriginalMatrices );
188
189 struct GslData;
190 std::unique_ptr<GslData> mData;
191};
192
193#endif // QGSMATRIXSOLVER_H
LinearMatrixMethod
Mathematical methods to use for solving linear matrix equations.
Definition qgis.h:7095
@ Lu
Fast lower-upper (LU) decomposition (fails on singular/collinear matrices).
Definition qgis.h:7096
QgsMatrixSolver(int maximumDimension)
Constructor for QgsMatrixSolver, pre-allocated to solve matrices with the specified maximumDimension.
QgsMatrixSolver(const QgsMatrixSolver &)=delete
void setValue(int row, int column, double value)
Sets the value for row, column in the preallocated matrix A.
QgsMatrixSolver & operator=(const QgsMatrixSolver &)=delete
int maximumDimension() const
Returns the maximum dimension supported by this solver.
static bool isAvailable()
Returns true if the matrix solver functionality is available on the current system.
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_THROW(name,...)
Definition qgis_sip.h:215