template struct mrpt::math::MatrixBlockSparseCols

A templated column-indexed efficient storage of block-sparse Jacobian or Hessian matrices, together with other arbitrary information.

Columns are stored in a non-associative container, but the contents of each column are kept within an std::map<> indexed by row. All submatrix blocks have the same size, which allows dense storage of them in fixed-size matrices, avoiding costly memory allocations.

Parameters:

NROWS

Rows in each elementary matrix.

NCOLS

Cols in each elementary matrix.

INFO

Type of the extra data fields within each block

HAS_REMAP

Is true, an inverse mapping between column indices and “user IDs” is kept.

INDEX_REMAP_MAP_IMPL

Ignore if HAS_REMAP=false. Defaults to “mrpt::containers::map_as_vector<size_t,size_t>” for amortized O(1). Can be set to “std::map<size_t,size_t>” in very sparse systems to save memory at the cost of a O(log N) access time when using the remap indices.

#include <mrpt/math/MatrixBlockSparseCols.h>

template <
    typename Scalar,
    int NROWS,
    int NCOLS,
    typename INFO,
    bool HAS_REMAP,
    typename INDEX_REMAP_MAP_IMPL = mrpt::containers::map_as_vector<size_t, size_t>
    >
struct MatrixBlockSparseCols
{
    // typedefs

    typedef Eigen::Matrix<Scalar, NROWS, NCOLS> matrix_t;
    typedef INFO symbolic_t;
    typedef std::map<size_t, TEntry> col_t;

    // structs

    struct TEntry;

    // construction

    MatrixBlockSparseCols();

    //
methods

    col_t& getCol(size_t idx);
    const col_t& getCol(size_t idx) const;
    const mrpt::containers::map_as_vector<size_t, size_t>& getColInverseRemappedIndices() const;
    const std::vector<size_t>& getColRemappedIndices() const;
    col_t& appendCol(size_t remapIndex);
    void setColCount(size_t nCols);
    size_t cols() const;
    void clearColEntries();
    void clearAll();

    void saveToTextFileAsDense(
        const std::string& filename,
        const bool force_symmetry = false,
        const bool is_col_compressed = true
        ) const;

    void getAsDense(
        mrpt::math::CMatrixDouble& D,
        const bool force_symmetry = false,
        const bool is_col_compressed = true
        ) const;

    size_t findCurrentNumberOfRows() const;

    template <class MATRIX>
    void getBinaryBlocksRepresentation(MATRIX& out) const;

    void copyNumericalValuesFrom(const MatrixBlockSparseCols<Scalar, NROWS, NCOLS, INFO, HAS_REMAP>& o);
};

Typedefs

typedef std::map<size_t, TEntry> col_t

Each compressed sparse column.

Methods

col_t& appendCol(size_t remapIndex)

Append one column, returning a ref to the new col_t data.

void setColCount(size_t nCols)

Change the number of columns (keep old contents)

size_t cols() const

Get current number of cols.

See also:

findCurrentNumberOfRows

void clearColEntries()

Clear all the entries in each column (do not change the number of columns, though!)

See also:

getColCount

void clearAll()

Clear all the entries in each column (do not change the number of columns, though!)

See also:

getColCount

void saveToTextFileAsDense(
    const std::string& filename,
    const bool force_symmetry = false,
    const bool is_col_compressed = true
    ) const

Builds a dense representation of the matrix and saves to a text file.

void getAsDense(
    mrpt::math::CMatrixDouble& D,
    const bool force_symmetry = false,
    const bool is_col_compressed = true
    ) const

Builds a dense representation of the matrix and saves to a text file.

Parameters:

is_col_compressed

true: interpret this object as compressed by cols; false: compressed by rows

size_t findCurrentNumberOfRows() const

Goes over all the columns and keep the largest column length.

See also:

cols()

template <class MATRIX>
void getBinaryBlocksRepresentation(MATRIX& out) const

Builds a binary matrix with 1s where an elementary matrix is stored, 0s elsewhere.

void copyNumericalValuesFrom(const MatrixBlockSparseCols<Scalar, NROWS, NCOLS, INFO, HAS_REMAP>& o)

Clear the current contents of this objects and replicates the sparse structure and numerical values of o.