13namespace CurveFitting {
29 using ElementRefType =
decltype(std::declval<MatrixClass>().operator()(0, 0));
37 FortranMatrix(
const int iFrom,
const int iTo,
const int jFrom,
const int jTo);
39 void allocate(
const int iFrom,
const int iTo,
const int jFrom,
const int jTo);
59 static size_t makeSize(
const int firstIndex,
const int lastIndex);
66 if (lastIndex < firstIndex) {
67 throw std::invalid_argument(
"Matrix defined with invalid index range.");
69 return static_cast<size_t>(lastIndex - firstIndex + 1);
73template <
class MatrixClass>
75 : MatrixClass(this->makeSize(1, 1), this->makeSize(1, 1)), m_base1(1), m_base2(1) {}
78template <
class MatrixClass>
80 : MatrixClass(this->makeSize(1, nx), this->makeSize(1, ny)), m_base1(1), m_base2(1) {}
93template <
class MatrixClass>
95 : MatrixClass(this->makeSize(iFirst, iLast), this->makeSize(jFirst, jLast)), m_base1(iFirst), m_base2(jFirst) {}
102template <
class MatrixClass>
106 this->resize(this->makeSize(iFirst, iLast), this->makeSize(jFirst, jLast));
115 this->resize(this->makeSize(1, nx), this->makeSize(1, ny));
119template <
class MatrixClass>
122 return this->MatrixClass::operator()(
static_cast<size_t>(i - m_base1),
static_cast<size_t>(j - m_base2));
126template <
class MatrixClass>
128 return this->MatrixClass::operator()(
static_cast<size_t>(i - m_base1),
static_cast<size_t>(j - m_base2));
133 return MatrixClass(std::move(*
this));
151 this->resize(
m.size1(),
m.size2());
152 for (
size_t i = 0; i < this->size1(); i++) {
153 for (
size_t j = 0; j < this->size2(); j++) {
154 this->operator()((
int)i + 1, (
int)j + 1) =
m.get(i, j);
FortranMatrix is a wrapper template for EigenMatrix and EigenComplexMatrix to simplify porting fortra...
void allocate(const int iFrom, const int iTo, const int jFrom, const int jTo)
Resize the matrix.
int m_base1
Base for the first index.
ElementConstType operator()(const int i, const int j) const
Index operator.
int len2() const
Get the size along the second dimension as an int.
static size_t makeSize(const int firstIndex, const int lastIndex)
Calculate the size (1D) of a matrix First.
int len1() const
Get the size along the first dimension as an int.
int m_base2
Base for the second index.
ElementRefType operator()(const int i, const int j)
Get the reference to the data element.
decltype(std::declval< MatrixClass >().operator()(0, 0)) ElementRefType
MatrixClass moveToBaseMatrix()
Move the data to a new matrix of MatrixClass.
FortranMatrix(const int nx, const int ny)
Constructor.
FortranMatrix()
Constructor.
void allocate(const int nx, const int ny)
Resize the matrix.
FortranMatrix< MatrixClass > transpose() const
copy and transpose the matrix
decltype(std::declval< const MatrixClass >().operator()(0, 0)) ElementConstType
Typedef the types returned by the base class's operators [].
FortranMatrix(const int iFrom, const int iTo, const int jFrom, const int jTo)
Constructor.
FortranMatrix< MatrixClass > & operator=(const MatrixClass &m)
Assignment operator - Matrix Class.
Helper class which provides the Collimation Length for SANS instruments.