smooth_feedback
Control and estimation on Lie groups
Loading...
Searching...
No Matches
Functions
sparse.hpp File Reference

Sparse matrix utilities. More...

#include <numeric>
#include <optional>
#include <Eigen/Sparse>
Include dependency graph for sparse.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename Source , int Options>
requires (std::is_base_of_v<Eigen::EigenBase<Source>, Source>)
void smooth::feedback::block_add (Eigen::SparseMatrix< double, Options > &dest, Eigen::Index row0, Eigen::Index col0, const Source &source, double scale=1, bool upper_only=false)
 Add block into a sparse matrix. More...
 
template<typename Source , int Options>
requires (std::is_base_of_v<Eigen::EigenBase<Source>, Source>)
void smooth::feedback::block_write (Eigen::SparseMatrix< double, Options > &dest, Eigen::Index row0, Eigen::Index col0, const Source &source, double scale=1, bool upper_only=false)
 Write block into a sparse matrix. More...
 
template<int Options>
void smooth::feedback::block_add_identity (Eigen::SparseMatrix< double, Options > &dest, Eigen::Index row0, Eigen::Index col0, Eigen::Index n, double scale=1)
 Add identity matrix block into sparse matrix. More...
 
template<int Options>
void smooth::feedback::block_write_identity (Eigen::SparseMatrix< double, Options > &dest, Eigen::Index row0, Eigen::Index col0, Eigen::Index n, double scale=1)
 Write identity matrix block into sparse matrix. More...
 
template<typename SparseMat >
requires (std::is_base_of_v<Eigen::SparseCompressedBase<std::decay_t<SparseMat>>, std::decay_t<SparseMat>>)
void smooth::feedback::set_zero (SparseMat &&mat)
 Zero a sparse matrix expression without changing allocation. More...
 
template<typename Mat >
requires (std::is_base_of_v<Eigen::EigenBase<Mat>, Mat>)
uint64_t smooth::feedback::count_explicit_zeros (const Mat &mat)
 Count number of explicit zeros in sparse matrix. More...
 
template<typename Mat >
requires (std::is_base_of_v<Eigen::EigenBase<Mat>, Mat>)
Eigen::MatrixX< typename Mat::Scalar > smooth::feedback::mark_explicit_zeros (const Mat &mat)
 Mark explicit zeros in sparse matrix. More...
 
template<typename S1 , typename S2 , typename S3 , typename S4 >
requires (std::is_base_of_v<Eigen::EigenBase<S1>, S1> && std::is_base_of_v<Eigen::EigenBase<S2>, S2> && std::is_base_of_v<Eigen::EigenBase<S3>, S3> && std::is_base_of_v<Eigen::EigenBase<S4>, S4>)
void smooth::feedback::d2r_fog (Eigen::SparseMatrix< double > &out, const S1 &Jf, const S2 &Hf, const S3 &Jg, const S4 &Hg, Eigen::Index r0=0, Eigen::Index c0=0)
 (Right) Hessian of composed function \( (f \circ g)(x) \). More...
 

Detailed Description

Sparse matrix utilities.

Definition in file sparse.hpp.

Function Documentation

◆ block_add()

template<typename Source , int Options>
requires (std::is_base_of_v<Eigen::EigenBase<Source>, Source>)
void smooth::feedback::block_add ( Eigen::SparseMatrix< double, Options > &  dest,
Eigen::Index  row0,
Eigen::Index  col0,
const Source &  source,
double  scale = 1,
bool  upper_only = false 
)
inline

Add block into a sparse matrix.

After this function the output variable dest is s.t.

dest[row0 + r, col0 + c] += scale * source[r, c]

Parameters
destdestination
row0starting row for block
col0starting column for block
sourceblock values
scalescaling parameter
upper_onlyonly add into upper triangular part
Note
Values are accessed with coeffRef().

Definition at line 35 of file sparse.hpp.

◆ block_add_identity()

template<int Options>
void smooth::feedback::block_add_identity ( Eigen::SparseMatrix< double, Options > &  dest,
Eigen::Index  row0,
Eigen::Index  col0,
Eigen::Index  n,
double  scale = 1 
)
inline

Add identity matrix block into sparse matrix.

After this function the output variable dest is s.t.

