28 :
EigenMatrix(ilist.size(), ilist.begin()->size()) {
29 for (
auto row = ilist.begin(); row != ilist.end(); ++row) {
30 if (row->size() !=
size2()) {
31 throw std::runtime_error(
"All rows in initializer list must have the same size.");
33 auto i =
static_cast<size_t>(std::distance(ilist.begin(), row));
34 for (
auto cell = row->begin(); cell != row->end(); ++cell) {
35 auto j =
static_cast<size_t>(std::distance(row->begin(), cell));
53 if (row + nRows > M.
size1() || col + nCols > M.
size2()) {
54 throw std::runtime_error(
"Submatrix exceeds matrix size.");
56 size_t newSize = nRows * nCols;
71 Eigen::MatrixXd tempMatr = tempMatrTr.transpose();
72 std::copy(tempMatr.data(), tempMatr.data() + tempMatr.size(),
m_data.data());
83 throw std::runtime_error(
"Submatrix exceeds matrix size.");
91 Eigen::MatrixXd tempMatr = tempMatrTr.transpose();
92 auto tempMatrSubView =
EigenMatrix_View(tempMatr.data(), tempMatr.rows(), tempMatr.cols(), nRows, nCols, row, col);
93 Eigen::MatrixXd tempMatrSub = tempMatrSubView.matrix_inspector();
94 std::copy(tempMatrSub.data(), tempMatrSub.data() + tempMatrSub.size(),
m_data.data());
111 for (
size_t i = 0; i < (size_t)
m.size(); i++) {
125 if (nx == 0 && ny == 0) {
148 throw std::out_of_range(
"Matrix is empty.");
153 throw std::out_of_range(
"EigenMatrix indices are out of range.");
162 throw std::out_of_range(
"Matrix is empty.");
167 throw std::out_of_range(
"EigenMatrix indices are out of range.");
180 const auto n =
d.size();
183 for (
size_t i = 0; i <
n; ++i) {
226 throw std::invalid_argument(
"Matrix by vector multiplication: wrong size of vector.");
240 if (
m.size1() !=
size2()) {
241 throw std::invalid_argument(
"Matrix by matrix multiplication: matricies are of incompatible sizes.");
256 throw std::invalid_argument(
"System of linear equations: the matrix must be square.");
259 if (
rhs.size() !=
n) {
260 throw std::invalid_argument(
"System of linear equations: right-hand side vector has wrong size.");
263 throw std::invalid_argument(
"Matrix A is singular.");
266 Eigen::MatrixXd b =
rhs.inspector();
267 Eigen::ColPivHouseholderQR<Eigen::MatrixXd> dec(
inspector());
268 auto res = dec.solve(b);
280 throw std::runtime_error(
"Matrix inverse: the matrix must be square.");
288 throw std::runtime_error(
"Matrix inverse: the matrix must be square.");
302 throw std::runtime_error(
"Matrix eigenSystem: the matrix must be square.");
305 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> solver;
312 if (!solver.eigenvectors().imag().isZero()) {
313 throw std::invalid_argument(
"eigensystem has complex eigenvalues or eigenvectors");
315 eigenValues = solver.eigenvalues().real();
316 eigenVectors = solver.eigenvectors().real();
324 throw std::out_of_range(
"EigenMatrix row index is out of range.");
328 Eigen::VectorXd rowVec = Eigen::Map<Eigen::VectorXd, 0, Eigen::InnerStride<>>(
337 throw std::out_of_range(
"EigenMatrix column index is out of range.");
341 Eigen::VectorXd colVec = Eigen::Map<Eigen::VectorXd, 0, Eigen::InnerStride<>>(
351 throw std::invalid_argument(
"Matrix by vector multiplication: wrong size of vector.");
const std::vector< double > & rhs
double value
The value of the point.
const std::vector< Type > & m_data
map_type & matrix_mutator()
size_t innerStride() const
const map_type matrix_inspector() const
size_t outerStride() const
A wrapper around Eigen::Matrix.
EigenMatrix & operator-=(const EigenMatrix &M)
Subtract a matrix from this.
bool isEmpty() const
Is matrix empty.
EigenMatrix_View m_view
The pointer to the vector.
void set(size_t i, size_t j, double value)
Set an element.
EigenMatrix()=default
Constructor.
EigenVector copyColumn(size_t i) const
Copy a column into an EigenVector.
EigenVector copyRow(size_t i) const
Copy a row into an EigenVector.
double get(size_t i, size_t j) const
Get an element.
size_t size1() const
First size of the matrix.
void eigenSystem(EigenVector &eigenValues, EigenMatrix &eigenVectors)
Calculate the eigensystem of a symmetric matrix.
double det() const
Calculate the determinant.
EigenMatrix tr() const
Calculate the eigensystem of a symmetric matrix.
EigenVector multiplyByVector(const EigenVector &v) const
map_type copy_view() const
Get a copy of the Eigen matrix.
EigenMatrix & operator*=(const double &d)
Multiply this matrix by a number.
void diag(const EigenVector &d)
Set the matrix to be diagonal.
void invert()
Invert this matrix.
EigenMatrix move()
Create a new matrix and move the data to it.
std::vector< double > m_data
Default element storage.
map_type & mutator()
Get the map to Eigen matrix.
EigenMatrix & operator+=(const EigenMatrix &M)
Add a matrix to this.
EigenVector operator*(const EigenVector &v) const
Matrix by vector multiplication.
EigenMatrix & operator=(const EigenMatrix &M)
Copy assignment operator.
void zero()
Set all elements to zero.
size_t size2() const
Second size of the matrix.
void identity()
Set this matrix to identity matrix.
void solve(const EigenVector &rhs, EigenVector &x)
Solve system of linear equations M*x == rhs, M is this matrix This matrix is destroyed.
const map_type inspector() const
Get a const copy of the Eigen matrix.
void resize(const size_t nx, const size_t ny)
Resize the matrix.
A wrapper around Eigen::Vector.
const vec_map_type inspector() const
Get the const map of the eigen vector.
size_t size() const
Size of the vector.
std::vector< T > getVector() const
size_t numRows() const
Return the number of rows in the matrix.
size_t numCols() const
Return the number of columns in the matrix.