GDAL
gdallinearsystem.h
1/******************************************************************************
2 *
3 * Project: GDAL
4 * Purpose: Linear system solver
5 * Author: VIZRT Development Team.
6 *
7 ******************************************************************************
8 * Copyright (c) 2017 Alan Thomas <alant@outlook.com.au>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
31#ifndef GDALLINEARSYSTEM_H_INCLUDED
32#define GDALLINEARSYSTEM_H_INCLUDED
33
34#include <vector>
35/*
36 * Matrix class with double entries.
37 * The elements are stored in column major order in a vector.
38 */
39struct GDALMatrix
40{
42 GDALMatrix() = default;
45 GDALMatrix(int rows, int cols)
46 : n_rows(rows), n_cols(cols), v(rows * cols, 0.)
47 {
48 }
50 inline int getNumRows() const
51 {
52 return n_rows;
53 }
55 inline int getNumCols() const
56 {
57 return n_cols;
58 }
60 inline double &operator()(int row, int col)
61 {
62 return v[row + col * n_rows];
63 }
65 inline double operator()(int row, int col) const
66 {
67 return v[row + col * n_rows];
68 }
70 double const *data() const
71 {
72 return v.data();
73 }
75 double *data()
76 {
77 return v.data();
78 }
80 void resize(int iRows, int iCols)
81 {
82 n_rows = iRows;
83 n_cols = iCols;
84 v.clear();
85 v.resize(iRows * iCols);
86 }
87
88 private:
89 int n_rows = 0;
90 int n_cols = 0;
91 std::vector<double> v;
92};
93
94bool GDALLinearSystemSolve(GDALMatrix &A, GDALMatrix &RHS, GDALMatrix &X);
95
96#endif /* #ifndef GDALLINEARSYSTEM_H_INCLUDED */
97