37template <
typename MatrixType>
40 using VectorType = Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic, 1>;
45 Eigen::Ref<MatrixType> mat,
47 : mat_(mat), columnIndices_(colIndices), useColumnIndices_(true) {
51 [[nodiscard]]
auto col(Eigen::Index colIdx) {
52 if (useColumnIndices_) {
53 return mat_.col(columnIndices_[colIdx]);
55 return mat_.col(colIdx);
59 [[nodiscard]]
auto rows()
const {
63 [[nodiscard]]
auto cols()
const {
64 if (useColumnIndices_) {
65 return (Eigen::Index)columnIndices_.size();
72 return columnIndices_;
79 if (useColumnIndices_) {
81 for (Eigen::Index iCol = 0; iCol < (Eigen::Index)columnIndices_.size(); ++iCol) {
82 result[iCol] = mat_.col(columnIndices_[iCol]).dot(b);
86 return mat_.transpose() * b;
91 Eigen::Ref<MatrixType> mat_;
93 bool useColumnIndices_;
156 using MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
173 void addMutating(Eigen::Ref<MatrixType> A, Eigen::Ref<VectorType> b) {
215 void reset(Eigen::Index n, T lambda = T(0));
262 using MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
285 Eigen::Ref<MatrixType> A_diag,
286 Eigen::Ref<MatrixType> A_common,
287 Eigen::Ref<VectorType> b) {
312 Eigen::Ref<VectorType> b);
333 return R_ii_[iBlock];
346 [[nodiscard]] T
At_times_b_dot(Eigen::Ref<const VectorType> rhs)
const;
351 const double lambda_;
360 std::deque<MatrixType> R_ii_;
361 std::deque<MatrixType> R_in_;
366 std::deque<VectorType> y_i_;
408 using MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
436 const Eigen::Index iCol_offset,
437 Eigen::Ref<MatrixType> A_band,
438 Eigen::Ref<MatrixType> A_common,
439 Eigen::Ref<VectorType> b) {
448 void addMutating(Eigen::Ref<MatrixType> A_common, Eigen::Ref<VectorType> b) {
463 Eigen::Index iCol_offset,
466 Eigen::Ref<VectorType> b);
489 Eigen::Index iCol_offset,
492 Eigen::Ref<VectorType> b);
518 return R_band_.rows();
521 [[nodiscard]] Eigen::Index
n_band()
const {
522 return R_band_.cols();
526 return R_common_.cols();
532 void initializeDiagonal();
534 [[nodiscard]] T R_band_entry(Eigen::Index iRow, Eigen::Index jCol)
const {
538 return R_band_(
bandwidth + iRow - jCol - 1, jCol);
541 [[nodiscard]] T& R_band_entry(Eigen::Index iRow, Eigen::Index jCol) {
545 return R_band_(
bandwidth + iRow - jCol - 1, jCol);
548 const double lambda_;
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
View over a matrix that exposes a (possibly reordered) subset of its columns.
momentum::span< const Eigen::Index > columnIndices() const
auto col(Eigen::Index colIdx)
ColumnIndexedMatrix(Eigen::Ref< MatrixType > mat)
VectorType transpose_times(Eigen::Ref< VectorType > b) const
Computes this->transpose() * b, returning a vector of length cols().
ColumnIndexedMatrix(Eigen::Ref< MatrixType > mat, momentum::span< const Eigen::Index > colIndices)
Eigen::Matrix< typename MatrixType::Scalar, Eigen::Dynamic, 1 > VectorType
Eigen::Matrix< T, Eigen::Dynamic, 1 > VectorType
Eigen::Index bandwidth() const
VectorType x_dense() const
Retrieves the full dense result vector of length n_band() + n_common().
void add(size_t iCol_offset, MatrixType A_band, MatrixType A_common, VectorType b)
Copying overload of addMutating() that takes both banded and common contributions.
Eigen::Index n_common() const
VectorType At_times_b() const
MatrixType y_dense() const
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixType
void add(MatrixType A_common, VectorType b)
Copying overload for contributions that only touch the common columns.
void zeroBandedPart(Eigen::Index iCol_offset, ColumnIndexedMatrix< MatrixType > A_band, ColumnIndexedMatrix< MatrixType > A_common, Eigen::Ref< VectorType > b)
Zeros out just the banded part of A_band by applying Householder rotations.
void addMutating(const Eigen::Index iCol_offset, Eigen::Ref< MatrixType > A_band, Eigen::Ref< MatrixType > A_common, Eigen::Ref< VectorType > b)
In-place addition; convenience wrapper that wraps the matrices in ColumnIndexedMatrix views without r...
Eigen::Index n_band() const
MatrixType R_dense() const
void reset()
Discards accumulated state, keeping the existing dimensions and damping.
void addMutating(Eigen::Ref< MatrixType > A_common, Eigen::Ref< VectorType > b)
In-place addition for contributions that only touch the common columns.
OnlineBandedHouseholderQR(Eigen::Index n_band, Eigen::Index n_common, Eigen::Index bandwidth, T lambda=T(0))
Constructs a banded solver.
MatrixType R_dense() const
VectorType At_times_b_dense() const
VectorType x_i(size_t iBlock) const
Retrieves the answer for a single diagonal block iBlock.
VectorType x_n() const
Retrieves the answer for just the final "common" rows.
OnlineBlockHouseholderQR(Eigen::Index n_common, T lambda=T(0))
Constructs a solver for problems with n_common shared unknowns.
const MatrixType & R_ii(size_t iBlock) const
VectorType x_dense() const
Retrieves the full dense result [x_0; x_1; ...; x_{B-1}; x_n].
T At_times_b_dot(Eigen::Ref< const VectorType > rhs) const
MatrixType y_dense() const
void addMutating(size_t iBlock, Eigen::Ref< MatrixType > A_diag, Eigen::Ref< MatrixType > A_common, Eigen::Ref< VectorType > b)
In-place addition; convenience wrapper that wraps the matrices in ColumnIndexedMatrix views without r...
const VectorType & y_i(size_t iBlock) const
Eigen::Matrix< T, Eigen::Dynamic, 1 > VectorType
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixType
VectorType At_times_b_i(size_t iBlock) const
VectorType At_times_b_n() const
void add(size_t iBlock, MatrixType A_diag, MatrixType A_common, VectorType b)
Copying overload of addMutating().
const MatrixType & R() const
const VectorType & y() const
void reset()
Discards accumulated state, keeping the existing n and lambda.
Eigen::Matrix< T, Eigen::Dynamic, 1 > VectorType
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixType
void add(MatrixType A, VectorType b)
Copying overload of addMutating().
OnlineHouseholderQR(Eigen::Index n, T lambda=T(0))
Constructs a solver for problems with n unknowns.
VectorType result() const
Solves R * x = y by back-substitution using the currently accumulated state and returns x.
VectorType At_times_b() const
void addMutating(Eigen::Ref< MatrixType > A, Eigen::Ref< VectorType > b)
In-place overload: factorizes A and b directly, mutating both buffers.
void validateColumnIndices(momentum::span< const Eigen::Index > colIndices, Eigen::Index maxEntry)
Validates that every entry in colIndices is in [0, maxEntry); throws otherwise.
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
Provides a C++17-compatible span type alias.