COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
copp::Matrix Class Reference

Lightweight owned column-major matrix. More...

#include <core.hpp>

Public Member Functions

 Matrix ()=default
 Matrix (std::size_t rows, std::size_t cols)
 Matrix (std::size_t rows, std::size_t cols, std::vector< double > data)
std::size_t rows () const noexcept
std::size_t cols () const noexcept
std::size_t size () const noexcept
bool empty () const noexcept
double * data () noexcept
const double * data () const noexcept
std::vector< double > & values () noexcept
const std::vector< double > & values () const noexcept
MatrixView view () const noexcept
double & operator() (std::size_t row, std::size_t col) noexcept
double operator() (std::size_t row, std::size_t col) const noexcept

Static Public Member Functions

static Matrix from_rows (std::initializer_list< std::initializer_list< double > > rows)
 Build a matrix from row-major initializer-list notation.
static Matrix from_columns (std::initializer_list< std::initializer_list< double > > columns)
 Build a matrix from column-major initializer-list notation.

Detailed Description

Lightweight owned column-major matrix.

This type is intentionally just storage plus shape. It does not implement linear algebra. The data layout is always column-major and matches nalgebra: matrix(row, col) is stored at row + col * rows().

Eigen integration lives in copp/eigen.hpp as adapters over this storage rather than changing the core return type. This keeps the core API usable without Eigen while still making Eigen views cheap for common users.

auto waypoints = copp::Matrix::from_columns({
{0.0, 0.0},
{0.5, 0.25},
{1.0, 1.0},
});
std::cout << waypoints(1, 2) << "\n"; // 1.0
static Matrix from_columns(std::initializer_list< std::initializer_list< double > > columns)
Build a matrix from column-major initializer-list notation.
Definition core.hpp:433

Definition at line 351 of file core.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

copp::Matrix::Matrix ( )
default

◆ Matrix() [2/3]

copp::Matrix::Matrix ( std::size_t rows,
std::size_t cols )
inline

Definition at line 356 of file core.hpp.

◆ Matrix() [3/3]

copp::Matrix::Matrix ( std::size_t rows,
std::size_t cols,
std::vector< double > data )
inline

Definition at line 359 of file core.hpp.

Member Function Documentation

◆ from_rows()

Matrix copp::Matrix::from_rows ( std::initializer_list< std::initializer_list< double > > rows)
inlinestatic

Build a matrix from row-major initializer-list notation.

Parameters
rowsOuter list of matrix rows. Every row must have the same number of columns.
Returns
An owned column-major Matrix containing the same logical values.
Exceptions
copp::Errorif input is empty or not rectangular.
auto matrix = copp::Matrix::from_rows({
{0.0, 0.5, 1.0},
{0.0, 0.25, 1.0},
});
static Matrix from_rows(std::initializer_list< std::initializer_list< double > > rows)
Build a matrix from row-major initializer-list notation.
Definition core.hpp:382

Definition at line 382 of file core.hpp.

◆ from_columns()

Matrix copp::Matrix::from_columns ( std::initializer_list< std::initializer_list< double > > columns)
inlinestatic

Build a matrix from column-major initializer-list notation.

This is convenient for waypoint paths because COPP represents waypoint matrices as (dim x n_points), where each column is one waypoint:

Parameters
columnsOuter list of waypoint columns. Every column must have the same dimension.
Returns
An owned column-major Matrix.
Exceptions
copp::Errorif input is empty or not rectangular.
auto waypoints = copp::Matrix::from_columns({
{0.0, 0.0},
{0.5, 0.25},
{1.0, 1.0},
});

Definition at line 433 of file core.hpp.

◆ rows()

std::size_t copp::Matrix::rows ( ) const
inlinenoexcept

Definition at line 466 of file core.hpp.

◆ cols()

std::size_t copp::Matrix::cols ( ) const
inlinenoexcept

Definition at line 467 of file core.hpp.

◆ size()

std::size_t copp::Matrix::size ( ) const
inlinenoexcept

Definition at line 468 of file core.hpp.

◆ empty()

bool copp::Matrix::empty ( ) const
inlinenoexcept

Definition at line 469 of file core.hpp.

◆ data() [1/2]

double * copp::Matrix::data ( )
inlinenoexcept

Definition at line 471 of file core.hpp.

◆ data() [2/2]

const double * copp::Matrix::data ( ) const
inlinenoexcept

Definition at line 472 of file core.hpp.

◆ values() [1/2]

std::vector< double > & copp::Matrix::values ( )
inlinenoexcept

Definition at line 474 of file core.hpp.

◆ values() [2/2]

const std::vector< double > & copp::Matrix::values ( ) const
inlinenoexcept

Definition at line 475 of file core.hpp.

◆ view()

MatrixView copp::Matrix::view ( ) const
inlinenoexcept

Definition at line 477 of file core.hpp.

◆ operator()() [1/2]

double & copp::Matrix::operator() ( std::size_t row,
std::size_t col )
inlinenoexcept

Definition at line 482 of file core.hpp.

◆ operator()() [2/2]

double copp::Matrix::operator() ( std::size_t row,
std::size_t col ) const
inlinenoexcept

Definition at line 487 of file core.hpp.


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