g2o
Public Member Functions | Public Attributes | Protected Attributes | List of all members
g2o::MatrixStructure Class Reference

representing the structure of a matrix in column compressed structure (only the upper triangular part of the matrix) More...

#include <matrix_structure.h>

Public Member Functions

 MatrixStructure ()
 
 ~MatrixStructure ()
 
void alloc (int n_, int nz)
 
void free ()
 
bool write (const char *filename) const
 
int nzMax () const
 max number of non-zeros blocks More...
 

Public Attributes

int n
 A is m-by-n. n must be >= 0. More...
 
int m
 A is m-by-n. m must be >= 0. More...
 
int * Ap
 column pointers for A, of size n+1 More...
 
int * Aii
 row indices of A, of size nz = Ap [n] More...
 

Protected Attributes

int maxN
 size of the allocated memory More...
 
int maxNz
 size of the allocated memory More...
 

Detailed Description

representing the structure of a matrix in column compressed structure (only the upper triangular part of the matrix)

Definition at line 37 of file matrix_structure.h.

Constructor & Destructor Documentation

g2o::MatrixStructure::MatrixStructure ( )

Definition at line 45 of file matrix_structure.cpp.

45  :
46  n(0), m(0), Ap(0), Aii(0), maxN(0), maxNz(0)
47 {
48 }
int * Ap
column pointers for A, of size n+1
int maxNz
size of the allocated memory
int n
A is m-by-n. n must be >= 0.
int m
A is m-by-n. m must be >= 0.
int * Aii
row indices of A, of size nz = Ap [n]
int maxN
size of the allocated memory
g2o::MatrixStructure::~MatrixStructure ( )

Definition at line 50 of file matrix_structure.cpp.

References free().

51 {
52  free();
53 }

Member Function Documentation

void g2o::MatrixStructure::alloc ( int  n_,
int  nz 
)

allocate space for the Matrix Structure. You may call this on an already allocated struct, it will then reallocate the memory + additional space (double the required space).

Definition at line 55 of file matrix_structure.cpp.

References Aii, Ap, maxN, maxNz, and n.

Referenced by g2o::SparseBlockMatrix< MatrixType >::fillBlockStructure().

56 {
57  if (n == 0) {
58  maxN = n = n_;
59  maxNz = nz;
60  Ap = new int[maxN + 1];
61  Aii = new int[maxNz];
62  }
63  else {
64  n = n_;
65  if (maxNz < nz) {
66  maxNz = 2 * nz;
67  delete[] Aii;
68  Aii = new int[maxNz];
69  }
70  if (maxN < n) {
71  maxN = 2 * n;
72  delete[] Ap;
73  Ap = new int[maxN + 1];
74  }
75  }
76 }
int * Ap
column pointers for A, of size n+1
int maxNz
size of the allocated memory
int n
A is m-by-n. n must be >= 0.
int * Aii
row indices of A, of size nz = Ap [n]
int maxN
size of the allocated memory
void g2o::MatrixStructure::free ( )

Definition at line 78 of file matrix_structure.cpp.

References Aii, Ap, m, maxN, maxNz, and n.

Referenced by ~MatrixStructure().

79 {
80  n = 0;
81  m = 0;
82  maxN = 0;
83  maxNz = 0;
84  delete[] Aii; Aii = 0;
85  delete[] Ap; Ap = 0;
86 }
int * Ap
column pointers for A, of size n+1
int maxNz
size of the allocated memory
int n
A is m-by-n. n must be >= 0.
int m
A is m-by-n. m must be >= 0.
int * Aii
row indices of A, of size nz = Ap [n]
int maxN
size of the allocated memory
int g2o::MatrixStructure::nzMax ( ) const
inline

max number of non-zeros blocks

Definition at line 61 of file matrix_structure.h.

Referenced by g2o::LinearSolverCSparse< MatrixType >::computeSymbolicDecomposition(), and g2o::LinearSolverCholmod< MatrixType >::computeSymbolicDecomposition().

61 { return maxNz;}
int maxNz
size of the allocated memory
bool g2o::MatrixStructure::write ( const char *  filename) const

Write the matrix pattern to a file. File is also loadable by octave, e.g., then use spy(matrix)

Definition at line 88 of file matrix_structure.cpp.

References Aii, Ap, m, and n.

89 {
90  const int& cols = n;
91  const int& rows = m;
92 
93  string name = filename;
94  std::string::size_type lastDot = name.find_last_of('.');
95  if (lastDot != std::string::npos)
96  name = name.substr(0, lastDot);
97 
98  vector<pair<int, int> > entries;
99  for (int i=0; i < cols; ++i) {
100  const int& rbeg = Ap[i];
101  const int& rend = Ap[i+1];
102  for (int j = rbeg; j < rend; ++j) {
103  entries.push_back(make_pair(Aii[j], i));
104  if (Aii[j] != i)
105  entries.push_back(make_pair(i, Aii[j]));
106  }
107  }
108 
109  sort(entries.begin(), entries.end(), ColSort());
110 
111  std::ofstream fout(filename);
112  fout << "# name: " << name << std::endl;
113  fout << "# type: sparse matrix" << std::endl;
114  fout << "# nnz: " << entries.size() << std::endl;
115  fout << "# rows: " << rows << std::endl;
116  fout << "# columns: " << cols << std::endl;
117  for (vector<pair<int, int> >::const_iterator it = entries.begin(); it != entries.end(); ++it) {
118  const pair<int, int>& entry = *it;
119  fout << entry.first << " " << entry.second << " 0" << std::endl; // write a constant value of 0
120  }
121 
122  return fout.good();
123 }
int * Ap
column pointers for A, of size n+1
int n
A is m-by-n. n must be >= 0.
int m
A is m-by-n. m must be >= 0.
int * Aii
row indices of A, of size nz = Ap [n]

Member Data Documentation

int* g2o::MatrixStructure::Aii
int* g2o::MatrixStructure::Ap
int g2o::MatrixStructure::m

A is m-by-n. m must be >= 0.

Definition at line 56 of file matrix_structure.h.

Referenced by g2o::SparseBlockMatrix< MatrixType >::fillBlockStructure(), free(), and write().

int g2o::MatrixStructure::maxN
protected

size of the allocated memory

Definition at line 64 of file matrix_structure.h.

Referenced by alloc(), and free().

int g2o::MatrixStructure::maxNz
protected

size of the allocated memory

Definition at line 65 of file matrix_structure.h.

Referenced by alloc(), and free().

int g2o::MatrixStructure::n

The documentation for this class was generated from the following files: