Coverage Report

Created: 2025-06-13 06:18

/src/gdal/alg/gdallinearsystem.h
Line
Count
Source (jump to first uncovered line)
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
13
/*! @cond Doxygen_Suppress */
14
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
{
26
    /// Creates a matrix with zero rows and columns.
27
    GDALMatrix() = default;
28
29
    /// Creates a matrix with \a rows rows and \a col columns
30
    /// Its elements are initialized to 0.
31
    GDALMatrix(int rows, int cols)
32
0
        : n_rows(rows), n_cols(cols), v(rows * cols, 0.)
33
0
    {
34
0
    }
35
36
    /// Returns the number or rows of the matrix
37
    inline int getNumRows() const
38
0
    {
39
0
        return n_rows;
40
0
    }
41
42
    /// Returns the number or columns of the matrix.
43
    inline int getNumCols() const
44
0
    {
45
0
        return n_cols;
46
0
    }
47
48
    /// Returns the reference to the element at the position \a row, \a col.
49
    inline double &operator()(int row, int col)
50
0
    {
51
0
        return v[row + col * static_cast<size_t>(n_rows)];
52
0
    }
53
54
    /// Returns the element at the position \a row, \a col by value.
55
    inline double operator()(int row, int col) const
56
0
    {
57
0
        return v[row + col * static_cast<size_t>(n_rows)];
58
0
    }
59
60
    /// Returns the values of the matrix in column major order.
61
    double const *data() const
62
0
    {
63
0
        return v.data();
64
0
    }
65
66
    /// Returns the values of the matrix in column major order.
67
    double *data()
68
0
    {
69
0
        return v.data();
70
0
    }
71
72
    /// Resizes the matrix. All values are set to zero.
73
    void resize(int iRows, int iCols)
74
0
    {
75
0
        n_rows = iRows;
76
0
        n_cols = iCols;
77
0
        v.clear();
78
0
        v.resize(static_cast<size_t>(iRows) * iCols);
79
0
    }
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
89
#endif /* #ifndef GDALLINEARSYSTEM_H_INCLUDED */
90
91
/*! @endcond */