9#include <initializer_list>
18#include <gch/small_vector.hpp>
20#include "sleipnir/autodiff/expression_graph.hpp"
21#include "sleipnir/autodiff/sleipnir_base.hpp"
22#include "sleipnir/autodiff/slice.hpp"
23#include "sleipnir/autodiff/variable.hpp"
24#include "sleipnir/autodiff/variable_block.hpp"
25#include "sleipnir/util/assert.hpp"
26#include "sleipnir/util/concepts.hpp"
27#include "sleipnir/util/empty.hpp"
28#include "sleipnir/util/function_ref.hpp"
29#include "sleipnir/util/symbol_exports.hpp"
36template <
typename Scalar_>
57 for (
int index = 0; index <
rows *
cols; ++index) {
58 m_storage.emplace_back();
69 for (
int index = 0; index <
rows *
cols; ++index) {
70 m_storage.emplace_back(
nullptr);
82 if (list.size() > 0) {
83 m_cols = list.begin()->size();
88 const auto&
row : list) {
89 slp_assert(
static_cast<int>(
row.size()) == m_cols);
93 for (
const auto&
row : list) {
94 std::ranges::copy(
row, std::back_inserter(m_storage));
106 m_rows = list.size();
108 if (list.size() > 0) {
109 m_cols = list.begin()->size();
114 const auto&
row : list) {
115 slp_assert(
static_cast<int>(
row.size()) == m_cols);
119 for (
const auto&
row : list) {
120 std::ranges::copy(
row, std::back_inserter(m_storage));
132 m_rows = list.size();
134 if (list.size() > 0) {
135 m_cols = list.begin()->size();
140 const auto&
row : list) {
141 slp_assert(
static_cast<int>(
row.size()) == m_cols);
145 for (
const auto&
row : list) {
146 std::ranges::copy(
row, std::back_inserter(m_storage));
153 template <
typename Derived>
169 template <
typename Derived>
178 m_storage.emplace_back(
values.diagonal()[
row]);
180 m_storage.emplace_back(
Scalar(0));
199 m_storage.emplace_back(std::move(
variable));
263 template <
typename Derived>
283 slp_assert(
rows() == 1 &&
cols() == 1);
285 (*this)[0, 0] =
value;
293 template <
typename Derived>
294 requires std::same_as<typename Derived::Scalar, Scalar>
332 slp_assert(index >= 0 && index <
rows() *
cols());
333 return m_storage[index];
341 slp_assert(index >= 0 && index <
rows() *
cols());
342 return m_storage[index];
445 slp_assert(
cols() == 1);
458 slp_assert(
cols() == 1);
504 template <EigenMatrixLike LHS, SleipnirMatrixLike<Scalar> RHS>
506 slp_assert(
lhs.cols() ==
rhs.rows());
510 for (
int i = 0;
i <
lhs.rows(); ++
i) {
511 for (
int j = 0;
j <
rhs.cols(); ++
j) {
513 for (
int k = 0;
k <
lhs.cols(); ++
k) {
527 template <SleipnirMatrixLike<Scalar> LHS, EigenMatrixLike RHS>
529 slp_assert(
lhs.cols() ==
rhs.rows());
533 for (
int i = 0;
i <
lhs.rows(); ++
i) {
534 for (
int j = 0;
j <
rhs.cols(); ++
j) {
536 for (
int k = 0;
k <
lhs.cols(); ++
k) {
550 template <SleipnirMatrixLike<Scalar> LHS, SleipnirMatrixLike<Scalar> RHS>
552 slp_assert(
lhs.cols() ==
rhs.rows());
556 for (
int i = 0;
i <
lhs.rows(); ++
i) {
557 for (
int j = 0;
j <
rhs.cols(); ++
j) {
559 for (
int k = 0;
k <
lhs.cols(); ++
k) {
573 template <EigenMatrixLike LHS>
591 template <SleipnirMatrixLike<Scalar> LHS, ScalarLike RHS>
608 template <EigenMatrixLike RHS>
626 template <ScalarLike LHS, SleipnirMatrixLike<Scalar> RHS>
646 for (
int i = 0;
i <
rows(); ++
i) {
648 for (
int j = 0;
j <
rhs.cols(); ++
j) {
650 for (
int k = 0;
k <
cols(); ++
k) {
679 template <EigenMatrixLike LHS>
698 template <SleipnirMatrixLike<Scalar> LHS, ScalarLike RHS>
717 template <SleipnirMatrixLike<Scalar> LHS>
750 template <EigenMatrixLike LHS, SleipnirMatrixLike<Scalar> RHS>
752 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
770 template <SleipnirMatrixLike<Scalar> LHS, EigenMatrixLike RHS>
772 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
790 template <SleipnirMatrixLike<Scalar> LHS, SleipnirMatrixLike<Scalar> RHS>
792 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
826 slp_assert(
rows() == 1 &&
cols() == 1);
842 template <EigenMatrixLike LHS, SleipnirMatrixLike<Scalar> RHS>
844 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
862 template <SleipnirMatrixLike<Scalar> LHS, EigenMatrixLike RHS>
864 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
882 template <SleipnirMatrixLike<Scalar> LHS, SleipnirMatrixLike<Scalar> RHS>
884 slp_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
918 slp_assert(
rows() == 1 &&
cols() == 1);
948 slp_assert(
rows() == 1 &&
cols() == 1);
949 return (*
this)[0, 0];
970 int rows()
const {
return m_rows; }
975 int cols()
const {
return m_cols; }
993 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
value() {
994 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
result{
rows(),
1009 Eigen::Matrix<Variable<Scalar>, Eigen::Dynamic, Eigen::Dynamic>
to_eigen()
1011 Eigen::Matrix<Variable<Scalar>, Eigen::Dynamic, Eigen::Dynamic>
result{
1068 constexpr std::array
p{
Scalar(1.0L),
1069 Scalar(0.499999999999999999999987615564159L),
1070 Scalar(0.119999999999999999999993719796468L),
1071 Scalar(0.0183333333333333333333318078905823L),
1072 Scalar(0.00199275362318840579710121408775205L),
1073 Scalar(0.00016304347826086956521736560868541L),
1074 Scalar(1.03519668737060041407846479512981e-05L),
1075 Scalar(5.17598343685300207039205144279119e-07L),
1076 Scalar(2.04315135665250081725989398668247e-08L),
1077 Scalar(6.30602270571759511499920806570486e-10L),
1078 Scalar(1.48377004840414002705850442238441e-11L),
1079 Scalar(2.52915349159796595521307855480881e-13L),
1080 Scalar(2.81017054621996217245857568431558e-15L),
1081 Scalar(1.54404975067030888596595580141692e-17L)};
1082 constexpr std::array
q{
Scalar(1.0L),
1083 Scalar(-0.500000000000000000000012384435841L),
1084 Scalar(0.120000000000000000000006104232309L),
1085 Scalar(-0.0183333333333333333333347707904729L),
1086 Scalar(0.00199275362318840579710166350137732L),
1087 Scalar(-0.000163043478260869565217413851346892L),
1088 Scalar(1.03519668737060041407885187519331e-05L),
1089 Scalar(-5.17598343685300207039443859549262e-07L),
1090 Scalar(2.04315135665250081726103781506842e-08L),
1091 Scalar(-6.30602270571759511500345035969254e-10L),
1092 Scalar(1.48377004840414002705969744674248e-11L),
1093 Scalar(-2.52915349159796595521550648156349e-13L),
1094 Scalar(2.81017054621996217246180850207342e-15L),
1095 Scalar(-1.54404975067030888596810607146175e-17L)};
1107 Eigen::Vector<Scalar, Eigen::Dynamic>::Constant(
rows(),
p[0])
1110 Eigen::Vector<Scalar, Eigen::Dynamic>::Constant(
rows(),
q[0])
1125 Q.T().to_eigen().lu().solve(
P.T().to_eigen()).transpose()};
1128#ifndef DOXYGEN_SHOULD_SKIP_THIS
1144 constexpr iterator& operator++() noexcept {
1149 constexpr iterator operator++(
int)
noexcept {
1150 iterator retval = *
this;
1155 constexpr iterator& operator--() noexcept {
1160 constexpr iterator operator--(
int)
noexcept {
1161 iterator retval = *
this;
1166 constexpr bool operator==(
const iterator&)
const noexcept =
default;
1168 constexpr reference operator*() const noexcept {
return *m_it; }
1171 gch::small_vector<Variable<Scalar>>::iterator m_it;
1174 class const_iterator {
1176 using iterator_category = std::bidirectional_iterator_tag;
1177 using value_type = Variable<Scalar>;
1178 using difference_type = std::ptrdiff_t;
1179 using pointer = Variable<Scalar>*;
1180 using const_reference =
const Variable<Scalar>&;
1182 constexpr const_iterator() noexcept = default;
1184 explicit constexpr const_iterator(
1185 gch::small_vector<Variable<Scalar>>::const_iterator it) noexcept
1188 constexpr const_iterator& operator++() noexcept {
1193 constexpr const_iterator operator++(
int)
noexcept {
1194 const_iterator retval = *
this;
1199 constexpr const_iterator& operator--() noexcept {
1204 constexpr const_iterator operator--(
int)
noexcept {
1205 const_iterator retval = *
this;
1210 constexpr bool operator==(
const const_iterator&)
const noexcept =
default;
1212 constexpr const_reference operator*() const noexcept {
return *m_it; }
1215 gch::small_vector<Variable<Scalar>>::const_iterator m_it;
1218 using reverse_iterator = std::reverse_iterator<iterator>;
1219 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1226 iterator
begin() {
return iterator{m_storage.begin()}; }
1231 iterator
end() {
return iterator{m_storage.end()}; }
1236 const_iterator
begin()
const {
return const_iterator{m_storage.begin()}; }
1241 const_iterator
end()
const {
return const_iterator{m_storage.end()}; }
1246 const_iterator
cbegin()
const {
return const_iterator{m_storage.cbegin()}; }
1251 const_iterator
cend()
const {
return const_iterator{m_storage.cend()}; }
1256 reverse_iterator
rbegin() {
return reverse_iterator{
end()}; }
1261 reverse_iterator
rend() {
return reverse_iterator{
begin()}; }
1267 return const_reverse_iterator{
end()};
1273 const_reverse_iterator
rend()
const {
1274 return const_reverse_iterator{
begin()};
1281 return const_reverse_iterator{
cend()};
1288 return const_reverse_iterator{
cbegin()};
1294 size_t size()
const {
return m_storage.size(); }
1359 gch::small_vector<Variable<Scalar>> m_storage;
1364template <
typename Derived>
1365VariableMatrix(
const Eigen::MatrixBase<Derived>&)
1366 -> VariableMatrix<typename Derived::Scalar>;
1368template <
typename Derived>
1369VariableMatrix(
const Eigen::DiagonalBase<Derived>&)
1370 -> VariableMatrix<typename Derived::Scalar>;
1378template <
typename Scalar>
1379VariableMatrix<Scalar> cwise_reduce(
1380 const VariableMatrix<Scalar>& lhs,
const VariableMatrix<Scalar>& rhs,
1381 function_ref<Variable<Scalar>(
const Variable<Scalar>& x,
1382 const Variable<Scalar>& y)>
1384 slp_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
1386 VariableMatrix<Scalar> result{detail::empty, lhs.rows(), lhs.cols()};
1388 for (
int row = 0; row < lhs.rows(); ++row) {
1389 for (
int col = 0; col < lhs.cols(); ++col) {
1390 result[row, col] = binary_op(lhs[row, col], rhs[row, col]);
1406template <
typename Scalar>
1407VariableMatrix<Scalar> block(
1408 std::initializer_list<std::initializer_list<VariableMatrix<Scalar>>> list) {
1412 for (
const auto& row : list) {
1413 if (row.size() > 0) {
1414 rows += row.
begin()->rows();
1418 int latest_cols = 0;
1419 for (
const auto& elem : row) {
1421 slp_assert(row.begin()->rows() == elem.rows());
1423 latest_cols += elem.cols();
1431 slp_assert(cols == latest_cols);
1435 VariableMatrix<Scalar> result{detail::empty, rows, cols};
1438 for (
const auto& row : list) {
1440 for (
const auto& elem : row) {
1441 result.block(row_offset, col_offset, elem.rows(), elem.cols()) = elem;
1442 col_offset += elem.cols();
1444 if (row.size() > 0) {
1445 row_offset += row.begin()->rows();
1463template <
typename Scalar>
1464VariableMatrix<Scalar> block(
1465 const std::vector<std::vector<VariableMatrix<Scalar>>>& list) {
1469 for (
const auto& row : list) {
1470 if (row.size() > 0) {
1471 rows += row.
begin()->rows();
1475 int latest_cols = 0;
1476 for (
const auto& elem : row) {
1478 slp_assert(row.begin()->rows() == elem.rows());
1480 latest_cols += elem.cols();
1488 slp_assert(cols == latest_cols);
1492 VariableMatrix<Scalar> result{detail::empty, rows, cols};
1495 for (
const auto& row : list) {
1497 for (
const auto& elem : row) {
1498 result.block(row_offset, col_offset, elem.rows(), elem.cols()) = elem;
1499 col_offset += elem.cols();
1501 if (row.size() > 0) {
1502 row_offset += row.begin()->rows();
1515template <
typename Scalar>
1516VariableMatrix<Scalar> solve(
const VariableMatrix<Scalar>& A,
1517 const VariableMatrix<Scalar>& B) {
1519 slp_assert(A.rows() == B.rows());
1521 if (A.rows() == 1 && A.cols() == 1) {
1523 return B[0, 0] / A[0, 0];
1524 }
else if (A.rows() == 2 && A.cols() == 2) {
1530 const auto& a = A[0, 0];
1531 const auto& b = A[0, 1];
1532 const auto& c = A[1, 0];
1533 const auto& d = A[1, 1];
1535 VariableMatrix adj_A{{d, -b}, {-c, a}};
1536 auto det_A = a * d - b * c;
1537 return adj_A / det_A * B;
1538 }
else if (A.rows() == 3 && A.cols() == 3) {
1550 const auto& a = A[0, 0];
1551 const auto& b = A[0, 1];
1552 const auto& c = A[0, 2];
1553 const auto& d = A[1, 0];
1554 const auto& e = A[1, 1];
1555 const auto& f = A[1, 2];
1556 const auto& g = A[2, 0];
1557 const auto& h = A[2, 1];
1558 const auto& i = A[2, 2];
1579 auto adj_A00 = ei - fh;
1580 auto adj_A10 = fg - di;
1581 auto adj_A20 = dh - eg;
1583 VariableMatrix adj_A{{adj_A00, ch - bi, bf - ce},
1584 {adj_A10, ai - cg, cd - af},
1585 {adj_A20, bg - ah, ae - bd}};
1586 auto det_A = a * adj_A00 + b * adj_A10 + c * adj_A20;
1587 return adj_A / det_A * B;
1588 }
else if (A.rows() == 4 && A.cols() == 4) {
1598 const auto& a = A[0, 0];
1599 const auto& b = A[0, 1];
1600 const auto& c = A[0, 2];
1601 const auto& d = A[0, 3];
1602 const auto& e = A[1, 0];
1603 const auto& f = A[1, 1];
1604 const auto& g = A[1, 2];
1605 const auto& h = A[1, 3];
1606 const auto& i = A[2, 0];
1607 const auto& j = A[2, 1];
1608 const auto& k = A[2, 2];
1609 const auto& l = A[2, 3];
1610 const auto& m = A[3, 0];
1611 const auto& n = A[3, 1];
1612 const auto& o = A[3, 2];
1613 const auto& p = A[3, 3];
1615 auto afk = a * f * k;
1616 auto afl = a * f * l;
1617 auto afo = a * f * o;
1618 auto afp = a * f * p;
1619 auto agj = a * g * j;
1620 auto agl = a * g * l;
1621 auto agn = a * g * n;
1622 auto agp = a * g * p;
1623 auto ahj = a * h * j;
1624 auto ahk = a * h * k;
1625 auto ahn = a * h * n;
1626 auto aho = a * h * o;
1627 auto ajo = a * j * o;
1628 auto ajp = a * j * p;
1629 auto akn = a * k * n;
1630 auto akp = a * k * p;
1631 auto aln = a * l * n;
1632 auto alo = a * l * o;
1633 auto bek = b * e * k;
1634 auto bel = b * e * l;
1635 auto beo = b * e * o;
1636 auto bep = b * e * p;
1637 auto bgi = b * g * i;
1638 auto bgl = b * g * l;
1639 auto bgm = b * g * m;
1640 auto bgp = b * g * p;
1641 auto bhi = b * h * i;
1642 auto bhk = b * h * k;
1643 auto bhm = b * h * m;
1644 auto bho = b * h * o;
1645 auto bio = b * i * o;
1646 auto bip = b * i * p;
1647 auto bjp = b * j * p;
1648 auto bkm = b * k * m;
1649 auto bkp = b * k * p;
1650 auto blm = b * l * m;
1651 auto blo = b * l * o;
1652 auto cej = c * e * j;
1653 auto cel = c * e * l;
1654 auto cen = c * e * n;
1655 auto cep = c * e * p;
1656 auto cfi = c * f * i;
1657 auto cfl = c * f * l;
1658 auto cfm = c * f * m;
1659 auto cfp = c * f * p;
1660 auto chi = c * h * i;
1661 auto chj = c * h * j;
1662 auto chm = c * h * m;
1663 auto chn = c * h * n;
1664 auto cin = c * i * n;
1665 auto cip = c * i * p;
1666 auto cjm = c * j * m;
1667 auto cjp = c * j * p;
1668 auto clm = c * l * m;
1669 auto cln = c * l * n;
1670 auto dej = d * e * j;
1671 auto dek = d * e * k;
1672 auto den = d * e * n;
1673 auto deo = d * e * o;
1674 auto dfi = d * f * i;
1675 auto dfk = d * f * k;
1676 auto dfm = d * f * m;
1677 auto dfo = d * f * o;
1678 auto dgi = d * g * i;
1679 auto dgj = d * g * j;
1680 auto dgm = d * g * m;
1681 auto dgn = d * g * n;
1682 auto din = d * i * n;
1683 auto dio = d * i * o;
1684 auto djm = d * j * m;
1685 auto djo = d * j * o;
1686 auto dkm = d * k * m;
1687 auto dkn = d * k * n;
1688 auto ejo = e * j * o;
1689 auto ejp = e * j * p;
1690 auto ekn = e * k * n;
1691 auto ekp = e * k * p;
1692 auto eln = e * l * n;
1693 auto elo = e * l * o;
1694 auto fio = f * i * o;
1695 auto fip = f * i * p;
1696 auto fkm = f * k * m;
1697 auto fkp = f * k * p;
1698 auto flm = f * l * m;
1699 auto flo = f * l * o;
1700 auto gin = g * i * n;
1701 auto gip = g * i * p;
1702 auto gjm = g * j * m;
1703 auto gjp = g * j * p;
1704 auto glm = g * l * m;
1705 auto gln = g * l * n;
1706 auto hin = h * i * n;
1707 auto hio = h * i * o;
1708 auto hjm = h * j * m;
1709 auto hjo = h * j * o;
1710 auto hkm = h * k * m;
1711 auto hkn = h * k * n;
1713 auto adj_A00 = fkp - flo - gjp + gln + hjo - hkn;
1714 auto adj_A01 = -bkp + blo + cjp - cln - djo + dkn;
1715 auto adj_A02 = bgp - bho - cfp + chn + dfo - dgn;
1716 auto adj_A03 = -bgl + bhk + cfl - chj - dfk + dgj;
1717 auto adj_A10 = -ekp + elo + gip - glm - hio + hkm;
1718 auto adj_A11 = akp - alo - cip + clm + dio - dkm;
1719 auto adj_A12 = -agp + aho + cep - chm - deo + dgm;
1720 auto adj_A13 = agl - ahk - cel + chi + dek - dgi;
1721 auto adj_A20 = ejp - eln - fip + flm + hin - hjm;
1722 auto adj_A21 = -ajp + aln + bip - blm - din + djm;
1723 auto adj_A22 = afp - ahn - bep + bhm + den - dfm;
1724 auto adj_A23 = -afl + ahj + bel - bhi - dej + dfi;
1725 auto adj_A30 = -ejo + ekn + fio - fkm - gin + gjm;
1727 auto adj_A31 = ajo - akn - bio + bkm + cin - cjm;
1728 auto adj_A32 = -afo + agn + beo - bgm - cen + cfm;
1729 auto adj_A33 = afk - agj - bek + bgi + cej - cfi;
1731 VariableMatrix adj_A{{adj_A00, adj_A01, adj_A02, adj_A03},
1732 {adj_A10, adj_A11, adj_A12, adj_A13},
1733 {adj_A20, adj_A21, adj_A22, adj_A23},
1734 {adj_A30, adj_A31, adj_A32, adj_A33}};
1735 auto det_A = a * adj_A00 + b * adj_A10 + c * adj_A20 + d * adj_A30;
1736 return adj_A / det_A * B;
1738 return VariableMatrix<Scalar>{
1739 A.to_eigen().householderQr().solve(B.to_eigen())};
1756template <
typename Scalar>
1757VariableMatrix<Scalar> gradient_tree(
const ExpressionGraph<Scalar>& top_list,
1758 const VariableMatrix<Scalar>& wrt) {
1759 slp_assert(wrt.cols() == 1);
1764 if (top_list.empty()) {
1765 return VariableMatrix<Scalar>{detail::empty, wrt.rows(), 1};
1769 top_list[0]->adjoint_expr = constant_ptr(Scalar(1));
1775 for (
auto& node : top_list) {
1776 auto& lhs = node->args[0];
1777 auto& rhs = node->args[1];
1779 if (lhs !=
nullptr) {
1780 if (rhs !=
nullptr) {
1782 lhs->adjoint_expr += node->grad_expr_l(lhs, rhs);
1783 rhs->adjoint_expr += node->grad_expr_r(lhs, rhs);
1786 lhs->adjoint_expr += node->grad_expr_l(lhs, rhs);
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->adjoint_expr)};
1800 for (
auto& node : top_list) {
1801 node->adjoint_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:37
const_reverse_iterator crbegin() const
Definition variable_matrix.hpp:1280
VariableMatrix(std::initializer_list< std::initializer_list< Variable< Scalar > > > list)
Definition variable_matrix.hpp:77
const_reverse_iterator crend() const
Definition variable_matrix.hpp:1287
Scalar_ Scalar
Scalar type alias.
Definition variable_matrix.hpp:40
iterator end()
Definition variable_matrix.hpp:1231
const Variable< Scalar > & operator[](int row, int col) const
Definition variable_matrix.hpp:321
VariableMatrix(Variable< Scalar > &&variable)
Definition variable_matrix.hpp:198
const VariableBlock< const VariableMatrix > block(int row_offset, int col_offset, int block_rows, int block_cols) const
Definition variable_matrix.hpp:368
size_t size() const
Definition variable_matrix.hpp:1294
static VariableMatrix< Scalar > zero(int rows, int cols)
Definition variable_matrix.hpp:1317
VariableBlock< VariableMatrix > block(int row_offset, int col_offset, int block_rows, int block_cols)
Definition variable_matrix.hpp:352
VariableMatrix(const std::vector< std::vector< Scalar > > &list)
Definition variable_matrix.hpp:104
VariableMatrix & operator=(ScalarLike auto value)
Definition variable_matrix.hpp:282
VariableMatrix & operator-=(const MatrixLike auto &rhs)
Definition variable_matrix.hpp:901
Variable< Scalar > & operator[](int index)
Definition variable_matrix.hpp:331
VariableMatrix & operator=(const Eigen::MatrixBase< Derived > &values)
Definition variable_matrix.hpp:264
friend VariableMatrix< Scalar > operator-(const LHS &lhs, const RHS &rhs)
Definition variable_matrix.hpp:843
VariableMatrix & operator-=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:917
friend VariableMatrix< Scalar > operator*(const Variable< Scalar > &lhs, const RHS &rhs)
Definition variable_matrix.hpp:609
Eigen::Matrix< Variable< Scalar >, Eigen::Dynamic, Eigen::Dynamic > to_eigen() const
Definition variable_matrix.hpp:1009
VariableMatrix & operator*=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:664
Scalar value(int index)
Definition variable_matrix.hpp:988
VariableMatrix(const VariableBlock< VariableMatrix > &values)
Definition variable_matrix.hpp:206
VariableMatrix(int rows, int cols)
Definition variable_matrix.hpp:55
const_iterator cbegin() const
Definition variable_matrix.hpp:1246
const_iterator begin() const
Definition variable_matrix.hpp:1236
const_iterator cend() const
Definition variable_matrix.hpp:1251
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > value()
Definition variable_matrix.hpp:993
const VariableBlock< const VariableMatrix > operator[](Slice row_slice, Slice col_slice) const
Definition variable_matrix.hpp:396
friend VariableMatrix< Scalar > operator/(const LHS &lhs, const Variable< Scalar > &rhs)
Definition variable_matrix.hpp:680
VariableMatrix(int rows)
Definition variable_matrix.hpp:49
VariableMatrix(std::span< const Variable< Scalar > > values, int rows, int cols)
Definition variable_matrix.hpp:248
VariableBlock< VariableMatrix > col(int col)
Definition variable_matrix.hpp:486
static VariableMatrix< Scalar > identity(int rows)
Definition variable_matrix.hpp:1300
VariableMatrix(const Eigen::MatrixBase< Derived > &values)
Definition variable_matrix.hpp:155
VariableMatrix< Scalar > exp() const
Definition variable_matrix.hpp:1044
const VariableBlock< const VariableMatrix > operator[](Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length) const
Definition variable_matrix.hpp:432
const VariableBlock< const VariableMatrix > col(int col) const
Definition variable_matrix.hpp:495
VariableMatrix & operator+=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:825
friend VariableMatrix< Scalar > operator*(const LHS &lhs, const Variable< Scalar > &rhs)
Definition variable_matrix.hpp:574
VariableBlock< VariableMatrix > segment(int offset, int length)
Definition variable_matrix.hpp:444
Scalar value(int row, int col)
Definition variable_matrix.hpp:982
const VariableBlock< const VariableMatrix > row(int row) const
Definition variable_matrix.hpp:477
VariableMatrix()=default
Constructs an empty VariableMatrix.
VariableMatrix & operator+=(const MatrixLike auto &rhs)
Definition variable_matrix.hpp:809
VariableMatrix(std::span< const Variable< Scalar > > values)
Definition variable_matrix.hpp:233
friend VariableMatrix< Scalar > operator-(const SleipnirMatrixLike< Scalar > auto &lhs)
Definition variable_matrix.hpp:932
static VariableMatrix< Scalar > constant(int rows, int cols, Scalar constant)
Definition variable_matrix.hpp:1348
VariableMatrix< Scalar > T() const
Definition variable_matrix.hpp:955
VariableMatrix< Scalar > cwise_transform(function_ref< Variable< Scalar >(const Variable< Scalar > &x)> unary_op) const
Definition variable_matrix.hpp:1027
friend VariableMatrix< Scalar > operator*(const LHS &lhs, const RHS &rhs)
Definition variable_matrix.hpp:505
const_reverse_iterator rbegin() const
Definition variable_matrix.hpp:1266
VariableMatrix(const Variable< Scalar > &variable)
Definition variable_matrix.hpp:190
reverse_iterator rend()
Definition variable_matrix.hpp:1261
VariableMatrix(const VariableBlock< const VariableMatrix > &values)
Definition variable_matrix.hpp:220
int rows() const
Definition variable_matrix.hpp:970
static VariableMatrix< Scalar > one(int rows, int cols)
Definition variable_matrix.hpp:1332
VariableMatrix(const Eigen::DiagonalBase< Derived > &values)
Definition variable_matrix.hpp:171
VariableBlock< VariableMatrix > operator[](Slice row_slice, Slice col_slice)
Definition variable_matrix.hpp:384
const_reverse_iterator rend() const
Definition variable_matrix.hpp:1273
VariableMatrix & operator*=(const MatrixLike auto &rhs)
Definition variable_matrix.hpp:643
VariableMatrix(detail::empty_t, int rows, int cols)
Definition variable_matrix.hpp:66
const_iterator end() const
Definition variable_matrix.hpp:1241
void set_value(const Eigen::MatrixBase< Derived > &values)
Definition variable_matrix.hpp:295
Variable< Scalar > & operator[](int row, int col)
Definition variable_matrix.hpp:310
iterator begin()
Definition variable_matrix.hpp:1226
const VariableBlock< const VariableMatrix > segment(int offset, int length) const
Definition variable_matrix.hpp:456
reverse_iterator rbegin()
Definition variable_matrix.hpp:1256
VariableBlock< VariableMatrix > row(int row)
Definition variable_matrix.hpp:468
friend VariableMatrix< Scalar > operator+(const LHS &lhs, const RHS &rhs)
Definition variable_matrix.hpp:751
VariableMatrix(const std::vector< std::vector< Variable< Scalar > > > &list)
Definition variable_matrix.hpp:130
VariableBlock< VariableMatrix > operator[](Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length)
Definition variable_matrix.hpp:414
VariableMatrix & operator/=(const ScalarLike auto &rhs)
Definition variable_matrix.hpp:735
const Variable< Scalar > & operator[](int index) const
Definition variable_matrix.hpp:340
int cols() const
Definition variable_matrix.hpp:975
Definition variable.hpp:55
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