Go to the documentation of this file.
20 #if MRPT_HAS_SUITESPARSE
21 #define NCOMPLEX // In MRPT we don't need complex numbers, so avoid the
27 #include <mrpt/otherlibs/CSparse/cs.h>
103 template <
class MATRIX>
106 std::vector<int> row_list, col_list;
108 std::vector<double> content_list;
109 const int nCol = C.cols();
110 const int nRow = C.rows();
111 for (
int c = 0;
c < nCol; ++
c)
113 col_list.push_back(row_list.size());
114 for (
int r = 0;
r < nRow; ++
r)
115 if (C.get_unsafe(
r,
c) != 0)
117 row_list.push_back(
r);
118 content_list.push_back(C(
r,
c));
121 col_list.push_back(row_list.size());
126 sparse_matrix.i = (
int*)malloc(
sizeof(
int) * row_list.size());
127 sparse_matrix.p = (
int*)malloc(
sizeof(
int) * col_list.size());
128 sparse_matrix.x = (
double*)malloc(
sizeof(
double) * content_list.size());
132 sizeof(row_list[0]) * row_list.size());
135 sizeof(col_list[0]) * col_list.size());
138 sizeof(content_list[0]) * content_list.size());
155 void copy(
const cs*
const sm);
172 CSparseMatrix(
const size_t nRows = 0,
const size_t nCols = 0);
179 template <
typename T>
184 "Input data must contain at least one non-zero element.");
195 it !=
data.end(); ++it)
197 it->first.first, it->first.second, it->second);
208 template <
typename T,
size_t N,
size_t M>
216 template <
typename T>
239 void clear(
const size_t nRows = 1,
const size_t nCols = 1);
276 this->
add_AB(*
this, other);
302 const size_t row,
const size_t col,
const double val)
317 template <
class MATRIX>
319 const size_t row,
const size_t col,
const MATRIX& M)
323 "insert_entry() is only available for sparse matrix in "
325 const size_t nR = M.rows();
326 const size_t nC = M.cols();
327 for (
size_t r = 0;
r < nR;
r++)
328 for (
size_t c = 0;
c < nC;
c++)
479 template <
class VECTOR>
489 void backsub(
const Eigen::VectorXd&
b, Eigen::VectorXd& result_x)
const;
493 void backsub(
const double*
b,
double* result,
const size_t N)
const;
void update(const CSparseMatrix &new_SM)
Update the Cholesky factorization from an updated vesion of the original input, square definite-posit...
virtual ~CSparseMatrix()
Destructor.
void construct_from_mrpt_mat(const MATRIX &C)
Initialization from a dense matrix of any kind existing in MRPT.
bool isColumnCompressed() const
Returns true if this sparse matrix is in "column compressed" form.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
csn * m_numeric_structure
void insert_submatrix(const size_t row, const size_t col, const MATRIX &M)
ONLY for TRIPLET matrices: insert a given matrix (in any of the MRPT formats) at a given location of ...
CSparseMatrix(const CSparseMatrixTemplate< T > &data)
A good way to initialize a sparse matrix from a list of non nullptr elements.
bool isTriplet() const
Returns true if this sparse matrix is in "triplet" form.
typename SparseMatrixMap::const_iterator const_iterator
Const iterator to move through the matrix.
void compressFromTriplet()
ONLY for TRIPLET matrices: convert the matrix in a column-compressed form.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void swap(CSparseMatrix &other)
Fast swap contents with another sparse matrix.
css * m_symbolic_structure
void construct_from_existing_cs(const cs &sm)
To be called by constructors only, assume previous pointers are trash and overwrite them.
void add_AB(const CSparseMatrix &A, const CSparseMatrix &B)
this = A+B
#define THROW_EXCEPTION(msg)
#define ASSERT_(f)
Defines an assertion mechanism.
CholeskyDecomp & operator=(const CholeskyDecomp &)=delete
CholeskyDecomp(const CSparseMatrix &A)
Constructor from a square definite-positive sparse matrix A, which can be use to solve Ax=b The actua...
void clear(const size_t nRows=1, const size_t nCols=1)
Erase all previous contents and leave the matrix as a "triplet" ROWS x COLS matrix without any nonzer...
void insert_entry_fast(const size_t row, const size_t col, const double val)
This was an optimized version, but is now equivalent to insert_entry() due to the need to be compatib...
CSparseMatrix operator+(const CSparseMatrix &other) const
A matrix of dynamic size.
GLdouble GLdouble GLdouble r
void multiply_AB(const CSparseMatrix &A, const CSparseMatrix &B)
this = A*B
GLsizei GLsizei GLenum GLenum const GLvoid * data
virtual ~CholeskyDecomp()
Destructor.
void copy_fast(cs *const sm)
Fast copy the data from an existing "cs" CSparse data structure, copying the pointers and leaving NUL...
void operator=(const CSparseMatrix &other)
Copy operator from another existing object.
bool saveToTextFile_sparse(const std::string &filName)
Save sparse structure to a text file loadable from MATLAB (can be called on triplet or CCS matrices).
static void cs2dense(const cs &SM, CMatrixDouble &outMat)
Static method to convert a "cs" structure into a dense representation of the sparse matrix.
CSparseMatrix(const CMatrixTemplateNumeric< T > &MAT)
Constructor from a dense matrix of any kind existing in MRPT, creating a "column-compressed" sparse m...
Used in mrpt::math::CSparseMatrix.
VECTOR backsub(const VECTOR &b) const
Return the vector from a back-substitution step that solves: Ux=b.
A sparse matrix container (with cells of any type), with iterators.
CSparseMatrix transpose() const
void operator+=(const CSparseMatrix &other)
void operator*=(const CSparseMatrix &other)
void multiply_Ab(const mrpt::math::CVectorDouble &b, mrpt::math::CVectorDouble &out_res) const
out_res = this * b
A numeric matrix of compile-time fixed size.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
CMatrixDouble get_L() const
Return the L matrix (L*L' = M), as a dense matrix.
mrpt::math::CVectorDouble operator*(const mrpt::math::CVectorDouble &other) const
void construct_from_triplet(const cs &triplet)
Initialization from a triplet "cs", which is first compressed.
CSparseMatrix operator*(const CSparseMatrix &other) const
void copy(const cs *const sm)
Copy the data from an existing "cs" CSparse data structure.
GLenum GLenum GLvoid * row
void internal_free_mem()
free buffers (deallocate the memory of the i,p,x buffers)
GLsizei const GLfloat * value
void setColCount(const size_t nCols)
bool saveToTextFile_dense(const std::string &filName)
save as a dense matrix to a text file
CExceptionNotDefPos(const char *s)
void get_dense(CMatrixDouble &outMat) const
Return a dense representation of the sparse matrix.
const CSparseMatrix * m_originalSM
A const reference to the original matrix used to build this decomposition.
CSparseMatrix(const size_t nRows=0, const size_t nCols=0)
Create an initially empty sparse matrix, in the "triplet" form.
GLsizei const GLchar ** string
void setRowCount(const size_t nRows)
Change the number of rows in the matrix (can't be lower than current size)
void insert_entry(const size_t row, const size_t col, const double val)
@ Access the matrix, get, set elements, etc.
CSparseMatrix(const CMatrixFixedNumeric< T, N, M > &MAT)
Constructor from a dense matrix of any kind existing in MRPT, creating a "column-compressed" sparse m...
Auxiliary class to hold the results of a Cholesky factorization of a sparse matrix.
A sparse matrix structure, wrapping T.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at mié 12 jul 2023 10:03:34 CEST | |