Sleipnir C++ API
Loading...
Searching...
No Matches
VariableMatrix.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <algorithm>
6#include <concepts>
7#include <initializer_list>
8#include <iterator>
9#include <span>
10#include <utility>
11#include <vector>
12
13#include <Eigen/Core>
14
22
23namespace sleipnir {
24
29 public:
30 struct empty_t {};
31 static constexpr empty_t empty{};
32
36 VariableMatrix() = default;
37
43 explicit VariableMatrix(int rows) : m_rows{rows}, m_cols{1} {
44 m_storage.reserve(Rows());
45 for (int row = 0; row < Rows(); ++row) {
46 m_storage.emplace_back();
47 }
48 }
49
56 VariableMatrix(int rows, int cols) : m_rows{rows}, m_cols{cols} {
57 m_storage.reserve(Rows() * Cols());
58 for (int index = 0; index < Rows() * Cols(); ++index) {
59 m_storage.emplace_back();
60 }
61 }
62
69 VariableMatrix(empty_t, int rows, int cols) : m_rows{rows}, m_cols{cols} {
70 m_storage.reserve(Rows() * Cols());
71 for (int index = 0; index < Rows() * Cols(); ++index) {
72 m_storage.emplace_back(nullptr);
73 }
74 }
75
81 VariableMatrix( // NOLINT
82 std::initializer_list<std::initializer_list<Variable>> list) {
83 // Get row and column counts for destination matrix
84 m_rows = list.size();
85 m_cols = 0;
86 if (list.size() > 0) {
87 m_cols = list.begin()->size();
88 }
89
90 // Assert the first and latest column counts are the same
91 for ([[maybe_unused]]
92 const auto& row : list) {
93 Assert(list.begin()->size() == row.size());
94 }
95
96 m_storage.reserve(Rows() * Cols());
97 for (const auto& row : list) {
98 std::copy(row.begin(), row.end(), std::back_inserter(m_storage));
99 }
100 }
101
109 VariableMatrix(const std::vector<std::vector<double>>& list) { // NOLINT
110 // Get row and column counts for destination matrix
111 m_rows = list.size();
112 m_cols = 0;
113 if (list.size() > 0) {
114 m_cols = list.begin()->size();
115 }
116
117 // Assert the first and latest column counts are the same
118 for ([[maybe_unused]]
119 const auto& row : list) {
120 Assert(list.begin()->size() == row.size());
121 }
122
123 m_storage.reserve(Rows() * Cols());
124 for (const auto& row : list) {
125 std::copy(row.begin(), row.end(), std::back_inserter(m_storage));
126 }
127 }
128
136 VariableMatrix(const std::vector<std::vector<Variable>>& list) { // NOLINT
137 // Get row and column counts for destination matrix
138 m_rows = list.size();
139 m_cols = 0;
140 if (list.size() > 0) {
141 m_cols = list.begin()->size();
142 }
143
144 // Assert the first and latest column counts are the same
145 for ([[maybe_unused]]
146 const auto& row : list) {
147 Assert(list.begin()->size() == row.size());
148 }
149
150 m_storage.reserve(Rows() * Cols());
151 for (const auto& row : list) {
152 std::copy(row.begin(), row.end(), std::back_inserter(m_storage));
153 }
154 }
155
161 template <typename Derived>
162 VariableMatrix(const Eigen::MatrixBase<Derived>& values) // NOLINT
163 : m_rows{static_cast<int>(values.rows())},
164 m_cols{static_cast<int>(values.cols())} {
165 m_storage.reserve(values.rows() * values.cols());
166 for (int row = 0; row < values.rows(); ++row) {
167 for (int col = 0; col < values.cols(); ++col) {
168 m_storage.emplace_back(values(row, col));
169 }
170 }
171 }
172
178 template <typename Derived>
179 VariableMatrix(const Eigen::DiagonalBase<Derived>& values) // NOLINT
180 : m_rows{static_cast<int>(values.rows())},
181 m_cols{static_cast<int>(values.cols())} {
182 m_storage.reserve(values.rows() * values.cols());
183 for (int row = 0; row < values.rows(); ++row) {
184 for (int col = 0; col < values.cols(); ++col) {
185 if (row == col) {
186 m_storage.emplace_back(values.diagonal()(row));
187 } else {
188 m_storage.emplace_back(0.0);
189 }
190 }
191 }
192 }
193
199 template <typename Derived>
200 VariableMatrix& operator=(const Eigen::MatrixBase<Derived>& values) {
201 Assert(Rows() == values.rows());
202 Assert(Cols() == values.cols());
203
204 for (int row = 0; row < values.rows(); ++row) {
205 for (int col = 0; col < values.cols(); ++col) {
206 (*this)(row, col) = values(row, col);
207 }
208 }
209
210 return *this;
211 }
212
218 template <typename Derived>
219 requires std::same_as<typename Derived::Scalar, double>
220 void SetValue(const Eigen::MatrixBase<Derived>& values) {
221 Assert(Rows() == values.rows());
222 Assert(Cols() == values.cols());
223
224 for (int row = 0; row < values.rows(); ++row) {
225 for (int col = 0; col < values.cols(); ++col) {
226 (*this)(row, col).SetValue(values(row, col));
227 }
228 }
229 }
230
236 VariableMatrix(const Variable& variable) // NOLINT
237 : m_rows{1}, m_cols{1} {
238 m_storage.emplace_back(variable);
239 }
240
246 VariableMatrix(Variable&& variable) : m_rows{1}, m_cols{1} { // NOLINT
247 m_storage.emplace_back(std::move(variable));
248 }
249
256 : m_rows{values.Rows()}, m_cols{values.Cols()} {
257 m_storage.reserve(Rows() * Cols());
258 for (int row = 0; row < Rows(); ++row) {
259 for (int col = 0; col < Cols(); ++col) {
260 m_storage.emplace_back(values(row, col));
261 }
262 }
263 }
264
271 : m_rows{values.Rows()}, m_cols{values.Cols()} {
272 m_storage.reserve(Rows() * Cols());
273 for (int row = 0; row < Rows(); ++row) {
274 for (int col = 0; col < Cols(); ++col) {
275 m_storage.emplace_back(values(row, col));
276 }
277 }
278 }
279
285 explicit VariableMatrix(std::span<const Variable> values)
286 : m_rows{static_cast<int>(values.size())}, m_cols{1} {
287 m_storage.reserve(Rows() * Cols());
288 for (int row = 0; row < Rows(); ++row) {
289 for (int col = 0; col < Cols(); ++col) {
290 m_storage.emplace_back(values[row * Cols() + col]);
291 }
292 }
293 }
294
302 VariableMatrix(std::span<const Variable> values, int rows, int cols)
303 : m_rows{rows}, m_cols{cols} {
304 Assert(static_cast<int>(values.size()) == Rows() * Cols());
305 m_storage.reserve(Rows() * Cols());
306 for (int row = 0; row < Rows(); ++row) {
307 for (int col = 0; col < Cols(); ++col) {
308 m_storage.emplace_back(values[row * Cols() + col]);
309 }
310 }
311 }
312
319 Variable& operator()(int row, int col) {
320 Assert(row >= 0 && row < Rows());
321 Assert(col >= 0 && col < Cols());
322 return m_storage[row * Cols() + col];
323 }
324
331 const Variable& operator()(int row, int col) const {
332 Assert(row >= 0 && row < Rows());
333 Assert(col >= 0 && col < Cols());
334 return m_storage[row * Cols() + col];
335 }
336
343 Assert(row >= 0 && row < Rows() * Cols());
344 return m_storage[row];
345 }
346
352 const Variable& operator()(int row) const {
353 Assert(row >= 0 && row < Rows() * Cols());
354 return m_storage[row];
355 }
356
365 VariableBlock<VariableMatrix> Block(int rowOffset, int colOffset,
366 int blockRows, int blockCols) {
367 Assert(rowOffset >= 0 && rowOffset <= Rows());
368 Assert(colOffset >= 0 && colOffset <= Cols());
369 Assert(blockRows >= 0 && blockRows <= Rows() - rowOffset);
370 Assert(blockCols >= 0 && blockCols <= Cols() - colOffset);
371 return VariableBlock{*this, rowOffset, colOffset, blockRows, blockCols};
372 }
373
382 const VariableBlock<const VariableMatrix> Block(int rowOffset, int colOffset,
383 int blockRows,
384 int blockCols) const {
385 Assert(rowOffset >= 0 && rowOffset <= Rows());
386 Assert(colOffset >= 0 && colOffset <= Cols());
387 Assert(blockRows >= 0 && blockRows <= Rows() - rowOffset);
388 Assert(blockCols >= 0 && blockCols <= Cols() - colOffset);
389 return VariableBlock{*this, rowOffset, colOffset, blockRows, blockCols};
390 }
391
399 int rowSliceLength = rowSlice.Adjust(Rows());
400 int colSliceLength = colSlice.Adjust(Cols());
401 return VariableBlock{*this, std::move(rowSlice), rowSliceLength,
402 std::move(colSlice), colSliceLength};
403 }
404
412 Slice colSlice) const {
413 int rowSliceLength = rowSlice.Adjust(Rows());
414 int colSliceLength = colSlice.Adjust(Cols());
415 return VariableBlock{*this, std::move(rowSlice), rowSliceLength,
416 std::move(colSlice), colSliceLength};
417 }
418
431 VariableBlock<VariableMatrix> operator()(Slice rowSlice, int rowSliceLength,
432 Slice colSlice, int colSliceLength) {
433 return VariableBlock{*this, std::move(rowSlice), rowSliceLength,
434 std::move(colSlice), colSliceLength};
435 }
436
449 Slice rowSlice, int rowSliceLength, Slice colSlice,
450 int colSliceLength) const {
451 return VariableBlock{*this, std::move(rowSlice), rowSliceLength,
452 std::move(colSlice), colSliceLength};
453 }
454
461 VariableBlock<VariableMatrix> Segment(int offset, int length) {
462 Assert(offset >= 0 && offset < Rows() * Cols());
463 Assert(length >= 0 && length <= Rows() * Cols() - offset);
464 return Block(offset, 0, length, 1);
465 }
466
474 int length) const {
475 Assert(offset >= 0 && offset < Rows() * Cols());
476 Assert(length >= 0 && length <= Rows() * Cols() - offset);
477 return Block(offset, 0, length, 1);
478 }
479
486 Assert(row >= 0 && row < Rows());
487 return Block(row, 0, 1, Cols());
488 }
489
496 Assert(row >= 0 && row < Rows());
497 return Block(row, 0, 1, Cols());
498 }
499
506 Assert(col >= 0 && col < Cols());
507 return Block(0, col, Rows(), 1);
508 }
509
516 Assert(col >= 0 && col < Cols());
517 return Block(0, col, Rows(), 1);
518 }
519
527 operator*(const VariableMatrix& lhs, const VariableMatrix& rhs) {
528 Assert(lhs.Cols() == rhs.Rows());
529
530 VariableMatrix result{lhs.Rows(), rhs.Cols()};
531
532 for (int i = 0; i < lhs.Rows(); ++i) {
533 for (int j = 0; j < rhs.Cols(); ++j) {
534 Variable sum;
535 for (int k = 0; k < lhs.Cols(); ++k) {
536 sum += lhs(i, k) * rhs(k, j);
537 }
538 result(i, j) = sum;
539 }
540 }
541
542 return result;
543 }
544
552 const Variable& rhs) {
553 VariableMatrix result{lhs.Rows(), lhs.Cols()};
554
555 for (int row = 0; row < result.Rows(); ++row) {
556 for (int col = 0; col < result.Cols(); ++col) {
557 result(row, col) = lhs(row, col) * rhs;
558 }
559 }
560
561 return result;
562 }
563
571 double rhs) {
572 return lhs * Variable{rhs};
573 }
574
582 operator*(const Variable& lhs, const VariableMatrix& rhs) {
583 VariableMatrix result{rhs.Rows(), rhs.Cols()};
584
585 for (int row = 0; row < result.Rows(); ++row) {
586 for (int col = 0; col < result.Cols(); ++col) {
587 result(row, col) = rhs(row, col) * lhs;
588 }
589 }
590
591 return result;
592 }
593
601 operator*(double lhs, const VariableMatrix& rhs) {
602 return Variable{lhs} * rhs;
603 }
604
611 Assert(Cols() == rhs.Rows() && Cols() == rhs.Cols());
612
613 for (int i = 0; i < Rows(); ++i) {
614 for (int j = 0; j < rhs.Cols(); ++j) {
615 Variable sum;
616 for (int k = 0; k < Cols(); ++k) {
617 sum += (*this)(i, k) * rhs(k, j);
618 }
619 (*this)(i, j) = sum;
620 }
621 }
622
623 return *this;
624 }
625
633 const Variable& rhs) {
634 VariableMatrix result{lhs.Rows(), lhs.Cols()};
635
636 for (int row = 0; row < result.Rows(); ++row) {
637 for (int col = 0; col < result.Cols(); ++col) {
638 result(row, col) = lhs(row, col) / rhs;
639 }
640 }
641
642 return result;
643 }
644
652 for (int row = 0; row < Rows(); ++row) {
653 for (int col = 0; col < Cols(); ++col) {
654 (*this)(row, col) /= rhs;
655 }
656 }
657
658 return *this;
659 }
660
668 operator+(const VariableMatrix& lhs, const VariableMatrix& rhs) {
669 VariableMatrix result{lhs.Rows(), lhs.Cols()};
670
671 for (int row = 0; row < result.Rows(); ++row) {
672 for (int col = 0; col < result.Cols(); ++col) {
673 result(row, col) = lhs(row, col) + rhs(row, col);
674 }
675 }
676
677 return result;
678 }
679
686 for (int row = 0; row < Rows(); ++row) {
687 for (int col = 0; col < Cols(); ++col) {
688 (*this)(row, col) += rhs(row, col);
689 }
690 }
691
692 return *this;
693 }
694
702 operator-(const VariableMatrix& lhs, const VariableMatrix& rhs) {
703 VariableMatrix result{lhs.Rows(), lhs.Cols()};
704
705 for (int row = 0; row < result.Rows(); ++row) {
706 for (int col = 0; col < result.Cols(); ++col) {
707 result(row, col) = lhs(row, col) - rhs(row, col);
708 }
709 }
710
711 return result;
712 }
713
720 for (int row = 0; row < Rows(); ++row) {
721 for (int col = 0; col < Cols(); ++col) {
722 (*this)(row, col) -= rhs(row, col);
723 }
724 }
725
726 return *this;
727 }
728
736 VariableMatrix result{lhs.Rows(), lhs.Cols()};
737
738 for (int row = 0; row < result.Rows(); ++row) {
739 for (int col = 0; col < result.Cols(); ++col) {
740 result(row, col) = -lhs(row, col);
741 }
742 }
743
744 return result;
745 }
746
750 operator Variable() const { // NOLINT
751 Assert(Rows() == 1 && Cols() == 1);
752 return (*this)(0, 0);
753 }
754
759 VariableMatrix result{Cols(), Rows()};
760
761 for (int row = 0; row < Rows(); ++row) {
762 for (int col = 0; col < Cols(); ++col) {
763 result(col, row) = (*this)(row, col);
764 }
765 }
766
767 return result;
768 }
769
773 int Rows() const { return m_rows; }
774
778 int Cols() const { return m_cols; }
779
786 double Value(int row, int col) {
787 Assert(row >= 0 && row < Rows());
788 Assert(col >= 0 && col < Cols());
789 return m_storage[row * Cols() + col].Value();
790 }
791
797 double Value(int index) {
798 Assert(index >= 0 && index < Rows() * Cols());
799 return m_storage[index].Value();
800 }
801
805 Eigen::MatrixXd Value() {
806 Eigen::MatrixXd result{Rows(), Cols()};
807
808 for (int row = 0; row < Rows(); ++row) {
809 for (int col = 0; col < Cols(); ++col) {
810 result(row, col) = Value(row, col);
811 }
812 }
813
814 return result;
815 }
816
823 function_ref<Variable(const Variable& x)> unaryOp) const {
824 VariableMatrix result{Rows(), Cols()};
825
826 for (int row = 0; row < Rows(); ++row) {
827 for (int col = 0; col < Cols(); ++col) {
828 result(row, col) = unaryOp((*this)(row, col));
829 }
830 }
831
832 return result;
833 }
834
835 class iterator {
836 public:
837 using iterator_category = std::forward_iterator_tag;
839 using difference_type = std::ptrdiff_t;
842
844
846 ++m_it;
847 return *this;
848 }
850 iterator retval = *this;
851 ++(*this);
852 return retval;
853 }
854 bool operator==(const iterator&) const = default;
855 reference operator*() { return *m_it; }
856
857 private:
859 };
860
862 public:
863 using iterator_category = std::forward_iterator_tag;
865 using difference_type = std::ptrdiff_t;
867 using const_reference = const Variable&;
868
871
873 ++m_it;
874 return *this;
875 }
877 const_iterator retval = *this;
878 ++(*this);
879 return retval;
880 }
881 bool operator==(const const_iterator&) const = default;
882 const_reference operator*() const { return *m_it; }
883
884 private:
886 };
887
891 iterator begin() { return iterator{m_storage.begin()}; }
892
896 iterator end() { return iterator{m_storage.end()}; }
897
901 const_iterator begin() const { return const_iterator{m_storage.begin()}; }
902
906 const_iterator end() const { return const_iterator{m_storage.end()}; }
907
911 const_iterator cbegin() const { return const_iterator{m_storage.cbegin()}; }
912
916 const_iterator cend() const { return const_iterator{m_storage.cend()}; }
917
921 size_t size() const { return m_storage.size(); }
922
929 static VariableMatrix Zero(int rows, int cols) {
930 VariableMatrix result{rows, cols};
931
932 for (auto& elem : result) {
933 elem = 0.0;
934 }
935
936 return result;
937 }
938
945 static VariableMatrix Ones(int rows, int cols) {
946 VariableMatrix result{rows, cols};
947
948 for (auto& elem : result) {
949 elem = 1.0;
950 }
951
952 return result;
953 }
954
955 private:
956 small_vector<Variable> m_storage;
957 int m_rows = 0;
958 int m_cols = 0;
959};
960
969 const VariableMatrix& lhs, const VariableMatrix& rhs,
970 function_ref<Variable(const Variable& x, const Variable& y)> binaryOp) {
971 Assert(lhs.Rows() == rhs.Rows());
972 Assert(lhs.Rows() == rhs.Rows());
973
974 VariableMatrix result{lhs.Rows(), lhs.Cols()};
975
976 for (int row = 0; row < lhs.Rows(); ++row) {
977 for (int col = 0; col < lhs.Cols(); ++col) {
978 result(row, col) = binaryOp(lhs(row, col), rhs(row, col));
979 }
980 }
981
982 return result;
983}
984
996 std::initializer_list<std::initializer_list<VariableMatrix>> list) {
997 // Get row and column counts for destination matrix
998 int rows = 0;
999 int cols = -1;
1000 for (const auto& row : list) {
1001 if (row.size() > 0) {
1002 rows += row.begin()->Rows();
1003 }
1004
1005 // Get number of columns in this row
1006 int latestCols = 0;
1007 for (const auto& elem : row) {
1008 // Assert the first and latest row have the same height
1009 Assert(row.begin()->Rows() == elem.Rows());
1010
1011 latestCols += elem.Cols();
1012 }
1013
1014 // If this is the first row, record the column count. Otherwise, assert the
1015 // first and latest column counts are the same.
1016 if (cols == -1) {
1017 cols = latestCols;
1018 } else {
1020 }
1021 }
1022
1024
1025 int rowOffset = 0;
1026 for (const auto& row : list) {
1027 int colOffset = 0;
1028 for (const auto& elem : row) {
1029 result.Block(rowOffset, colOffset, elem.Rows(), elem.Cols()) = elem;
1030 colOffset += elem.Cols();
1031 }
1032 rowOffset += row.begin()->Rows();
1033 }
1034
1035 return result;
1036}
1037
1051 const std::vector<std::vector<VariableMatrix>>& list) {
1052 // Get row and column counts for destination matrix
1053 int rows = 0;
1054 int cols = -1;
1055 for (const auto& row : list) {
1056 if (row.size() > 0) {
1057 rows += row.begin()->Rows();
1058 }
1059
1060 // Get number of columns in this row
1061 int latestCols = 0;
1062 for (const auto& elem : row) {
1063 // Assert the first and latest row have the same height
1064 Assert(row.begin()->Rows() == elem.Rows());
1065
1066 latestCols += elem.Cols();
1067 }
1068
1069 // If this is the first row, record the column count. Otherwise, assert the
1070 // first and latest column counts are the same.
1071 if (cols == -1) {
1072 cols = latestCols;
1073 } else {
1075 }
1076 }
1077
1079
1080 int rowOffset = 0;
1081 for (const auto& row : list) {
1082 int colOffset = 0;
1083 for (const auto& elem : row) {
1084 result.Block(rowOffset, colOffset, elem.Rows(), elem.Cols()) = elem;
1085 colOffset += elem.Cols();
1086 }
1087 rowOffset += row.begin()->Rows();
1088 }
1089
1090 return result;
1091}
1092
1101 const VariableMatrix& B);
1102
1103} // namespace sleipnir
#define Assert(condition)
Definition Assert.hpp:24
#define SLEIPNIR_DLLEXPORT
Definition SymbolExports.hpp:34
Definition Slice.hpp:21
constexpr int Adjust(int length)
Definition Slice.hpp:118
Definition VariableBlock.hpp:24
Definition VariableMatrix.hpp:861
std::forward_iterator_tag iterator_category
Definition VariableMatrix.hpp:863
std::ptrdiff_t difference_type
Definition VariableMatrix.hpp:865
bool operator==(const const_iterator &) const =default
const_iterator & operator++()
Definition VariableMatrix.hpp:872
const_reference operator*() const
Definition VariableMatrix.hpp:882
const_iterator(small_vector< Variable >::const_iterator it)
Definition VariableMatrix.hpp:869
const_iterator operator++(int)
Definition VariableMatrix.hpp:876
Definition VariableMatrix.hpp:835
reference operator*()
Definition VariableMatrix.hpp:855
std::ptrdiff_t difference_type
Definition VariableMatrix.hpp:839
bool operator==(const iterator &) const =default
iterator(small_vector< Variable >::iterator it)
Definition VariableMatrix.hpp:843
iterator & operator++()
Definition VariableMatrix.hpp:845
std::forward_iterator_tag iterator_category
Definition VariableMatrix.hpp:837
iterator operator++(int)
Definition VariableMatrix.hpp:849
Definition VariableMatrix.hpp:28
int Cols() const
Definition VariableMatrix.hpp:778
friend SLEIPNIR_DLLEXPORT VariableMatrix operator*(double lhs, const VariableMatrix &rhs)
Definition VariableMatrix.hpp:601
double Value(int row, int col)
Definition VariableMatrix.hpp:786
friend SLEIPNIR_DLLEXPORT VariableMatrix operator/(const VariableMatrix &lhs, const Variable &rhs)
Definition VariableMatrix.hpp:632
VariableBlock< VariableMatrix > Col(int col)
Definition VariableMatrix.hpp:505
VariableMatrix(const std::vector< std::vector< Variable > > &list)
Definition VariableMatrix.hpp:136
const Variable & operator()(int row) const
Definition VariableMatrix.hpp:352
VariableMatrix(empty_t, int rows, int cols)
Definition VariableMatrix.hpp:69
VariableMatrix & operator*=(const VariableMatrix &rhs)
Definition VariableMatrix.hpp:610
VariableMatrix(const Variable &variable)
Definition VariableMatrix.hpp:236
VariableMatrix(std::span< const Variable > values)
Definition VariableMatrix.hpp:285
VariableBlock< VariableMatrix > operator()(Slice rowSlice, Slice colSlice)
Definition VariableMatrix.hpp:398
friend SLEIPNIR_DLLEXPORT VariableMatrix operator*(const VariableMatrix &lhs, const VariableMatrix &rhs)
Definition VariableMatrix.hpp:527
const VariableBlock< const VariableMatrix > Segment(int offset, int length) const
Definition VariableMatrix.hpp:473
static VariableMatrix Zero(int rows, int cols)
Definition VariableMatrix.hpp:929
friend SLEIPNIR_DLLEXPORT VariableMatrix operator*(const VariableMatrix &lhs, double rhs)
Definition VariableMatrix.hpp:570
static VariableMatrix Ones(int rows, int cols)
Definition VariableMatrix.hpp:945
iterator begin()
Definition VariableMatrix.hpp:891
Variable & operator()(int row, int col)
Definition VariableMatrix.hpp:319
const VariableBlock< const VariableMatrix > operator()(Slice rowSlice, Slice colSlice) const
Definition VariableMatrix.hpp:411
VariableMatrix(int rows, int cols)
Definition VariableMatrix.hpp:56
friend SLEIPNIR_DLLEXPORT VariableMatrix operator*(const Variable &lhs, const VariableMatrix &rhs)
Definition VariableMatrix.hpp:582
VariableMatrix(const VariableBlock< const VariableMatrix > &values)
Definition VariableMatrix.hpp:270
VariableMatrix & operator=(const Eigen::MatrixBase< Derived > &values)
Definition VariableMatrix.hpp:200
VariableMatrix(Variable &&variable)
Definition VariableMatrix.hpp:246
Eigen::MatrixXd Value()
Definition VariableMatrix.hpp:805
const VariableBlock< const VariableMatrix > Block(int rowOffset, int colOffset, int blockRows, int blockCols) const
Definition VariableMatrix.hpp:382
VariableMatrix(const Eigen::DiagonalBase< Derived > &values)
Definition VariableMatrix.hpp:179
VariableMatrix(std::initializer_list< std::initializer_list< Variable > > list)
Definition VariableMatrix.hpp:81
const_iterator begin() const
Definition VariableMatrix.hpp:901
VariableMatrix T() const
Definition VariableMatrix.hpp:758
VariableBlock< VariableMatrix > Block(int rowOffset, int colOffset, int blockRows, int blockCols)
Definition VariableMatrix.hpp:365
int Rows() const
Definition VariableMatrix.hpp:773
friend SLEIPNIR_DLLEXPORT VariableMatrix operator+(const VariableMatrix &lhs, const VariableMatrix &rhs)
Definition VariableMatrix.hpp:668
VariableBlock< VariableMatrix > operator()(Slice rowSlice, int rowSliceLength, Slice colSlice, int colSliceLength)
Definition VariableMatrix.hpp:431
VariableMatrix(std::span< const Variable > values, int rows, int cols)
Definition VariableMatrix.hpp:302
size_t size() const
Definition VariableMatrix.hpp:921
const Variable & operator()(int row, int col) const
Definition VariableMatrix.hpp:331
VariableMatrix(int rows)
Definition VariableMatrix.hpp:43
void SetValue(const Eigen::MatrixBase< Derived > &values)
Definition VariableMatrix.hpp:220
const VariableBlock< const VariableMatrix > Col(int col) const
Definition VariableMatrix.hpp:515
VariableMatrix & operator/=(const Variable &rhs)
Definition VariableMatrix.hpp:651
const_iterator cbegin() const
Definition VariableMatrix.hpp:911
VariableMatrix CwiseTransform(function_ref< Variable(const Variable &x)> unaryOp) const
Definition VariableMatrix.hpp:822
VariableBlock< VariableMatrix > Segment(int offset, int length)
Definition VariableMatrix.hpp:461
VariableMatrix(const VariableBlock< VariableMatrix > &values)
Definition VariableMatrix.hpp:255
const VariableBlock< const VariableMatrix > Row(int row) const
Definition VariableMatrix.hpp:495
VariableMatrix & operator+=(const VariableMatrix &rhs)
Definition VariableMatrix.hpp:685
const VariableBlock< const VariableMatrix > operator()(Slice rowSlice, int rowSliceLength, Slice colSlice, int colSliceLength) const
Definition VariableMatrix.hpp:448
VariableMatrix & operator-=(const VariableMatrix &rhs)
Definition VariableMatrix.hpp:719
VariableMatrix(const Eigen::MatrixBase< Derived > &values)
Definition VariableMatrix.hpp:162
friend SLEIPNIR_DLLEXPORT VariableMatrix operator-(const VariableMatrix &lhs, const VariableMatrix &rhs)
Definition VariableMatrix.hpp:702
iterator end()
Definition VariableMatrix.hpp:896
double Value(int index)
Definition VariableMatrix.hpp:797
const_iterator end() const
Definition VariableMatrix.hpp:906
friend SLEIPNIR_DLLEXPORT VariableMatrix operator*(const VariableMatrix &lhs, const Variable &rhs)
Definition VariableMatrix.hpp:551
VariableMatrix(const std::vector< std::vector< double > > &list)
Definition VariableMatrix.hpp:109
VariableBlock< VariableMatrix > Row(int row)
Definition VariableMatrix.hpp:485
Variable & operator()(int row)
Definition VariableMatrix.hpp:342
friend SLEIPNIR_DLLEXPORT VariableMatrix operator-(const VariableMatrix &lhs)
Definition VariableMatrix.hpp:735
const_iterator cend() const
Definition VariableMatrix.hpp:916
Definition Variable.hpp:33
Definition FunctionRef.hpp:17
Definition small_vector.hpp:499
Definition small_vector.hpp:3616
Definition Expression.hpp:18
SLEIPNIR_DLLEXPORT VariableMatrix Solve(const VariableMatrix &A, const VariableMatrix &B)
IntrusiveSharedPtr< T > AllocateIntrusiveShared(Alloc alloc, Args &&... args)
Definition IntrusiveSharedPtr.hpp:275
constexpr bool empty(const small_vector< T, InlineCapacity, Allocator > &v) noexcept
Definition small_vector.hpp:4353
SLEIPNIR_DLLEXPORT VariableMatrix CwiseReduce(const VariableMatrix &lhs, const VariableMatrix &rhs, function_ref< Variable(const Variable &x, const Variable &y)> binaryOp)
Definition VariableMatrix.hpp:968
SLEIPNIR_DLLEXPORT VariableMatrix Block(std::initializer_list< std::initializer_list< VariableMatrix > > list)
Definition VariableMatrix.hpp:995
constexpr small_vector< T, InlineCapacity, Allocator >::size_type size(const small_vector< T, InlineCapacity, Allocator > &v) noexcept
Definition small_vector.hpp:4336
Definition VariableMatrix.hpp:30