Mantid
Loading...
Searching...
No Matches
EigenMatrix.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "EigenVector.h"
10#include "MantidCurveFitting/DllConfig.h"
11
12#include "EigenMatrixView.h"
13#include "MantidKernel/Matrix.h"
14
15#include "Eigen/Core"
16#include "Eigen/Dense"
17
18#include <iomanip>
19#include <stdexcept>
20#include <vector>
21
22namespace Mantid {
23namespace CurveFitting {
24
25class EigenMatrix;
26
33class MANTID_CURVEFITTING_DLL EigenMatrix {
34public:
36 EigenMatrix() = default;
38 EigenMatrix(const size_t nx, const size_t ny);
40 EigenMatrix(std::initializer_list<std::initializer_list<double>> ilist);
42 EigenMatrix(const EigenMatrix &M);
44 EigenMatrix(EigenMatrix &M, size_t row, size_t col, size_t nRows, size_t nCols);
48 EigenMatrix(const Kernel::Matrix<double> &M, size_t row, size_t col, size_t nRows, size_t nCols);
49
51 EigenMatrix &operator=(const EigenMatrix &M);
53 EigenMatrix &operator=(const Eigen::MatrixXd v);
54
56 inline map_type &mutator() { return m_view.matrix_mutator(); }
58 inline const map_type inspector() const { return m_view.matrix_inspector(); }
60 inline map_type copy_view() const { return m_view.matrix_copy(); }
61
63 bool isEmpty() const;
65 void resize(const size_t nx, const size_t ny);
67 size_t size1() const;
69 size_t size2() const;
70
72 void set(size_t i, size_t j, double value);
74 double get(size_t i, size_t j) const;
76 double operator()(size_t i, size_t j) const;
78 double &operator()(size_t i, size_t j);
79
81 void identity();
83 void zero();
85 void diag(const EigenVector &d);
89 EigenMatrix &operator+=(const double &d);
93 EigenMatrix &operator-=(const double &d);
95 EigenMatrix &operator*=(const double &d);
97 EigenVector operator*(const EigenVector &v) const;
99 EigenMatrix operator*(const EigenMatrix &m) const;
100
102 EigenVector copyRow(size_t i) const;
104 EigenVector copyColumn(size_t i) const;
105
110 void solve(const EigenVector &rhs, EigenVector &x);
112 void invert();
114 double det() const;
116 void eigenSystem(EigenVector &eigenValues, EigenMatrix &eigenVectors);
118 EigenMatrix tr() const;
119
120protected:
122 EigenMatrix move();
123
124private:
126 EigenMatrix(std::vector<double> &&data, size_t nx, size_t ny);
128 std::vector<double> m_data;
131 EigenVector multiplyByVector(const EigenVector &v) const;
132};
133
135inline std::ostream &operator<<(std::ostream &ostr, const EigenMatrix &m) {
136 std::ios::fmtflags fflags(ostr.flags());
137 ostr << std::scientific << std::setprecision(6);
138 for (size_t i = 0; i < m.size1(); ++i) {
139 for (size_t j = 0; j < m.size2(); ++j) {
140 ostr << std::setw(13) << m.get(i, j) << ' ';
141 }
142 ostr << '\n';
143 }
144 ostr.flags(fflags);
145 return ostr;
146}
147
149inline double EigenMatrix::operator()(size_t i, size_t j) const { return const_cast<EigenMatrix &>(*this)(i, j); }
150
152inline double &EigenMatrix::operator()(size_t i, size_t j) { return m_data[j * m_view.rows() + i]; }
153
154} // namespace CurveFitting
155} // namespace Mantid
const std::vector< double > & rhs
double value
The value of the point.
Definition: FitMW.cpp:51
A wrapper around Eigen::Matrix.
Definition: EigenMatrix.h:33
EigenMatrix_View m_view
The pointer to the vector.
Definition: EigenMatrix.h:130
EigenMatrix()=default
Constructor.
map_type copy_view() const
Get a copy of the Eigen matrix.
Definition: EigenMatrix.h:60
std::vector< double > m_data
Default element storage.
Definition: EigenMatrix.h:128
map_type & mutator()
Get the map to Eigen matrix.
Definition: EigenMatrix.h:56
double operator()(size_t i, size_t j) const
The "index" operator.
Definition: EigenMatrix.h:149
const map_type inspector() const
Get a const copy of the Eigen matrix.
Definition: EigenMatrix.h:58
A wrapper around Eigen::Vector.
Definition: EigenVector.h:27
Numerical Matrix class.
Definition: Matrix.h:42
MatrixWorkspace_sptr MANTID_API_DLL operator*(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator+=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator-=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Subtracts two workspaces.
MANTID_API_DLL std::ostream & operator<<(std::ostream &, const AlgorithmHistory &)
Prints a text representation.
MatrixWorkspace_sptr MANTID_API_DLL operator*=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
Eigen::Map< Eigen::MatrixXd, 0, dynamic_stride > map_type
Helper class which provides the Collimation Length for SANS instruments.