9#include <initializer_list>
19#include <gch/small_vector.hpp>
21#include "sleipnir/autodiff/expression_graph.hpp"
22#include "sleipnir/autodiff/sleipnir_base.hpp"
23#include "sleipnir/autodiff/slice.hpp"
24#include "sleipnir/autodiff/variable.hpp"
25#include "sleipnir/autodiff/variable_block.hpp"
26#include "sleipnir/util/assert.hpp"
27#include "sleipnir/util/concepts.hpp"
28#include "sleipnir/util/empty.hpp"
29#include "sleipnir/util/function_ref.hpp"
30#include "sleipnir/util/symbol_exports.hpp"
37template <
typename Scalar_>
58 for (
int index = 0; index <
rows *
cols; ++index) {
59 m_storage.emplace_back();
70 for (
int index = 0; index <
rows *
cols; ++index) {
71 m_storage.emplace_back(
nullptr);
83 if (list.size() > 0) {
84 m_cols = list.begin()->size();
89 const auto&
row : list) {
90 slp_assert(
static_cast<int>(
row.size()) == m_cols);
94 for (
const auto&
row : list) {
95 std::ranges::copy(
row, std::back_inserter(m_storage));
107 m_rows = list.size();
109 if (list.size() > 0) {
110 m_cols = list.begin()->size();
115 const auto&
row : list) {
116 slp_assert(
static_cast<int>(
row.size()) == m_cols);
120 for (
const auto&
row : list) {
121 std::ranges::copy(
row, std::back_inserter(m_storage));
133 m_rows = list.size();
135 if (list.size() > 0) {
136 m_cols = list.begin()->size();
141 const auto&
row : list) {
142 slp_assert(
static_cast<int>(
row.size()) == m_cols);
146 for (
const auto&
row : list) {
147 std::ranges::copy(
row, std::back_inserter(m_storage));
154 template <
typename Derived>
170 template <
typename Derived>
179 m_storage.emplace_back(
values.diagonal()[
row]);
181 m_storage.emplace_back(
Scalar(0));
200 m_storage.emplace_back(std::move(
variable));
264 template <
typename Derived>
284 slp_assert(
rows() == 1 &&
cols() == 1);
286 (*this)[0, 0] =
value;
294 template <
typename Derived>
295 requires std::same_as<typename Derived::Scalar, Scalar>
333 slp_assert(index >= 0 && index <
rows() *
cols());
334 return m_storage[index];
342 slp_assert(index >= 0 && index <
rows() *
cols());
343 return m_storage[index];
446 slp_assert(
cols() == 1);
459 slp_assert(
cols() == 1);
505 template <EigenMatrixLike LHS, SleipnirMatrixLike<Scalar> RHS>
507 slp_assert(
lhs.cols() ==
rhs.rows());
511 for (
int i = 0;
i <
lhs.rows(); ++
i) {
512 for (
int j = 0;
j <
rhs.cols(); ++
j) {
514 for (
int k = 0;
k <
lhs.cols(); ++
k) {
528 template <SleipnirMatrixLike<Scalar> LHS, EigenMatrixLike RHS>
530 slp_assert(
lhs.cols() ==
rhs.rows());
534 for (
int i = 0;
i <
lhs.rows(); ++
i) {
535 for (
int j = 0;
j <
rhs.cols(); ++
j) {
537 for (
int k = 0;
k <
lhs.cols(); ++
k) {
551 template <SleipnirMatrixLike<Scalar> LHS, SleipnirMatrixLike<Scalar> RHS>
553 slp_assert(
lhs.cols() ==
rhs.rows());
557 for (
int i = 0;
i <
lhs.rows(); ++
i) {
558 for (
int j = 0;
j <
rhs.cols(); ++
j) {
560 for (
int k = 0;
k <
lhs.cols(); ++
k) {
574 template <SleipnirMatrixLike<Scalar> LHS, ScalarLike RHS>
591 template <ScalarLike LHS, SleipnirMatrixLike<Scalar> RHS>
611 for (
int i = 0;
i <
rows(); ++
i) {
613 for (
int j = 0;
j <
rhs.cols(); ++
j) {
615 for (
int k = 0;
k <
cols(); ++
k) {
644 template <SleipnirMatrixLike<Scalar> LHS, ScalarLike RHS>
663 template <SleipnirMatrixLike<Scalar> LHS>
696 template <EigenMatrixLike LHS, SleipnirMatrixLike<Scalar> RHS>
698 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
716 template <SleipnirMatrixLike<Scalar> LHS, EigenMatrixLike RHS>
718 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
736 template <SleipnirMatrixLike<Scalar> LHS, SleipnirMatrixLike<Scalar> RHS>
738 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
772 slp_assert(
rows() == 1 &&
cols() == 1);
788 template <EigenMatrixLike LHS, SleipnirMatrixLike<Scalar> RHS>
790 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
808 template <SleipnirMatrixLike<Scalar> LHS, EigenMatrixLike RHS>
810 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
828 template <SleipnirMatrixLike<Scalar> LHS, SleipnirMatrixLike<Scalar> RHS>
830 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
864 slp_assert(
rows() == 1 &&
cols() == 1);
894 slp_assert(
rows() == 1 &&
cols() == 1);
895 return (*
this)[0, 0];
916 int rows()
const {
return m_rows; }
921 int cols()
const {
return m_cols; }
954 Eigen::MatrixX<Variable<Scalar>>
to_eigen()
const {
1013 constexpr std::array
p{
Scalar(1.0L),
1014 Scalar(0.499999999999999999999987615564159L),
1015 Scalar(0.119999999999999999999993719796468L),
1016 Scalar(0.0183333333333333333333318078905823L),
1017 Scalar(0.00199275362318840579710121408775205L),
1018 Scalar(0.00016304347826086956521736560868541L),
1019 Scalar(1.03519668737060041407846479512981e-05L),
1020 Scalar(5.17598343685300207039205144279119e-07L),
1021 Scalar(2.04315135665250081725989398668247e-08L),
1022 Scalar(6.30602270571759511499920806570486e-10L),
1023 Scalar(1.48377004840414002705850442238441e-11L),
1024 Scalar(2.52915349159796595521307855480881e-13L),
1025 Scalar(2.81017054621996217245857568431558e-15L),
1026 Scalar(1.54404975067030888596595580141692e-17L)};
1027 constexpr std::array
q{
Scalar(1.0L),
1028 Scalar(-0.500000000000000000000012384435841L),
1029 Scalar(0.120000000000000000000006104232309L),
1030 Scalar(-0.0183333333333333333333347707904729L),
1031 Scalar(0.00199275362318840579710166350137732L),
1032 Scalar(-0.000163043478260869565217413851346892L),
1033 Scalar(1.03519668737060041407885187519331e-05L),
1034 Scalar(-5.17598343685300207039443859549262e-07L),
1035 Scalar(2.04315135665250081726103781506842e-08L),
1036 Scalar(-6.30602270571759511500345035969254e-10L),
1037 Scalar(1.48377004840414002705969744674248e-11L),
1038 Scalar(-2.52915349159796595521550648156349e-13L),
1039 Scalar(2.81017054621996217246180850207342e-15L),
1040 Scalar(-1.54404975067030888596810607146175e-17L)};
1052 Eigen::VectorX<Scalar>::Constant(
rows(),
p[0]).asDiagonal()};
1054 Eigen::VectorX<Scalar>::Constant(
rows(),
q[0]).asDiagonal()};
1075 Q.T().to_eigen().lu().solve(
P.T().to_eigen()).transpose()};
1078#ifndef DOXYGEN_SHOULD_SKIP_THIS
1094 constexpr iterator& operator++() noexcept {
1099 constexpr iterator operator++(
int)
noexcept {
1100 iterator retval = *
this;
1105 constexpr iterator& operator--() noexcept {
1110 constexpr iterator operator--(
int)
noexcept {
1111 iterator retval = *
this;
1116 constexpr bool operator==(
const iterator&)
const noexcept =
default;
1118 constexpr reference operator*() const noexcept {
return *m_it; }
1121 gch::small_vector<Variable<Scalar>>::iterator m_it;
1124 class const_iterator {
1126 using iterator_category = std::bidirectional_iterator_tag;
1127 using value_type = Variable<Scalar>;
1128 using difference_type = std::ptrdiff_t;
1129 using pointer = Variable<Scalar>*;
1130 using const_reference =
const Variable<Scalar>&;
1132 constexpr const_iterator() noexcept = default;
1134 explicit constexpr const_iterator(
1135 gch::small_vector<Variable<Scalar>>::const_iterator it) noexcept
1138 constexpr const_iterator& operator++() noexcept {
1143 constexpr const_iterator operator++(
int)
noexcept {
1144 const_iterator retval = *
this;
1149 constexpr const_iterator& operator--() noexcept {
1154 constexpr const_iterator operator--(
int)
noexcept {
1155 const_iterator retval = *
this;
1160 constexpr bool operator==(
const const_iterator&)
const noexcept =
default;
1162 constexpr const_reference operator*() const noexcept {
return *m_it; }
1165 gch::small_vector<Variable<Scalar>>::const_iterator m_it;
1168 using reverse_iterator = std::reverse_iterator<iterator>;
1169 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1176 iterator
begin() {
return iterator{m_storage.begin()}; }
1181 iterator
end() {
return iterator{m_storage.end()}; }
1186 const_iterator
begin()
const {
return const_iterator{m_storage.begin()}; }
1191 const_iterator
end()
const {
return const_iterator{m_storage.end()}; }
1196 const_iterator
cbegin()
const {
return const_iterator{m_storage.cbegin()}; }
1201 const_iterator
cend()
const {
return const_iterator{m_storage.cend()}; }
1206 reverse_iterator
rbegin() {
return reverse_iterator{
end()}; }
1211 reverse_iterator
rend() {
return reverse_iterator{
begin()}; }
1217 return const_reverse_iterator{
end()};
1223 const_reverse_iterator
rend()
const {
1224 return const_reverse_iterator{
begin()};
1231 return const_reverse_iterator{
cend()};
1238 return const_reverse_iterator{
cbegin()};
1244 size_t size()
const {
return m_storage.size(); }
1309 gch::small_vector<Variable<Scalar>> m_storage;
1314template <
typename Derived>
1315VariableMatrix(
const Eigen::MatrixBase<Derived>&)
1316 -> VariableMatrix<typename Derived::Scalar>;
1318template <
typename Derived>
1319VariableMatrix(
const Eigen::DiagonalBase<Derived>&)
1320 -> VariableMatrix<typename Derived::Scalar>;
1327template <
typename Scalar, EigenMatrixLike LHS>
1328 requires std::same_as<typename std::decay_t<LHS>::Scalar, Scalar>
1329VariableMatrix<Scalar> operator*(
const LHS& lhs,
const Variable<Scalar>& rhs) {
1330 VariableMatrix<Scalar> result(detail::empty, lhs.rows(), lhs.cols());
1332 for (
int row = 0; row < result.rows(); ++row) {
1333 for (
int col = 0; col < result.cols(); ++col) {
1334 result[row, col] = lhs[row, col] * rhs;
1346template <
typename Scalar, EigenMatrixLike RHS>
1347 requires std::same_as<typename std::decay_t<RHS>::Scalar, Scalar>
1348VariableMatrix<Scalar> operator*(
const Variable<Scalar>& lhs,
const RHS& rhs) {
1349 VariableMatrix<Scalar> result(detail::empty, rhs.rows(), rhs.cols());
1351 for (
int row = 0; row < result.rows(); ++row) {
1352 for (
int col = 0; col < result.cols(); ++col) {
1353 result[row, col] = rhs[row, col] * lhs;
1366template <
typename Scalar, EigenMatrixLike LHS>
1367 requires std::same_as<typename std::decay_t<LHS>::Scalar, Scalar>
1368VariableMatrix<Scalar> operator/(
const LHS& lhs,
const Variable<Scalar>& rhs) {
1369 VariableMatrix<Scalar> result(detail::empty, lhs.rows(), lhs.cols());
1371 for (
int row = 0; row < result.rows(); ++row) {
1372 for (
int col = 0; col < result.cols(); ++col) {
1373 result[row, col] = lhs[row, col] / rhs;
1386template <
typename Scalar>
1387VariableMatrix<Scalar> cwise_reduce(
1388 const VariableMatrix<Scalar>& lhs,
const VariableMatrix<Scalar>& rhs,
1389 function_ref<Variable<Scalar>(
const Variable<Scalar>& x,
1390 const Variable<Scalar>& y)>
1392 slp_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
1394 VariableMatrix<Scalar> result{detail::empty, lhs.rows(), lhs.cols()};
1396 for (
int row = 0; row < lhs.rows(); ++row) {
1397 for (
int col = 0; col < lhs.cols(); ++col) {
1398 result[row, col] = binary_op(lhs[row, col], rhs[row, col]);
1414template <
typename Scalar>
1415VariableMatrix<Scalar> block(
1416 std::initializer_list<std::initializer_list<VariableMatrix<Scalar>>> list) {
1420 for (
const auto& row : list) {
1421 if (row.size() > 0) {
1422 rows += row.
begin()->rows();
1426 int latest_cols = 0;
1427 for (
const auto& elem : row) {
1429 slp_assert(row.begin()->rows() == elem.rows());
1431 latest_cols += elem.cols();
1439 slp_assert(cols == latest_cols);
1443 VariableMatrix<Scalar> result{detail::empty, rows, cols};
1446 for (
const auto& row : list) {
1448 for (
const auto& elem : row) {
1449 result.block(row_offset, col_offset, elem.rows(), elem.cols()) = elem;
1450 col_offset += elem.cols();
1452 if (row.size() > 0) {
1453 row_offset += row.begin()->rows();
1471template <
typename Scalar>
1472VariableMatrix<Scalar> block(
1473 const std::vector<std::vector<VariableMatrix<Scalar>>>& list) {
1477 for (
const auto& row : list) {
1478 if (row.size() > 0) {
1479 rows += row.
begin()->rows();
1483 int latest_cols = 0;
1484 for (
const auto& elem : row) {
1486 slp_assert(row.begin()->rows() == elem.rows());
1488 latest_cols += elem.cols();
1496 slp_assert(cols == latest_cols);
1500 VariableMatrix<Scalar> result{detail::empty, rows, cols};
1503 for (
const auto& row : list) {
1505 for (
const auto& elem : row) {
1506 result.block(row_offset, col_offset, elem.rows(), elem.cols()) = elem;
1507 col_offset += elem.cols();
1509 if (row.size() > 0) {
1510 row_offset += row.begin()->rows();
1523template <
typename Scalar>
1524VariableMatrix<Scalar> solve(
const VariableMatrix<Scalar>& A,
1525 const VariableMatrix<Scalar>& B) {
1527 slp_assert(A.rows() == B.rows());
1529 if (A.rows() == 1 && A.cols() == 1) {
1531 return B[0, 0] / A[0, 0];
1532 }
else if (A.rows() == 2 && A.cols() == 2) {
1538 const auto& a = A[0, 0];
1539 const auto& b = A[0, 1];
1540 const auto& c = A[1, 0];
1541 const auto& d = A[1, 1];
1543 VariableMatrix adj_A{{d, -b}, {-c, a}};
1544 auto det_A = a * d - b * c;
1545 return adj_A / det_A * B;
1546 }
else if (A.rows() == 3 && A.cols() == 3) {
1558 const auto& a = A[0, 0];
1559 const auto& b = A[0, 1];
1560 const auto& c = A[0, 2];
1561 const auto& d = A[1, 0];
1562 const auto& e = A[1, 1];
1563 const auto& f = A[1, 2];
1564 const auto& g = A[2, 0];
1565 const auto& h = A[2, 1];
1566 const auto& i = A[2, 2];
1587 auto adj_A00 = ei - fh;
1588 auto adj_A10 = fg - di;
1589 auto adj_A20 = dh - eg;
1591 VariableMatrix adj_A{{adj_A00, ch - bi, bf - ce},
1592 {adj_A10, ai - cg, cd - af},
1593 {adj_A20, bg - ah, ae - bd}};
1594 auto det_A = a * adj_A00 + b * adj_A10 + c * adj_A20;
1595 return adj_A / det_A * B;
1596 }
else if (A.rows() == 4 && A.cols() == 4) {
1606 const auto& a = A[0, 0];
1607 const auto& b = A[0, 1];
1608 const auto& c = A[0, 2];
1609 const auto& d = A[0, 3];
1610 const auto& e = A[1, 0];
1611 const auto& f = A[1, 1];
1612 const auto& g = A[1, 2];
1613 const auto& h = A[1, 3];
1614 const auto& i = A[2, 0];
1615 const auto& j = A[2, 1];
1616 const auto& k = A[2, 2];
1617 const auto& l = A[2, 3];
1618 const auto& m = A[3, 0];
1619 const auto& n = A[3, 1];
1620 const auto& o = A[3, 2];
1621 const auto& p = A[3, 3];
1623 auto afk = a * f * k;
1624 auto afl = a * f * l;
1625 auto afo = a * f * o;
1626 auto afp = a * f * p;
1627 auto agj = a * g * j;
1628 auto agl = a * g * l;
1629 auto agn = a * g * n;
1630 auto agp = a * g * p;
1631 auto ahj = a * h * j;
1632 auto ahk = a * h * k;
1633 auto ahn = a * h * n;
1634 auto aho = a * h * o;
1635 auto ajo = a * j * o;
1636 auto ajp = a * j * p;
1637 auto akn = a * k * n;
1638 auto akp = a * k * p;
1639 auto aln = a * l * n;
1640 auto alo = a * l * o;
1641 auto bek = b * e * k;
1642 auto bel = b * e * l;
1643 auto beo = b * e * o;
1644 auto bep = b * e * p;
1645 auto bgi = b * g * i;
1646 auto bgl = b * g * l;
1647 auto bgm = b * g * m;
1648 auto bgp = b * g * p;
1649 auto bhi = b * h * i;
1650 auto bhk = b * h * k;
1651 auto bhm = b * h * m;
1652 auto bho = b * h * o;
1653 auto bio = b * i * o;
1654 auto bip = b * i * p;
1655 auto bjp = b * j * p;
1656 auto bkm = b * k * m;
1657 auto bkp = b * k * p;
1658 auto blm = b * l * m;
1659 auto blo = b * l * o;
1660 auto cej = c * e * j;
1661 auto cel = c * e * l;
1662 auto cen = c * e * n;
1663 auto cep = c * e * p;
1664 auto cfi = c * f * i;
1665 auto cfl = c * f * l;
1666 auto cfm = c * f * m;
1667 auto cfp = c * f * p;
1668 auto chi = c * h * i;
1669 auto chj = c * h * j;
1670 auto chm = c * h * m;
1671 auto chn = c * h * n;
1672 auto cin = c * i * n;
1673 auto cip = c * i * p;
1674 auto cjm = c * j * m;
1675 auto cjp = c * j * p;
1676 auto clm = c * l * m;
1677 auto cln = c * l * n;
1678 auto dej = d * e * j;
1679 auto dek = d * e * k;
1680 auto den = d * e * n;
1681 auto deo = d * e * o;
1682 auto dfi = d * f * i;
1683 auto dfk = d * f * k;
1684 auto dfm = d * f * m;
1685 auto dfo = d * f * o;
1686 auto dgi = d * g * i;
1687 auto dgj = d * g * j;
1688 auto dgm = d * g * m;
1689 auto dgn = d * g * n;
1690 auto din = d * i * n;
1691 auto dio = d * i * o;
1692 auto djm = d * j * m;
1693 auto djo = d * j * o;
1694 auto dkm = d * k * m;
1695 auto dkn = d * k * n;
1696 auto ejo = e * j * o;
1697 auto ejp = e * j * p;
1698 auto ekn = e * k * n;
1699 auto ekp = e * k * p;
1700 auto eln = e * l * n;
1701 auto elo = e * l * o;
1702 auto fio = f * i * o;
1703 auto fip = f * i * p;
1704 auto fkm = f * k * m;
1705 auto fkp = f * k * p;
1706 auto flm = f * l * m;
1707 auto flo = f * l * o;
1708 auto gin = g * i * n;
1709 auto gip = g * i * p;
1710 auto gjm = g * j * m;
1711 auto gjp = g * j * p;
1712 auto glm = g * l * m;
1713 auto gln = g * l * n;
1714 auto hin = h * i * n;
1715 auto hio = h * i * o;
1716 auto hjm = h * j * m;
1717 auto hjo = h * j * o;
1718 auto hkm = h * k * m;
1719 auto hkn = h * k * n;
1721 auto adj_A00 = fkp - flo - gjp + gln + hjo - hkn;
1722 auto adj_A01 = -bkp + blo + cjp - cln - djo + dkn;
1723 auto adj_A02 = bgp - bho - cfp + chn + dfo - dgn;
1724 auto adj_A03 = -bgl + bhk + cfl - chj - dfk + dgj;
1725 auto adj_A10 = -ekp + elo + gip - glm - hio + hkm;
1726 auto adj_A11 = akp - alo - cip + clm + dio - dkm;
1727 auto adj_A12 = -agp + aho + cep - chm - deo + dgm;
1728 auto adj_A13 = agl - ahk - cel + chi + dek - dgi;
1729 auto adj_A20 = ejp - eln - fip + flm + hin - hjm;
1730 auto adj_A21 = -ajp + aln + bip - blm - din + djm;
1731 auto adj_A22 = afp - ahn - bep + bhm + den - dfm;
1732 auto adj_A23 = -afl + ahj + bel - bhi - dej + dfi;
1733 auto adj_A30 = -ejo + ekn + fio - fkm - gin + gjm;
1735 auto adj_A31 = ajo - akn - bio + bkm + cin - cjm;
1736 auto adj_A32 = -afo + agn + beo - bgm - cen + cfm;
1737 auto adj_A33 = afk - agj - bek + bgi + cej - cfi;
1739 VariableMatrix adj_A{{adj_A00, adj_A01, adj_A02, adj_A03},
1740 {adj_A10, adj_A11, adj_A12, adj_A13},
1741 {adj_A20, adj_A21, adj_A22, adj_A23},
1742 {adj_A30, adj_A31, adj_A32, adj_A33}};
1743 auto det_A = a * adj_A00 + b * adj_A10 + c * adj_A20 + d * adj_A30;
1744 return adj_A / det_A * B;
1746 return VariableMatrix<Scalar>{
1747 A.to_eigen().householderQr().solve(B.to_eigen())};
1764template <
typename Scalar>
1765VariableMatrix<Scalar> gradient_tree(
const ExpressionGraph<Scalar>& top_list,
1766 const VariableMatrix<Scalar>& wrt) {
1767 slp_assert(wrt.cols() == 1);
1772 if (top_list.empty()) {
1773 return VariableMatrix<Scalar>{detail::empty, wrt.rows(), 1};
1777 top_list[0]->adj_expr = constant_ptr(Scalar(1));
1783 for (
auto& node : top_list) {
1786 if (!node->is_leaf && node->adj_expr !=
nullptr) {
1787 node->accumulate_adjoints_expr();
1792 VariableMatrix<Scalar> grad{detail::empty, wrt.rows(), 1};
1793 for (
int row = 0; row < grad.rows(); ++row) {
1794 grad[row] = Variable{std::move(wrt[row].expr->adj_expr)};
1800 for (
auto& node : top_list) {
1801 node->adj_expr =
nullptr;
1809extern template class EXPORT_TEMPLATE_DECLARE(SLEIPNIR_DLLEXPORT)
1810VariableMatrix<double>;
1812extern template SLEIPNIR_DLLEXPORT VariableMatrix<double> solve(
1813 const VariableMatrix<double>& A,
const VariableMatrix<double>& B);
Definition intrusive_shared_ptr.hpp:27
Definition sleipnir_base.hpp:9
Represents a sequence of elements in an iterable object.
Definition slice.hpp:25
Definition variable_block.hpp:27
Definition variable_matrix.hpp:38
const_reverse_iterator crbegin() const
Definition variable_matrix.hpp:1230
VariableMatrix(std::initializer_list< std::initializer_list< Variable< Scalar > > > list)
Definition variable_matrix.hpp:78
const_reverse_iterator crend() const
Definition variable_matrix.hpp:1237
Scalar_ Scalar
Scalar type alias.
Definition variable_matrix.hpp:41
iterator end()
Definition variable_matrix.hpp:1181
const Variable< Scalar > & operator[](int row, int col) const
Definition variable_matrix.hpp:322
VariableMatrix(Variable< Scalar > &&variable)
Definition variable_matrix.hpp:199
const VariableBlock< const VariableMatrix > block(int row_offset, int col_offset, int block_rows, int block_cols) const
Definition variable_matrix.hpp:369
size_t size() const
Definition variable_matrix.hpp:1244
static VariableMatrix< Scalar > zero(int rows, int cols)
Definition variable_matrix.hpp:1267
VariableBlock< VariableMatrix > block(int row_offset, int col_offset, int block_rows, int block_cols)
Definition variable_matrix.hpp:353
VariableMatrix(const std::vector< std::vector< Scalar > > &list)
Definition variable_matrix.hpp:105
VariableMatrix & operator=(ScalarLike auto value)
Definition variable_matrix.hpp:283
Eigen::MatrixX< Scalar > value()
Definition variable_matrix.hpp:939
VariableMatrix & operator-=(const MatrixLike auto &rhs)
Definition variable_matrix.hpp:847
Variable< Scalar > & operator[](int index)
Definition variable_matrix.hpp:332
VariableMatrix & operator=(const Eigen::MatrixBase< Derived > &values)
Definition variable_matrix.hpp:265
friend VariableMatrix< Scalar > operator-(const LHS &lhs, const RHS &rhs)
Definition variable_matrix.hpp:789
VariableMatrix & operator-=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:863
VariableMatrix & operator*=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:629
Scalar value(int index)
Definition variable_matrix.hpp:934
VariableMatrix(const VariableBlock< VariableMatrix > &values)
Definition variable_matrix.hpp:207
VariableMatrix(int rows, int cols)
Definition variable_matrix.hpp:56
const_iterator cbegin() const
Definition variable_matrix.hpp:1196
const_iterator begin() const
Definition variable_matrix.hpp:1186
const_iterator cend() const
Definition variable_matrix.hpp:1201
const VariableBlock< const VariableMatrix > operator[](Slice row_slice, Slice col_slice) const
Definition variable_matrix.hpp:397
friend VariableMatrix< Scalar > operator/(const LHS &lhs, const Variable< Scalar > &rhs)
Definition variable_matrix.hpp:664
VariableMatrix(int rows)
Definition variable_matrix.hpp:50
VariableMatrix(std::span< const Variable< Scalar > > values, int rows, int cols)
Definition variable_matrix.hpp:249
VariableBlock< VariableMatrix > col(int col)
Definition variable_matrix.hpp:487
static VariableMatrix< Scalar > identity(int rows)
Definition variable_matrix.hpp:1250
VariableMatrix(const Eigen::MatrixBase< Derived > &values)
Definition variable_matrix.hpp:156
VariableMatrix< Scalar > exp() const
Definition variable_matrix.hpp:987
const VariableBlock< const VariableMatrix > operator[](Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length) const
Definition variable_matrix.hpp:433
const VariableBlock< const VariableMatrix > col(int col) const
Definition variable_matrix.hpp:496
VariableMatrix & operator+=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:771
VariableBlock< VariableMatrix > segment(int offset, int length)
Definition variable_matrix.hpp:445
Scalar value(int row, int col)
Definition variable_matrix.hpp:928
const VariableBlock< const VariableMatrix > row(int row) const
Definition variable_matrix.hpp:478
VariableMatrix()=default
Constructs an empty VariableMatrix.
Eigen::MatrixX< Variable< Scalar > > to_eigen() const
Definition variable_matrix.hpp:954
VariableMatrix & operator+=(const MatrixLike auto &rhs)
Definition variable_matrix.hpp:755
VariableMatrix(std::span< const Variable< Scalar > > values)
Definition variable_matrix.hpp:234
friend VariableMatrix< Scalar > operator-(const SleipnirMatrixLike< Scalar > auto &lhs)
Definition variable_matrix.hpp:878
static VariableMatrix< Scalar > constant(int rows, int cols, Scalar constant)
Definition variable_matrix.hpp:1298
VariableMatrix< Scalar > T() const
Definition variable_matrix.hpp:901
VariableMatrix< Scalar > cwise_transform(function_ref< Variable< Scalar >(const Variable< Scalar > &x)> unary_op) const
Definition variable_matrix.hpp:970
friend VariableMatrix< Scalar > operator*(const LHS &lhs, const RHS &rhs)
Definition variable_matrix.hpp:506
const_reverse_iterator rbegin() const
Definition variable_matrix.hpp:1216
VariableMatrix(const Variable< Scalar > &variable)
Definition variable_matrix.hpp:191
reverse_iterator rend()
Definition variable_matrix.hpp:1211
VariableMatrix(const VariableBlock< const VariableMatrix > &values)
Definition variable_matrix.hpp:221
int rows() const
Definition variable_matrix.hpp:916
static VariableMatrix< Scalar > one(int rows, int cols)
Definition variable_matrix.hpp:1282
VariableMatrix(const Eigen::DiagonalBase< Derived > &values)
Definition variable_matrix.hpp:172
VariableBlock< VariableMatrix > operator[](Slice row_slice, Slice col_slice)
Definition variable_matrix.hpp:385
const_reverse_iterator rend() const
Definition variable_matrix.hpp:1223
VariableMatrix & operator*=(const MatrixLike auto &rhs)
Definition variable_matrix.hpp:608
VariableMatrix(detail::empty_t, int rows, int cols)
Definition variable_matrix.hpp:67
const_iterator end() const
Definition variable_matrix.hpp:1191
void set_value(const Eigen::MatrixBase< Derived > &values)
Definition variable_matrix.hpp:296
Variable< Scalar > & operator[](int row, int col)
Definition variable_matrix.hpp:311
iterator begin()
Definition variable_matrix.hpp:1176
const VariableBlock< const VariableMatrix > segment(int offset, int length) const
Definition variable_matrix.hpp:457
reverse_iterator rbegin()
Definition variable_matrix.hpp:1206
VariableBlock< VariableMatrix > row(int row)
Definition variable_matrix.hpp:469
friend VariableMatrix< Scalar > operator+(const LHS &lhs, const RHS &rhs)
Definition variable_matrix.hpp:697
VariableMatrix(const std::vector< std::vector< Variable< Scalar > > > &list)
Definition variable_matrix.hpp:131
VariableBlock< VariableMatrix > operator[](Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length)
Definition variable_matrix.hpp:415
VariableMatrix & operator/=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:681
const Variable< Scalar > & operator[](int index) const
Definition variable_matrix.hpp:341
int cols() const
Definition variable_matrix.hpp:921
Definition variable.hpp:63
Definition function_ref.hpp:13
Definition concepts.hpp:18
Definition concepts.hpp:24
Definition concepts.hpp:33
Definition concepts.hpp:38
Type tag used to designate an uninitialized VariableMatrix.
Definition empty.hpp:8