sas
Modularised monitoring, logging, and control of robots.
Loading...
Searching...
No Matches
sas_core.hpp File Reference

Core numerical utilities used across the project. More...

#include <eigen3/Eigen/Dense>

Go to the source code of this file.

Enumerations

enum class  sas::Statistics { Mean }
 Statistical measures supported by sas_core utilities. More...

Functions

template<class T>
constexpr T sas::incremental_mean (const T &current_mean, const int &current_number_of_samples, const T &new_sample)
 incremental_mean a simple implementation of incremental mean, for the many cases in which keeping a vector of all values would be impractical.
VectorXd sas::concatenate (const VectorXd &a, const VectorXd &b)
 Concatenate two vectors by appending b after a.
VectorXd sas::concatenate (const std::vector< VectorXd > &as)
 Concatenate a list of vectors into a single vector.
MatrixXd sas::vstack (const MatrixXd &A, const MatrixXd &B)
 Stack two matrices vertically (A above B).
MatrixXd sas::block_diag (const std::vector< MatrixXd > &As)
 Create a block-diagonal matrix from a list of matrices.
std::vector< VectorXd > sas::split (const VectorXd &a, const std::vector< int > &ns)
 Split a vector into pieces with sizes specified by ns.

Detailed Description

Core numerical utilities used across the project.

This header contains lightweight, frequently used functions such as incremental mean computation, vector/matrix concatenation, block-diagonal assembly and vector splitting utilities. These utilities are intended to be header-only and efficient for use in real-time control loops.

Enumeration Type Documentation

◆ Statistics

enum class sas::Statistics
strong

Statistical measures supported by sas_core utilities.

Enumeration of lightweight statistics that classes and functions may compute (for example, Clock statistics). Add new entries here as new statistics are supported.

Function Documentation

◆ block_diag()

MatrixXd sas::block_diag ( const std::vector< MatrixXd > & As)

Create a block-diagonal matrix from a list of matrices.

block_diag creates a block diagonal matrix using an input of std::vector<MatrixXd>. e.g. if As= [A, B, C], then block_diag(As) = |A 0 0| |0 B 0| |0 0 C|

Parameters
AsVector of matrices to place on the block diagonal.
Returns
Block-diagonal matrix containing the input matrices along its diagonal.
Parameters
Asthe std::vector<MatrixXd> contaning the matrix to form the block diagonal matrix.
Returns
the block diagonal matrix.

◆ concatenate() [1/2]

VectorXd sas::concatenate ( const std::vector< VectorXd > & as)

Concatenate a list of vectors into a single vector.

concatenate a std::vector of VectorXd.

Parameters
asVector of vectors to concatenate in order.
Returns
Concatenated vector containing the elements of each input vector in order.
Parameters
aan std::vector of VectorXd.
Returns
the result of the concatenated vectors.

◆ concatenate() [2/2]

VectorXd sas::concatenate ( const VectorXd & a,
const VectorXd & b )

Concatenate two vectors by appending b after a.

concatenate two VectorXd.

Parameters
aFirst vector.
bSecond vector.
Returns
Concatenated vector containing all elements of a followed by b.
Parameters
aa VectorXd.
ba VectorXd.
Returns
the result of the concatenated vectors.

◆ incremental_mean()

template<class T>
T sas::incremental_mean ( const T & current_mean,
const int & current_number_of_samples,
const T & new_sample )
constexpr

incremental_mean a simple implementation of incremental mean, for the many cases in which keeping a vector of all values would be impractical.

Parameters
current_meanthe current value of the mean.
current_number_of_samplesthe current number of samples, not considering the new_sample.
new_samplethe new sample that will change the mean.
Exceptions
std::range_errorif current_number_of_samples is negative.
Returns
the incremental mean, considering the new_sample.

◆ split()

std::vector< VectorXd > sas::split ( const VectorXd & a,
const std::vector< int > & ns )

Split a vector into pieces with sizes specified by ns.

split splits the input VectorXd as into a set of subvectors defined by ns.

Parameters
aVector to split.
nsSizes of each piece; their sum must equal a.size().
Returns
Vector containing the split VectorXd pieces.
Parameters
asthe VectorXd to be split.
nsthe sizes of the subvectors.
Returns
an std::vector<VectorXd> of the splitted vectors.

◆ vstack()

MatrixXd sas::vstack ( const MatrixXd & A,
const MatrixXd & B )

Stack two matrices vertically (A above B).

vstack vertically (row-wise) stack two MatrixXd.

Parameters
ATop matrix.
BBottom matrix.
Returns
Matrix formed by stacking A on top of B. Columns must match.
Exceptions
std::range_errorif A and B have different numbers of columns.
Parameters
Athe first MatrixXd.
Bthe second MatrixXd.
Returns
the vstacked MatrixXd.
Exceptions
astd::range_error if A and B don't have the same number of columns.
Note
returns an empty matrix if both arguments are empty or return the other argument of only one of the arguments is empty.