Isis 3 Programmer Reference
SparseBlockMatrix.h
1 #ifndef SparseBlockMatrix_h
2 #define SparseBlockMatrix_h
3 
9 /* SPDX-License-Identifier: CC0-1.0 */
10 
11 // std library
12 #include <iostream>
13 
14 // Qt library
15 #include <QMap>
16 #include <QList>
17 
18 // boost library
19 #include <boost/numeric/ublas/fwd.hpp>
20 
21 // Isis library
22 #include "LinearAlgebra.h"
23 
24 // Qt library
25 class QDebug;
26 
27 namespace Isis {
28 
58  public QMap< int, LinearAlgebra::Matrix * > {
59 
60  public:
61  SparseBlockColumnMatrix(); // default constructor
62  ~SparseBlockColumnMatrix(); // destructor
63 
64  // copy constructor
66 
68 
69  void wipe();
70  void copy(const SparseBlockColumnMatrix& src);
71 
72  void zeroBlocks();
73  bool insertMatrixBlock(int nColumnBlock, int nRows, int nCols);
74 
75  void setStartColumn(int nStartColumn);
76  int startColumn() const;
77  int numberOfElements();
78  int numberOfRows();
79  int numberOfColumns();
80  void print(std::ostream& outstream);
81  void printClean(std::ostream& outstream);
82 
83  protected:
87  };
88 
89  // operators to read/write SparseBlockColumnMatrix to/from binary disk file
90  QDataStream &operator<<(QDataStream &, const SparseBlockColumnMatrix &);
91  QDataStream &operator>>(QDataStream &, SparseBlockColumnMatrix &);
92 
93  // operator to write SparseBlockColumnMatrix to QDebug stream
94  QDebug operator<<(QDebug dbg, const SparseBlockColumnMatrix &sbcm);
95 
96 
125  public QMap< int, LinearAlgebra::Matrix * > {
126 
127  public:
128  SparseBlockRowMatrix(){} // default constructor
130 
131  // copy constructor
133 
135 
136 
137  void wipe();
138  void copy(const SparseBlockRowMatrix& src);
139 
140  void zeroBlocks();
141  bool insertMatrixBlock(int nRowBlock, int nRows, int nCols);
142  void copyToBoost(boost::numeric::ublas::compressed_matrix<double>& B);
143  int getLeadingColumnsForBlock(int nblockColumn);
144  int numberOfElements();
145  void print(std::ostream& outstream);
146  void printClean(std::ostream& outstream);
147  };
148 
149  // operators to read/write SparseBlockRowMatrix to/from binary disk file
150  QDataStream &operator<<(QDataStream &, const SparseBlockRowMatrix &);
151  QDataStream &operator>>(QDataStream &, SparseBlockRowMatrix &);
152 
153  // operator to write SparseBlockRowMatrix to QDebug stream
154  QDebug operator<<(QDebug dbg, const SparseBlockRowMatrix &sbcm);
155 
186  class SparseBlockMatrix : public QList< SparseBlockColumnMatrix* > {
187 
188  public:
189  SparseBlockMatrix() {} // default constructor
191 
192  // copy constructor
194 
196 
197  void wipe();
198  void copy(const SparseBlockMatrix& src);
199 
200  bool setNumberOfColumns( int n );
201  void zeroBlocks();
202  bool insertMatrixBlock(int nColumnBlock, int nRowBlock, int nRows, int nCols);
203  LinearAlgebra::Matrix *getBlock(int column, int row);
204  int numberOfBlocks();
207  int numberOfElements();
208  void print(std::ostream& outstream);
209  void printClean(std::ostream& outstream);
210  bool write(std::ofstream &fp_out, bool binary=true);
211  int getLeadingColumnsForBlock(int nblockColumn);
212  int getLeadingRowsForBlock(int nblockRow);
213  };
214 
215  // operators to read/write SparseBlockMatrix to/from binary disk file
216  QDataStream &operator<<(QDataStream &, const SparseBlockMatrix &);
217  QDataStream &operator>>(QDataStream &, SparseBlockMatrix &);
218 
219  // operator to write SparseBlockMatrix to QDebug stream
220  QDebug operator<<(QDebug dbg, const SparseBlockMatrix &m);
221 }
222 
223 #endif
Isis::SparseBlockMatrix::getLeadingColumnsForBlock
int getLeadingColumnsForBlock(int nblockColumn)
Sums and returns the number of columns in each matrix block prior to nblockColumn.
Definition: SparseBlockMatrix.cpp:1054
Isis::SparseBlockRowMatrix::printClean
void printClean(std::ostream &outstream)
Prints matrix blocks to std output stream out for debugging.
Definition: SparseBlockMatrix.cpp:578
Isis::SparseBlockRowMatrix::copyToBoost
void copyToBoost(boost::numeric::ublas::compressed_matrix< double > &B)
Copies a SparseBlockRowMatrix to a Boost compressed_matrix.
Definition: SparseBlockMatrix.cpp:626
Isis::SparseBlockRowMatrix::operator=
SparseBlockRowMatrix & operator=(const SparseBlockRowMatrix &src)
"Equals" operator.
Definition: SparseBlockMatrix.cpp:482
Isis::operator<<
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Definition: Hillshade.cpp:314
Isis::SparseBlockColumnMatrix
SparseBlockColumnMatrix.
Definition: SparseBlockMatrix.h:58
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::SparseBlockRowMatrix::copy
void copy(const SparseBlockRowMatrix &src)
Copy method.
Definition: SparseBlockMatrix.cpp:458
Isis::SparseBlockRowMatrix::zeroBlocks
void zeroBlocks()
Sets all elements of all matrix blocks to zero.
Definition: SparseBlockMatrix.cpp:611
Isis::SparseBlockRowMatrix::~SparseBlockRowMatrix
~SparseBlockRowMatrix()
Destructor.
Definition: SparseBlockMatrix.cpp:428
Isis::SparseBlockRowMatrix::wipe
void wipe()
Deletes all pointer elements and removes them from the map.
Definition: SparseBlockMatrix.cpp:437
Isis::SparseBlockColumnMatrix::setStartColumn
void setStartColumn(int nStartColumn)
Sets starting column for block in full matrix.
Definition: SparseBlockMatrix.cpp:147
Isis::SparseBlockColumnMatrix::operator=
SparseBlockColumnMatrix & operator=(const SparseBlockColumnMatrix &src)
"Equals" operator.
Definition: SparseBlockMatrix.cpp:99
Isis::SparseBlockColumnMatrix::print
void print(std::ostream &outstream)
Prints matrix blocks to std output stream out for debugging.
Definition: SparseBlockMatrix.cpp:239
Isis::SparseBlockColumnMatrix::numberOfRows
int numberOfRows()
Returns total number of rows in map (this needs to be clarified and maybe rewritten).
Definition: SparseBlockMatrix.cpp:215
Isis::LinearAlgebra::Matrix
boost::numeric::ublas::matrix< double > Matrix
Definition for an Isis::LinearAlgebra::Matrix of doubles.
Definition: LinearAlgebra.h:100
Isis::SparseBlockColumnMatrix::printClean
void printClean(std::ostream &outstream)
Prints matrix blocks to std output stream out for debugging.
Definition: SparseBlockMatrix.cpp:266
Isis::SparseBlockColumnMatrix::SparseBlockColumnMatrix
SparseBlockColumnMatrix()
Default constructor.
Definition: SparseBlockMatrix.cpp:35
Isis::SparseBlockColumnMatrix::~SparseBlockColumnMatrix
~SparseBlockColumnMatrix()
Destructor.
Definition: SparseBlockMatrix.cpp:43
Isis::SparseBlockColumnMatrix::startColumn
int startColumn() const
Sets starting column for block in full matrix.
Definition: SparseBlockMatrix.cpp:157
Isis::SparseBlockRowMatrix::numberOfElements
int numberOfElements()
Returns total number of matrix elements in map (NOTE: NOT the number of matrix blocks).
Definition: SparseBlockMatrix.cpp:530
Isis::SparseBlockColumnMatrix::insertMatrixBlock
bool insertMatrixBlock(int nColumnBlock, int nRows, int nCols)
Inserts a "newed" LinearAlgebra::Matrix pointer of size (nRows, nCols) into the map with the block co...
Definition: SparseBlockMatrix.cpp:121
Isis::SparseBlockMatrix::getLeadingRowsForBlock
int getLeadingRowsForBlock(int nblockRow)
Sums and returns the number of rows in each matrix block prior to nblockRow.
Definition: SparseBlockMatrix.cpp:1088
Isis::SparseBlockMatrix::numberOfElements
int numberOfElements()
Returns number of matrix elements in matrix.
Definition: SparseBlockMatrix.cpp:963
Isis::SparseBlockMatrix::~SparseBlockMatrix
~SparseBlockMatrix()
Destructor.
Definition: SparseBlockMatrix.cpp:809
Isis::SparseBlockColumnMatrix::m_startColumn
int m_startColumn
starting column for this Block Column in full matrix e.g.
Definition: SparseBlockMatrix.h:84
Isis::SparseBlockColumnMatrix::copy
void copy(const SparseBlockColumnMatrix &src)
Copy method.
Definition: SparseBlockMatrix.cpp:73
Isis::SparseBlockMatrix::wipe
void wipe()
Deletes all pointer elements and removes them from the list.
Definition: SparseBlockMatrix.cpp:818
Isis::SparseBlockMatrix::numberOfOffDiagonalBlocks
int numberOfOffDiagonalBlocks()
Returns number of off-diagonal matrix blocks.
Definition: SparseBlockMatrix.cpp:953
Isis::SparseBlockMatrix::print
void print(std::ostream &outstream)
Prints matrix blocks to std output stream out for debugging.
Definition: SparseBlockMatrix.cpp:1005
Isis::SparseBlockMatrix::getBlock
LinearAlgebra::Matrix * getBlock(int column, int row)
Returns pointer to boost matrix at position (column, row).
Definition: SparseBlockMatrix.cpp:986
Isis::SparseBlockRowMatrix::insertMatrixBlock
bool insertMatrixBlock(int nRowBlock, int nRows, int nCols)
Inserts a "newed" LinearAlgebra::Matrix pointer of size (nRows, nCols) into the map with the block ro...
Definition: SparseBlockMatrix.cpp:507
Isis::SparseBlockRowMatrix::print
void print(std::ostream &outstream)
Prints matrix blocks to std output stream out for debugging.
Definition: SparseBlockMatrix.cpp:552
Isis::SparseBlockMatrix::printClean
void printClean(std::ostream &outstream)
Prints matrix blocks to std output stream out for debugging.
Definition: SparseBlockMatrix.cpp:1029
Isis::SparseBlockRowMatrix::getLeadingColumnsForBlock
int getLeadingColumnsForBlock(int nblockColumn)
Sums and returns the number of columns in each matrix block prior to nblockColumn.
Definition: SparseBlockMatrix.cpp:661
Isis::SparseBlockColumnMatrix::zeroBlocks
void zeroBlocks()
Sets all elements of all matrix blocks to zero.
Definition: SparseBlockMatrix.cpp:299
Isis::SparseBlockMatrix::zeroBlocks
void zeroBlocks()
Sets all elements of all matrix blocks to zero.
Definition: SparseBlockMatrix.cpp:994
Isis::SparseBlockMatrix::setNumberOfColumns
bool setNumberOfColumns(int n)
Initializes number of columns (SparseBlockColumnMatrix).
Definition: SparseBlockMatrix.cpp:873
QMap
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:22
Isis::SparseBlockColumnMatrix::numberOfColumns
int numberOfColumns()
Returns total number of columns in map (NOTE: NOT the number of matrix blocks).
Definition: SparseBlockMatrix.cpp:190
Isis::SparseBlockMatrix::numberOfDiagonalBlocks
int numberOfDiagonalBlocks()
Returns number of diagonal matrix blocks (equivalent to size - there is one per column).
Definition: SparseBlockMatrix.cpp:924
Isis::SparseBlockColumnMatrix::numberOfElements
int numberOfElements()
Returns total number of matrix elements in map (NOTE: NOT the number of matrix blocks).
Definition: SparseBlockMatrix.cpp:168
Isis::SparseBlockRowMatrix
SparseBlockRowMatrix.
Definition: SparseBlockMatrix.h:125
Isis::SparseBlockMatrix::copy
void copy(const SparseBlockMatrix &src)
Copy method.
Definition: SparseBlockMatrix.cpp:839
Isis::operator>>
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
Definition: CSVReader.cpp:447
Isis::SparseBlockMatrix
SparseBlockMatrix.
Definition: SparseBlockMatrix.h:186
Isis::SparseBlockMatrix::numberOfBlocks
int numberOfBlocks()
Returns total number of blocks in matrix.
Definition: SparseBlockMatrix.cpp:905
Isis::SparseBlockColumnMatrix::wipe
void wipe()
Deletes all pointer elements and removes them from the map.
Definition: SparseBlockMatrix.cpp:52
Isis::SparseBlockMatrix::insertMatrixBlock
bool insertMatrixBlock(int nColumnBlock, int nRowBlock, int nRows, int nCols)
Inserts a "newed" boost LinearAlgebra::Matrix pointer of size (nRows, nCols) into the matrix at nColu...
Definition: SparseBlockMatrix.cpp:895
Isis::SparseBlockMatrix::operator=
SparseBlockMatrix & operator=(const SparseBlockMatrix &src)
"Equals" operator.
Definition: SparseBlockMatrix.cpp:855
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16