sym-ildl  1.2
Incomplete LDL' factorizations of indefinite symmetric and skew-symmetric matrices.
lil_sparse_matrix.h
1 // -*- mode: c++ -*-
2 #ifndef _LIL_SPARSE_MATRIX_H_
3 #define _LIL_SPARSE_MATRIX_H_
4 
5 #include <vector>
6 #include <string>
7 #include <fstream>
8 #include <limits>
9 
10 
11 using std::vector;
12 
14 template<class el_type>
16 {
17 
18 public:
19 
20  typedef vector<int> idx_vector_type;
21  typedef vector<el_type> elt_vector_type;
22 
24  friend std::ostream & operator<<(std::ostream& os, const lil_sparse_matrix& A)
25  {
26  os << A.to_string();
27  return os;
28  };
29 
30  int m_n_rows;
31  int m_n_cols;
32  int nnz_count;
33  el_type eps;
34 
35  vector<idx_vector_type> m_idx;
36  vector<elt_vector_type> m_x;
37 
39  lil_sparse_matrix (int n_rows, int n_cols) : m_n_rows(n_rows), m_n_cols (n_cols)
40  {
41  nnz_count = 0;
42  eps = 1e-8;
43  }
44 
46  int n_rows() const
47  {
48  return m_n_rows;
49  }
50 
52  int n_cols() const
53  {
54  return m_n_cols;
55  }
56 
58  int nnz() const
59  {
60  return nnz_count;
61  };
62 
68  virtual el_type coeff(const int& i, const int& j, int offset = 0) const = 0;
69 
72  virtual std::string to_string() const = 0;
73 
76  {
77  }
78 };
79 
80 #endif // _LIL_SPARSE_MATRIX_H_
int nnz_count
Number of nonzeros in the matrix.
Definition: lil_sparse_matrix.h:32
vector< elt_vector_type > m_x
The values of the nonzeros in the matrix.
Definition: lil_sparse_matrix.h:36
virtual std::string to_string() const =0
vector< idx_vector_type > m_idx
The row/col indices. The way m_idx is used depends on whether the matrix is in LIL-C or LIL-R...
Definition: lil_sparse_matrix.h:35
int m_n_cols
Number of cols in the matrix.
Definition: lil_sparse_matrix.h:31
el_type eps
Machine epsilon for el_type.
Definition: lil_sparse_matrix.h:33
int n_rows() const
Definition: lil_sparse_matrix.h:46
friend std::ostream & operator<<(std::ostream &os, const lil_sparse_matrix &A)
Allows outputting the contents of the matrix via << operators.
Definition: lil_sparse_matrix.h:24
lil_sparse_matrix(int n_rows, int n_cols)
Default constructor for an abstract matrix. This constructor will be extended by base classes dependi...
Definition: lil_sparse_matrix.h:39
int m_n_rows
Number of rows in the matrix.
Definition: lil_sparse_matrix.h:28
virtual el_type coeff(const int &i, const int &j, int offset=0) const =0
Returns A_ij (zero-indexed). This function should be extended by subclasses as it is dependent on the...
virtual ~lil_sparse_matrix()
Definition: lil_sparse_matrix.h:75
The abstract parent of all sparse matrices.
Definition: lil_sparse_matrix.h:15
int nnz() const
Definition: lil_sparse_matrix.h:58
int n_cols() const
Definition: lil_sparse_matrix.h:52