LCOV - code coverage report
Current view: top level - alg - gdallinearsystem.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 11 11 100.0 %
Date: 2024-11-21 22:18:42 Functions: 5 5 100.0 %

          Line data    Source code
       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         123 :     GDALMatrix(int rows, int cols)
      32         123 :         : n_rows(rows), n_cols(cols), v(rows * cols, 0.)
      33             :     {
      34         123 :     }
      35             : 
      36             :     /// Returns the number or rows of the matrix
      37         246 :     inline int getNumRows() const
      38             :     {
      39         246 :         return n_rows;
      40             :     }
      41             : 
      42             :     /// Returns the number or columns of the matrix.
      43         246 :     inline int getNumCols() const
      44             :     {
      45         246 :         return n_cols;
      46             :     }
      47             : 
      48             :     /// Returns the reference to the element at the position \a row, \a col.
      49    13599800 :     inline double &operator()(int row, int col)
      50             :     {
      51    13599800 :         return v[row + col * static_cast<size_t>(n_rows)];
      52             :     }
      53             : 
      54             :     /// Returns the element at the position \a row, \a col by value.
      55             :     inline double operator()(int row, int col) const
      56             :     {
      57             :         return v[row + col * static_cast<size_t>(n_rows)];
      58             :     }
      59             : 
      60             :     /// Returns the values of the matrix in column major order.
      61             :     double const *data() const
      62             :     {
      63             :         return v.data();
      64             :     }
      65             : 
      66             :     /// Returns the values of the matrix in column major order.
      67         123 :     double *data()
      68             :     {
      69         123 :         return v.data();
      70             :     }
      71             : 
      72             :     /// Resizes the matrix. All values are set to zero.
      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             : 
      89             : #endif /* #ifndef GDALLINEARSYSTEM_H_INCLUDED */
      90             : 
      91             : /*! @endcond */

Generated by: LCOV version 1.14