g2o
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
g2o::csparse::CSparse Class Reference

#include <csparse_wrapper.h>

Classes

struct  FactorView
 View onto the cholesky factor. More...
 
class  Impl
 
struct  SparseView
 View onto the sparse matrix structure of CSparse using CCS storage. More...
 

Public Member Functions

 CSparse ()
 
 ~CSparse ()
 
bool factorize ()
 
bool hasFactor () const
 
void freeFactor ()
 
FactorView factor ()
 
bool amd (const SparseView &sparseView, VectorXI &result)
 compute AMD ordering on the given SparseView, store into result
 
int choleskyNz () const
 
bool solve (double *x, double *b) const
 
bool analyze ()
 
bool analyze_p (int *permutation)
 
bool hasSymbolic () const
 
void freeSymbolic ()
 
SparseView sparseView ()
 
bool writeSparse (const std::string &filename) const
 

Private Attributes

std::unique_ptr< ImplpImpl
 

Detailed Description

Definition at line 38 of file csparse_wrapper.h.

Constructor & Destructor Documentation

◆ CSparse()

g2o::csparse::CSparse::CSparse ( )

Definition at line 104 of file csparse_wrapper.cpp.

104: pImpl(std::make_unique<Impl>()) {}
std::unique_ptr< Impl > pImpl

◆ ~CSparse()

g2o::csparse::CSparse::~CSparse ( )
default

Member Function Documentation

◆ amd()

bool g2o::csparse::CSparse::amd ( const SparseView sparseView,
VectorXI result 
)

compute AMD ordering on the given SparseView, store into result

Definition at line 117 of file csparse_wrapper.cpp.

117 {
118 // prepare block structure for the CSparse call
119 cs auxBlock;
120 auxBlock.nzmax = sparseView.nzmax;
121 auxBlock.m = sparseView.m;
122 auxBlock.n = sparseView.n;
123 auxBlock.p = sparseView.p;
124 auxBlock.i = sparseView.i;
125 auxBlock.x = NULL; // no values
126 auxBlock.nz = -1; // CCS format
127
128 // AMD ordering on the block structure
129 int* permutation = cs_amd(1, &auxBlock);
130 if (!permutation) return false;
131 result.resize(auxBlock.m);
132 VectorXI::ConstMapType permutation_map(permutation, result.size());
133 result = permutation_map;
134 cs_free(permutation);
135 return true;
136}

References g2o::csparse::CSparse::SparseView::i, g2o::csparse::CSparse::SparseView::m, g2o::csparse::CSparse::SparseView::n, g2o::csparse::CSparse::SparseView::nzmax, g2o::csparse::CSparse::SparseView::p, and sparseView().

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

◆ analyze()

bool g2o::csparse::CSparse::analyze ( )

Definition at line 160 of file csparse_wrapper.cpp.

160 {
161 freeSymbolic();
162 pImpl->symbolicDecomposition = cs_schol(1, &pImpl->ccsA);
163 return pImpl->symbolicDecomposition != nullptr;
164}

References freeSymbolic(), and pImpl.

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

◆ analyze_p()

bool g2o::csparse::CSparse::analyze_p ( int *  permutation)

Definition at line 166 of file csparse_wrapper.cpp.

166 {
167 freeSymbolic();
168 pImpl->symbolicDecomposition = static_cast<css*>(cs_calloc(1, sizeof(css)));
169 int n = pImpl->ccsA.n;
170 pImpl->symbolicDecomposition->pinv = cs_pinv(permutation, n);
171 cs* C = cs_symperm(&pImpl->ccsA, pImpl->symbolicDecomposition->pinv, 0);
172 pImpl->symbolicDecomposition->parent = cs_etree(C, 0);
173 int* post = cs_post(pImpl->symbolicDecomposition->parent, n);
174 int* c = cs_counts(C, pImpl->symbolicDecomposition->parent, post, 0);
175 cs_free(post);
176 cs_spfree(C);
177 pImpl->symbolicDecomposition->cp =
178 static_cast<int*>(cs_malloc(n + 1, sizeof(int)));
179 pImpl->symbolicDecomposition->unz = pImpl->symbolicDecomposition->lnz =
180 cs_cumsum(pImpl->symbolicDecomposition->cp, c, n);
181 cs_free(c);
182 if (pImpl->symbolicDecomposition->lnz < 0) {
183 cs_sfree(pImpl->symbolicDecomposition);
184 pImpl->symbolicDecomposition = nullptr;
185 }
186 return pImpl->symbolicDecomposition != nullptr;
187}

References freeSymbolic(), and pImpl.

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

◆ choleskyNz()

int g2o::csparse::CSparse::choleskyNz ( ) const