dest[row0 + k, col0 + k] += scale, k = 0...n-1

Parameters
destdestination
row0starting row for block
col0starting column for block
nsize of identity matrix
scalescaling parameter
Note
Values are accessed with coeffRef().

Definition at line 103 of file sparse.hpp.

◆ block_write()

template<typename Source , int Options>
requires (std::is_base_of_v<Eigen::EigenBase<Source>, Source>)
void smooth::feedback::block_write ( Eigen::SparseMatrix< double, Options > &  dest,
Eigen::Index  row0,
Eigen::Index  col0,
const Source &  source,
double  scale = 1,
bool  upper_only = false 
)
inline

Write block into a sparse matrix.

After this function the output variable dest is s.t.

dest[row0 + r, col0 + c] = scale * source[r, c]

Parameters
destdestination
row0starting row for block
col0starting column for block
sourceblock values
scalescaling parameter
upper_onlyonly add into upper triangular part
Note
Values are accessed with coeffRef().

Definition at line 70 of file sparse.hpp.

◆ block_write_identity()

template<int Options>
void smooth::feedback::block_write_identity ( Eigen::SparseMatrix< double, Options > &  dest,
Eigen::Index  row0,
Eigen::Index  col0,
Eigen::Index  n,
double  scale = 1 
)
inline

Write identity matrix block into sparse matrix.

After this function the output variable dest is s.t.

dest[row0 + k, col0 + k] += scale, k = 0...n-1

Parameters
destdestination
row0starting row for block
col0starting column for block
nsize of identity matrix
scalescaling parameter
Note
Values are accessed with coeffRef().

Definition at line 125 of file sparse.hpp.

◆ count_explicit_zeros()

template<typename Mat >
requires (std::is_base_of_v<Eigen::EigenBase<Mat>, Mat>)
uint64_t smooth::feedback::count_explicit_zeros ( const Mat &  mat)

Count number of explicit zeros in sparse matrix.

Parameters
matsparse matrix

Definition at line 158 of file sparse.hpp.

◆ d2r_fog()

template<typename S1 , typename S2 , typename S3 , typename S4 >
requires (std::is_base_of_v<Eigen::EigenBase<S1>, S1> && std::is_base_of_v<Eigen::EigenBase<S2>, S2> && std::is_base_of_v<Eigen::EigenBase<S3>, S3> && std::is_base_of_v<Eigen::EigenBase<S4>, S4>)
void smooth::feedback::d2r_fog ( Eigen::SparseMatrix< double > &  out,
const S1 &  Jf,
const S2 &  Hf,
const S3 &  Jg,
const S4 &  Hg,
Eigen::Index  r0 = 0,
Eigen::Index  c0 = 0 
)
inline

(Right) Hessian of composed function \( (f \circ g)(x) \).

Parameters
[out]outresult [No x No*Nx]
[in]Jf(Right) Jacobian of f at y = g(x) [No x Ny ]
[in]Hf(Right) Hessian of f at y = g(x) [Ny x No*Ny]
[in]Jg(Right) Jacobian of g at x [Ny x Nx ]
[in]Hg(Right) Hessian of g at x [Nx x Ny*Nx]
[in]r0row to insert result
[in]r0col to insert result
Note
out must have appropriate size

Definition at line 213 of file sparse.hpp.

◆ mark_explicit_zeros()

template<typename Mat >
requires (std::is_base_of_v<Eigen::EigenBase<Mat>, Mat>)
Eigen::MatrixX< typename Mat::Scalar > smooth::feedback::mark_explicit_zeros ( const Mat &  mat)

Mark explicit zeros in sparse matrix.

Parameters
matsparse matrix

Returns a matrix that has values as follows:

  • 0 for implicit zeros
  • 1 for non-zeros
  • 9 for explicit zeros

Definition at line 181 of file sparse.hpp.

◆ set_zero()

template<typename SparseMat >
requires (std::is_base_of_v<Eigen::SparseCompressedBase<std::decay_t<SparseMat>>, std::decay_t<SparseMat>>)
void smooth::feedback::set_zero ( SparseMat &&  mat)
inline

Zero a sparse matrix expression without changing allocation.

Note
Expression must be write-able.
More efficient for compressed expressions.

Definition at line 140 of file sparse.hpp.