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 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
15#ifndef GDALLINEARSYSTEM_H_INCLUDED
16#define GDALLINEARSYSTEM_H_INCLUDED
17
18#include <vector>
19
20/*
21 * Matrix class with double entries.
22 * The elements are stored in column major order in a vector.
23 */
24 struct GDALMatrix
25{
27 GDALMatrix() = default;
28
31 GDALMatrix(int rows, int cols)
32 : n_rows(rows), n_cols(cols), v(rows * cols, 0.)
33 {
34 }
35
37 inline int getNumRows() const
38 {
39 return n_rows;
40 }
41
43 inline int getNumCols() const
44 {
45 return n_cols;
46 }
47
49 inline double &operator()(int row, int col)
50 {
51 return v[row + col * static_cast<size_t>(n_rows)];
52 }
53
55 inline double operator()(int row, int col) const
56 {
57 return v[row + col * static_cast<size_t>(n_rows)];
58 }
59
61 double const *data() const
62 {
63 return v.data();
64 }
65
67 double *data()
68 {
69 return v.data();
70 }
71
73 void resize(int iRows, int iCols)
74 {
75 n_rows = iRows;
76 n_cols = iCols;
77 v.clear();
78 v.resize(static_cast<size_t>(iRows) * iCols);
79 }
80
81 private:
82 int n_rows = 0;
83 int n_cols = 0;
84 std::vector<double> v;
85};
86
87 bool GDALLinearSystemSolve(GDALMatrix &A, GDALMatrix &RHS, GDALMatrix &X,
88 bool bForceBuiltinMethod = false);
89
90#endif /* #ifndef GDALLINEARSYSTEM_H_INCLUDED */
91