Definition at line 189 of file csparse_wrapper.cpp.

189 {
190 if (pImpl->symbolicDecomposition) return pImpl->symbolicDecomposition->lnz;
191 return -1;
192}

References pImpl.

Referenced by g2o::LinearSolverCSparse< MatrixType >::solve(), and g2o::LinearSolverCSparse< MatrixType >::solveBlocks_impl().

◆ factor()

CSparse::FactorView g2o::csparse::CSparse::factor ( )

◆ factorize()

bool g2o::csparse::CSparse::factorize ( )

Definition at line 194 of file csparse_wrapper.cpp.

194 {
195 pImpl->prepareWorkspace();
196 freeFactor();
198 &pImpl->ccsA, pImpl->symbolicDecomposition, pImpl->csIntWorkspace,
199 pImpl->csWorkspace);
200
201 return pImpl->numericCholesky != nullptr;
202}
csn * cs_chol_workspace(const cs *A, const css *S, int *cin, double *xin)

References g2o::csparse_extension::cs_chol_workspace(), freeFactor(), and pImpl.

Referenced by g2o::LinearSolverCSparse< MatrixType >::solveBlocks_impl().

◆ freeFactor()

void g2o::csparse::CSparse::freeFactor ( )

Definition at line 108 of file csparse_wrapper.cpp.

108 {
109 if (pImpl->numericCholesky) {
110 cs_nfree(pImpl->numericCholesky);
111 pImpl->numericCholesky = nullptr;
112 }
113}

References pImpl.

Referenced by factorize(), and g2o::LinearSolverCSparse< MatrixType >::solveBlocks_impl().

◆ freeSymbolic()

void g2o::csparse::CSparse::freeSymbolic ( )

Definition at line 208 of file csparse_wrapper.cpp.

208 {
209 if (pImpl->symbolicDecomposition != nullptr) {
210 cs_sfree(pImpl->symbolicDecomposition);
211 pImpl->symbolicDecomposition = nullptr;
212 }
213}

References pImpl.

Referenced by analyze(), analyze_p(), and g2o::LinearSolverCSparse< MatrixType >::init().

◆ hasFactor()

bool g2o::csparse::CSparse::hasFactor ( ) const

Definition at line 115 of file csparse_wrapper.cpp.

115{ return pImpl->numericCholesky != nullptr; }

References pImpl.

◆ hasSymbolic()

bool g2o::csparse::CSparse::hasSymbolic ( ) const

Definition at line 204 of file csparse_wrapper.cpp.

204 {
205 return pImpl->symbolicDecomposition != nullptr;
206}

References pImpl.

Referenced by g2o::LinearSolverCSparse< MatrixType >::prepareSolve().

◆ solve()

bool g2o::csparse::CSparse::solve ( double *  x,
double *  b 
) const

Definition at line 150 of file csparse_wrapper.cpp.

150 {
151 pImpl->prepareWorkspace();
152
153 if (x != b) memcpy(x, b, pImpl->ccsA.n * sizeof(double));
155 &pImpl->ccsA, x, pImpl->symbolicDecomposition, pImpl->csWorkspace,
156 pImpl->csIntWorkspace);
157 return static_cast<bool>(ok);
158}
int cs_cholsolsymb(const cs *A, double *b, const css *S, double *x, int *work)

References g2o::csparse_extension::cs_cholsolsymb(), and pImpl.

Referenced by g2o::LinearSolverCSparse< MatrixType >::solve().

◆ sparseView()

CSparse::SparseView g2o::csparse::CSparse::sparseView ( )

Definition at line 138 of file csparse_wrapper.cpp.

138 {
139 CSparseExt& sparse = pImpl->ccsA;
140 return CSparse::SparseView(sparse.m, sparse.n, sparse.nzmax, sparse.p,
141 sparse.i, sparse.x, sparse.columnsAllocated);
142}

References g2o::csparse::CSparseExt::columnsAllocated, and pImpl.

Referenced by amd(), and g2o::LinearSolverCSparse< MatrixType >::fillCSparse().

◆ writeSparse()

bool g2o::csparse::CSparse::writeSparse ( const std::string &  filename) const

Definition at line 215 of file csparse_wrapper.cpp.

215 {
216 return csparse_extension::writeCs2Octave(filename.c_str(), &pImpl->ccsA,
217 true);
218}
bool writeCs2Octave(const char *filename, const cs *A, bool upperTriangular)

References pImpl, and g2o::csparse_extension::writeCs2Octave().

Referenced by g2o::LinearSolverCSparse< MatrixType >::solve().

Member Data Documentation

◆ pImpl

std::unique_ptr<Impl> g2o::csparse::CSparse::pImpl
private

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