Mantid
Loading...
Searching...
No Matches
EigenVectorView.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2022 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 +
8
9namespace Mantid::CurveFitting {
10// EigenVector_View Constructors
11// default constructor
13
14// constructor: map->vector view
18EigenVector_View::EigenVector_View(vec_map_type &vector, const int nElements, const size_t startElement)
19 : m_view(vector.data(), vector.size(), dynamic_stride(0, 1)) {
20 if (nElements == -1) {
21 // if nElements is default, do nothing as m_view is initialised as such
22 } else {
23 new (&m_view) vec_map_type(vector.data() + startElement, nElements, dynamic_stride(0, 1));
24 }
25}
26
27// constructor: vector->vector view
31EigenVector_View::EigenVector_View(Eigen::VectorXd &vector, const int nElements, const size_t startElement)
32 : m_view(vector.data(), vector.size(), dynamic_stride(0, 1)) {
33 if (nElements == -1) {
34 // if nElements is default, do nothing as m_view is initialised as such
35 } else {
36 new (&m_view) vec_map_type(vector.data() + startElement, nElements, dynamic_stride(0, 1));
37 }
38}
39
40// constructor: array->vector view
44EigenVector_View::EigenVector_View(double *base, const size_t nElements, const size_t startElement)
45 : m_view(base + startElement, nElements, dynamic_stride(0, 1)) {}
46
47// CONST constructor: map->vector view
51EigenVector_View::EigenVector_View(const vec_map_type &vector, const size_t nElements, const size_t startElement)
52 : m_view({}, 0, dynamic_stride(0, 0)) {
53 new (&m_view) vec_const_map_type(vector.data() + startElement, nElements, dynamic_stride(0, 1));
54}
55
56// CONST constructor: vector->vector view
60EigenVector_View::EigenVector_View(const Eigen::VectorXd &vector, const size_t nElements, const size_t startElement)
61 : m_view({}, 0, dynamic_stride(0, 0)), m_isConst(true) {
62 new (&m_view) vec_const_map_type(vector.data() + startElement, nElements, dynamic_stride(0, 1));
63}
64
65// CONST constructor: array->vector view
69EigenVector_View::EigenVector_View(const double *base, const size_t nElements, const size_t startElement)
70 : m_view({}, 0, dynamic_stride(0, 0)), m_isConst(true) {
71 new (&m_view) vec_const_map_type(base + startElement, nElements, dynamic_stride(0, 1));
72}
73
74// CONST copy constructor
76EigenVector_View::EigenVector_View(const EigenVector_View &v) : m_view({}, 0, dynamic_stride(0, 0)), m_isConst(true) {
77 new (&m_view) vec_const_map_type(v.vector_inspector().data(), v.size(), dynamic_stride(0, 1));
78}
79
80// copy constructor
84 : m_view(v.vector_mutator().data(), v.size(), dynamic_stride(0, 1)), m_isConst(false) {}
85
88 if (!m_isConst) {
89 return m_view;
90 } else {
91 throw std::runtime_error("Vector is const vector, cannot mutate const vector.");
92 }
93}
94
96 new (&m_view)
97 vec_map_type(v.m_view.data(), v.m_view.size(), dynamic_stride(v.m_view.outerStride(), v.m_view.innerStride()));
98
99 return *this;
100}
101
103 new (&m_view)
104 vec_map_type(v.m_view.data(), v.m_view.size(), dynamic_stride(v.m_view.outerStride(), v.m_view.innerStride()));
105 return *this;
106}
107} // namespace Mantid::CurveFitting
EigenVector_View & operator=(EigenVector_View &V)
Eigen::Map< Eigen::VectorXd, 0, dynamic_stride > vec_map_type
Eigen::Map< const Eigen::VectorXd, 0, dynamic_stride > vec_const_map_type
Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > dynamic_stride