DOCI-Exact  1.0
SparseMatrix_CRS.h
Go to the documentation of this file.
1 #ifndef SPARSEMATRIX_CRS_H
2 #define SPARSEMATRIX_CRS_H
3 
4 #include <iostream>
5 #include <vector>
6 
7 #include "helpers.h"
8 
9 // dark magic to get the friend operator<< to work...
10 namespace helpers { class SparseMatrix_CRS; };
11 std::ostream &operator<<(std::ostream &output,helpers::SparseMatrix_CRS &matrix_p);
12 
13 namespace helpers {
14 
22 class SparseMatrix_CRS
23 {
33  friend std::ostream &::operator<<(std::ostream &output,helpers::SparseMatrix_CRS &matrix_p);
34 
35  public:
36 
37  SparseMatrix_CRS(unsigned int n);
38 
39  virtual ~SparseMatrix_CRS() = default;
40 
41  //easy to access the numbers
42  double operator()(unsigned int i,unsigned int j) const;
43 
44  unsigned int gn() const;
45 
46  void ConvertFromMatrix(const helpers::matrix &dense);
47 
48  void ConvertToMatrix(helpers::matrix &dense) const;
49 
50  void PrintRaw() const;
51 
52  void PushToRow(unsigned int j, double value);
53 
54  void PushToRowNext(unsigned int j, double value);
55 
56  void NewRow();
57 
58  void mvprod(const double *, double *) const;
59 
60  void mvprod(const double *, double *, double) const;
61 
62  void SetGuess(unsigned int);
63 
64  int WriteToFile(const char*,const char*,bool=false) const;
65 
66  int ReadFromFile(const char*,const char*);
67 
68  unsigned int NumOfElInRow(unsigned int idx) const;
69 
70  double GetElementInRow(unsigned int row_index, unsigned int element_index) const;
71 
72  unsigned int GetElementColIndexInRow(unsigned int row_index, unsigned int element_index) const;
73 
74  void AddList(std::vector< std::unique_ptr<SparseMatrix_CRS> > &);
75 
76  private:
77 
79  std::vector<double> data;
81  std::vector<unsigned int> col;
83  std::vector<unsigned int> row;
84 
86  unsigned int n;
87 };
88 
89 }
90 
91 #endif /* SPARSEMATRIX_CRS_H */
92 
93 /* vim: set ts=3 sw=3 expandtab :*/
virtual ~SparseMatrix_CRS()=default
void ConvertFromMatrix(const helpers::matrix &dense)
SparseMatrix_CRS(unsigned int n)
double operator()(unsigned int i, unsigned int j) const
unsigned int NumOfElInRow(unsigned int idx) const
std::ostream & operator<<(std::ostream &output, helpers::SparseMatrix_CRS &matrix_p)
void ConvertToMatrix(helpers::matrix &dense) const
unsigned int GetElementColIndexInRow(unsigned int row_index, unsigned int element_index) const
double GetElementInRow(unsigned int row_index, unsigned int element_index) const
void PushToRow(unsigned int j, double value)
void PushToRowNext(unsigned int j, double value)
unsigned int gn() const
void AddList(std::vector< std::unique_ptr< SparseMatrix_CRS > > &)
int ReadFromFile(const char *, const char *)
int WriteToFile(const char *, const char *, bool=false) const
void mvprod(const double *, double *) const