23template <
typename Mat>
38 if (
this == &values) {
42 if (m_mat ==
nullptr) {
44 m_row_slice = values.m_row_slice;
45 m_row_slice_length = values.m_row_slice_length;
46 m_col_slice = values.m_col_slice;
47 m_col_slice_length = values.m_col_slice_length;
73 if (
this == &values) {
77 if (m_mat ==
nullptr) {
79 m_row_slice = values.m_row_slice;
80 m_row_slice_length = values.m_row_slice_length;
81 m_col_slice = values.m_col_slice;
82 m_col_slice_length = values.m_col_slice_length;
103 m_row_slice{0, mat.
rows(), 1},
104 m_row_slice_length{m_row_slice.adjust(mat.
rows())},
105 m_col_slice{0, mat.
cols(), 1},
106 m_col_slice_length{m_col_slice.adjust(mat.
cols())} {}
120 m_row_slice{row_offset, row_offset + block_rows, 1},
121 m_row_slice_length{m_row_slice.adjust(mat.
rows())},
122 m_col_slice{col_offset, col_offset + block_cols, 1},
123 m_col_slice_length{m_col_slice.adjust(mat.
cols())} {}
137 Slice col_slice,
int col_slice_length)
139 m_row_slice{
std::move(row_slice)},
140 m_row_slice_length{row_slice_length},
141 m_col_slice{
std::move(col_slice)},
142 m_col_slice_length{col_slice_length} {}
155 (*this)(0, 0) =
value;
179 template <
typename Derived>
197 template <
typename Derived>
198 requires std::same_as<typename Derived::Scalar, double>
199 void set_value(
const Eigen::MatrixBase<Derived>& values) {
251 requires(!std::is_const_v<Mat>)
255 return (*m_mat)(m_row_slice.
start +
row * m_row_slice.
step,
269 return (*m_mat)(m_row_slice.
start +
row * m_row_slice.
step,
280 requires(!std::is_const_v<Mat>)
312 return (*
this)({row_offset, row_offset + block_rows, 1},
313 {col_offset, col_offset + block_cols, 1});
326 int block_rows,
int block_cols)
const {
331 return (*
this)({row_offset, row_offset + block_rows, 1},
332 {col_offset, col_offset + block_cols, 1});
343 int row_slice_length = row_slice.
adjust(m_row_slice_length);
344 int col_slice_length = col_slice.
adjust(m_col_slice_length);
363 Slice col_slice)
const {
364 int row_slice_length = row_slice.
adjust(m_row_slice_length);
365 int col_slice_length = col_slice.
adjust(m_col_slice_length);
389 Slice col_slice,
int col_slice_length) {
413 int row_slice_length,
415 int col_slice_length)
const {
436 return block(offset, 0, length, 1);
449 return block(offset, 0, length, 1);
505 for (
int i = 0; i <
rows(); ++i) {
506 for (
int j = 0; j < rhs.cols(); ++j) {
508 for (
int k = 0; k <
cols(); ++k) {
509 sum += (*this)(i, k) * rhs(k, j);
541 slp_assert(rhs.rows() == 1 && rhs.cols() == 1);
545 (*this)(
row,
col) /= rhs(0, 0);
645 return (*
this)(0, 0);
653 std::remove_cv_t<Mat>
T()
const {
654 std::remove_cv_t<Mat> result{Mat::empty,
cols(),
rows()};
670 int rows()
const {
return m_row_slice_length; }
677 int cols()
const {
return m_col_slice_length; }
689 return (*m_mat)(m_row_slice.
start +
row * m_row_slice.
step,
711 Eigen::MatrixXd result{
rows(),
cols()};
730 std::remove_cv_t<Mat> result{Mat::empty,
rows(),
cols()};
741#ifndef DOXYGEN_SHOULD_SKIP_THIS
754 : m_mat{mat}, m_index{
index} {}
787 : m_mat{mat}, m_index{
index} {}
803 return (*m_mat)[m_index];
863 Mat* m_mat =
nullptr;
866 int m_row_slice_length = 0;
869 int m_col_slice_length = 0;
#define slp_assert(condition)
Abort in C++.
Definition assert.hpp:26
Represents a sequence of elements in an iterable object.
Definition slice.hpp:31
int step
Step.
Definition slice.hpp:40
int stop
Stop index (exclusive).
Definition slice.hpp:37
constexpr int adjust(int length)
Adjusts start and end slice indices assuming a sequence of the specified length.
Definition slice.hpp:134
int start
Start index (inclusive).
Definition slice.hpp:34
Definition variable_block.hpp:776
constexpr bool operator==(const const_iterator &) const noexcept=default
constexpr const_iterator() noexcept=default
std::forward_iterator_tag iterator_category
Definition variable_block.hpp:778
constexpr const_reference operator*() const noexcept
Definition variable_block.hpp:802
std::ptrdiff_t difference_type
Definition variable_block.hpp:780
constexpr const_iterator operator++(int) noexcept
Definition variable_block.hpp:794
constexpr const_iterator & operator++() noexcept
Definition variable_block.hpp:789
Definition variable_block.hpp:743
constexpr iterator operator++(int) noexcept
Definition variable_block.hpp:761
constexpr bool operator==(const iterator &) const noexcept=default
std::ptrdiff_t difference_type
Definition variable_block.hpp:747
constexpr iterator & operator++() noexcept
Definition variable_block.hpp:756
constexpr iterator() noexcept=default
std::forward_iterator_tag iterator_category
Definition variable_block.hpp:745
constexpr reference operator*() const noexcept
Definition variable_block.hpp:769
A submatrix of autodiff variables with reference semantics.
Definition variable_block.hpp:24
VariableBlock< Mat > & operator=(const Mat &values)
Assigns a VariableMatrix to the block.
Definition variable_block.hpp:215
VariableBlock< Mat > & operator*=(const ScalarLike auto &rhs)
Compound matrix multiplication-assignment operator.
Definition variable_block.hpp:524
const_iterator begin() const
Returns begin iterator.
Definition variable_block.hpp:832
const_iterator end() const
Returns end iterator.
Definition variable_block.hpp:839
const Variable & operator()(int row, int col) const
Returns a scalar subblock at the given row and column.
Definition variable_block.hpp:266
Eigen::MatrixXd value()
Returns the contents of the variable matrix.
Definition variable_block.hpp:710
const_iterator cbegin() const
Returns begin iterator.
Definition variable_block.hpp:846
VariableBlock< Mat > row(int row)
Returns a row slice of the variable matrix.
Definition variable_block.hpp:458
Variable & operator[](int row)
Returns a scalar subblock at the given row.
Definition variable_block.hpp:279
VariableBlock< Mat > & operator=(ScalarLike auto value)
Assigns a double to the block.
Definition variable_block.hpp:152
VariableBlock< Mat > & operator+=(const MatrixLike auto &rhs)
Compound addition-assignment operator.
Definition variable_block.hpp:574
std::remove_cv_t< Mat > cwise_transform(function_ref< Variable(const Variable &x)> unary_op) const
Transforms the matrix coefficient-wise with an unary operator.
Definition variable_block.hpp:728
VariableBlock< Mat > & operator*=(const MatrixLike auto &rhs)
Compound matrix multiplication-assignment operator.
Definition variable_block.hpp:502
iterator begin()
Returns begin iterator.
Definition variable_block.hpp:818
VariableBlock(VariableBlock< Mat > &&)=default
Move constructor.
VariableBlock< Mat > & operator=(const VariableBlock< Mat > &values)
Assigns a VariableBlock to the block.
Definition variable_block.hpp:37
VariableBlock< const Mat > col(int col) const
Returns a column slice of the variable matrix.
Definition variable_block.hpp:491
Variable & operator()(int row, int col)
Returns a scalar subblock at the given row and column.
Definition variable_block.hpp:250
int rows() const
Returns the number of rows in the matrix.
Definition variable_block.hpp:670
double value(int row, int col)
Returns an element of the variable matrix.
Definition variable_block.hpp:686
const VariableBlock< const Mat > operator()(Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length) const
Returns a slice of the variable matrix.
Definition variable_block.hpp:412
const Variable & operator[](int row) const
Returns a scalar subblock at the given row.
Definition variable_block.hpp:292
VariableBlock< Mat > col(int col)
Returns a column slice of the variable matrix.
Definition variable_block.hpp:480
VariableBlock< Mat > & operator=(const Eigen::MatrixBase< Derived > &values)
Assigns an Eigen matrix to the block.
Definition variable_block.hpp:180
VariableBlock< Mat > operator()(Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length)
Returns a slice of the variable matrix.
Definition variable_block.hpp:388
VariableBlock< Mat > & operator=(Mat &&values)
Assigns a VariableMatrix to the block.
Definition variable_block.hpp:232
const_iterator cend() const
Returns end iterator.
Definition variable_block.hpp:853
void set_value(const Eigen::MatrixBase< Derived > &values)
Sets block's internal values.
Definition variable_block.hpp:199
VariableBlock< Mat > & operator/=(const MatrixLike auto &rhs)
Compound matrix division-assignment operator.
Definition variable_block.hpp:540
VariableBlock< Mat > & operator-=(const ScalarLike auto &rhs)
Compound subtraction-assignment operator.
Definition variable_block.hpp:628
VariableBlock(Mat &mat, int row_offset, int col_offset, int block_rows, int block_cols)
Constructs a Variable block pointing to a subset of the given matrix.
Definition variable_block.hpp:117
VariableBlock< Mat > & operator/=(const ScalarLike auto &rhs)
Compound matrix division-assignment operator.
Definition variable_block.hpp:558
VariableBlock< Mat > segment(int offset, int length)
Returns a segment of the variable vector.
Definition variable_block.hpp:433
VariableBlock< Mat > & operator-=(const MatrixLike auto &rhs)
Compound subtraction-assignment operator.
Definition variable_block.hpp:610
VariableBlock< Mat > & operator+=(const ScalarLike auto &rhs)
Compound addition-assignment operator.
Definition variable_block.hpp:592
iterator end()
Returns end iterator.
Definition variable_block.hpp:825
double value(int index)
Returns a row of the variable column vector.
Definition variable_block.hpp:700
VariableBlock(Mat &mat)
Constructs a Variable block pointing to all of the given matrix.
Definition variable_block.hpp:101
VariableBlock< const Mat > row(int row) const
Returns a row slice of the variable matrix.
Definition variable_block.hpp:469
const VariableBlock< const Mat > operator()(Slice row_slice, Slice col_slice) const
Returns a slice of the variable matrix.
Definition variable_block.hpp:362
const VariableBlock< Mat > segment(int offset, int length) const
Returns a segment of the variable vector.
Definition variable_block.hpp:446
int cols() const
Returns the number of columns in the matrix.
Definition variable_block.hpp:677
VariableBlock< Mat > block(int row_offset, int col_offset, int block_rows, int block_cols)
Returns a block of the variable matrix.
Definition variable_block.hpp:306
size_t size() const
Returns number of elements in matrix.
Definition variable_block.hpp:860
std::remove_cv_t< Mat > T() const
Returns the transpose of the variable matrix.
Definition variable_block.hpp:653
VariableBlock(const VariableBlock< Mat > &)=default
Copy constructor.
VariableBlock< Mat > & operator=(VariableBlock< Mat > &&values)
Assigns a VariableBlock to the block.
Definition variable_block.hpp:72
VariableBlock(Mat &mat, Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length)
Constructs a Variable block pointing to a subset of the given matrix.
Definition variable_block.hpp:136
VariableBlock< Mat > operator()(Slice row_slice, Slice col_slice)
Returns a slice of the variable matrix.
Definition variable_block.hpp:342
const VariableBlock< const Mat > block(int row_offset, int col_offset, int block_rows, int block_cols) const
Returns a block slice of the variable matrix.
Definition variable_block.hpp:325
void set_value(double value)
Assigns a double to the block.
Definition variable_block.hpp:167
An autodiff variable pointing to an expression node.
Definition variable.hpp:40
Definition function_ref.hpp:13
Definition concepts.hpp:40
Definition concepts.hpp:13
Definition expression_graph.hpp:11
Definition PointerIntPair.h:280