|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
A dense column-major matrix whose underlying storage capacity grows monotonically and is reused across resizes, unlike Eigen::Matrix<T, Dynamic, Dynamic> which reallocates on every resize() / conservativeResize() call. More...
#include <resizeable_matrix.h>
Public Types | |
| using | MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> |
Public Member Functions | |
| ResizeableMatrix ()=default | |
| ResizeableMatrix (Eigen::Index rows, Eigen::Index cols=1) | |
| Constructs a matrix of the given logical size and zero-initializes all entries. | |
| void | resizeAndSetZero (Eigen::Index rows, Eigen::Index cols=1) |
| Sets the logical size to rows x cols and zeroes every element. | |
| Eigen::Index | rows () const |
| Eigen::Index | cols () const |
| Eigen::Map< MatrixType, Eigen::Aligned128 > | mat () |
| Returns an aligned, mutable Eigen::Map view of the logical rows() x cols() matrix. | |
| Eigen::Map< const MatrixType, Eigen::Aligned128 > | mat () const |
| Const overload of mat(). | |
| Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, 1 >, Eigen::Aligned128 > | vec () |
| Returns an aligned, mutable Eigen::Map view interpreting the storage as a length-rows() column vector. | |
| Eigen::Map< const Eigen::Matrix< T, Eigen::Dynamic, 1 >, Eigen::Aligned128 > | vec () const |
| Const overload of vec(). | |
Static Public Attributes | |
| static constexpr std::size_t | kAlignment = 128 |
| Alignment in bytes for the underlying storage. | |
A dense column-major matrix whose underlying storage capacity grows monotonically and is reused across resizes, unlike Eigen::Matrix<T, Dynamic, Dynamic> which reallocates on every resize() / conservativeResize() call.
Motivation: solver inner loops repeatedly build matrices (e.g. blockwise Jacobians) whose logical dimensions vary slightly from iteration to iteration. Using a plain Eigen matrix triggers a heap allocation each time the size changes; this class amortizes those costs by only growing the backing buffer when the requested element count exceeds the current capacity. Storage shrinks only when the object is destroyed.
Capacity vs. logical size: rows() / cols() report the logical size requested by the last resizeAndSetZero(). The backing std::vector capacity may be larger and is never returned to the allocator while the object lives.
Layout: data is stored contiguously in column-major order (matching Eigen's default) and is aligned to kAlignment bytes so that the returned Eigen::Map<..., Eigen::Aligned128> can use aligned SIMD loads/stores.
Thread safety: not thread-safe. Concurrent calls to any non-const method, or a non-const method concurrent with any other access, are data races. Multiple readers via const accessors are safe provided no writer is active.
Definition at line 40 of file resizeable_matrix.h.
| using momentum::ResizeableMatrix< T >::MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> |
Definition at line 46 of file resizeable_matrix.h.
|
default |
|
inlineexplicit |
Constructs a matrix of the given logical size and zero-initializes all entries.
| rows | Number of rows in the logical matrix. |
| cols | Number of columns in the logical matrix; defaults to 1 (column vector). |
Definition at line 53 of file resizeable_matrix.h.
References cols(), resizeAndSetZero(), and rows().
|
inlinenodiscard |
Definition at line 83 of file resizeable_matrix.h.
Referenced by ResizeableMatrix(), and resizeAndSetZero().
|
inline |
Returns an aligned, mutable Eigen::Map view of the logical rows() x cols() matrix.
The map is invalidated by any subsequent call to resizeAndSetZero().
Definition at line 89 of file resizeable_matrix.h.
|
inline |
Const overload of mat().
Definition at line 94 of file resizeable_matrix.h.
|
inline |
Sets the logical size to rows x cols and zeroes every element.
The backing buffer is reused if its current capacity is sufficient; otherwise it grows. Capacity never shrinks. Any Eigen::Map previously returned by mat() / vec() is invalidated by this call (storage may have been reallocated, and existing contents are overwritten with zeros regardless).
| rows | Number of rows in the new logical matrix. |
| cols | Number of columns in the new logical matrix; defaults to 1. |
Definition at line 67 of file resizeable_matrix.h.
References cols(), and rows().
Referenced by ResizeableMatrix().
|
inlinenodiscard |
Definition at line 80 of file resizeable_matrix.h.
Referenced by ResizeableMatrix(), and resizeAndSetZero().
|
inline |
Returns an aligned, mutable Eigen::Map view interpreting the storage as a length-rows() column vector.
The cols() value is ignored; intended for the single-column case. The map is invalidated by any subsequent call to resizeAndSetZero(). TODO: vec() ignores cols_ and only exposes the first column when cols_ > 1. Either document this contract loudly or assert cols_ == 1.
Definition at line 103 of file resizeable_matrix.h.
|
inline |
Const overload of vec().
Definition at line 108 of file resizeable_matrix.h.
|
staticconstexpr |
Alignment in bytes for the underlying storage.
Chosen to satisfy Eigen::Aligned128 so the Eigen::Map accessors below can perform aligned SIMD loads/stores.
Definition at line 44 of file resizeable_matrix.h.