13#include <boost/math/special_functions/fpclassify.hpp>
38 for (
auto cell = ilist.begin(); cell != ilist.end(); ++cell) {
39 auto i =
static_cast<size_t>(std::distance(ilist.begin(), cell));
53 for (
size_t i = 0; i < (size_t)v->size(); ++i) {
86 for (
size_t i = 0; i < (size_t)v.size(); ++i) {
101 }
else if (
n !=
size()) {
117 std::stringstream errmsg;
118 errmsg <<
"EigenVector index = " << i <<
" is out of range = " <<
m_data.size() <<
" in EigenVector.set()";
119 throw std::out_of_range(errmsg.str());
128 std::stringstream errmsg;
129 errmsg <<
"EigenVector index = " << i <<
" is out of range = " <<
m_data.size() <<
" in EigenVector.get()";
130 throw std::out_of_range(errmsg.str());
140 throw std::runtime_error(
"EigenVectors have different sizes.");
150 throw std::runtime_error(
"EigenVectors have different sizes.");
159 throw std::runtime_error(
"EigenVectors have different sizes.");
182 if (N == 0.0 || !boost::math::isfinite(N)) {
183 throw std::runtime_error(
"Cannot normalize null vector.");
193 return std::accumulate(
m_data.cbegin(),
m_data.cend(), 0.,
194 [](
double sum,
double element) { return sum + element * element; });
201 throw std::runtime_error(
"Vectors have different sizes in dot product.");
211 throw std::runtime_error(
"Cannot find min element of empty vector.");
213 auto it = std::min_element(
m_data.begin(),
m_data.end());
216 throw std::runtime_error(
"Cannot find min element of vector.");
218 return static_cast<size_t>(std::distance(
m_data.begin(), it));
224 throw std::runtime_error(
"Cannot find ax element of empty vector.");
226 auto it = std::max_element(
m_data.begin(),
m_data.end());
229 throw std::runtime_error(
"Cannot find max element of vector.");
231 return static_cast<size_t>(std::distance(
m_data.begin(), it));
237 throw std::runtime_error(
"Cannot find min or max element of empty vector.");
239 auto pit = std::minmax_element(
m_data.begin(),
m_data.end());
240 if (pit.first ==
m_data.end() || pit.second ==
m_data.end()) {
242 throw std::runtime_error(
"Cannot find min or max element of vector.");
244 return std::make_pair(
static_cast<size_t>(std::distance(
m_data.begin(), pit.first)),
245 static_cast<size_t>(std::distance(
m_data.begin(), pit.second)));
252 std::vector<size_t> indices(
size());
253 for (
size_t i = 0; i <
size(); ++i) {
257 std::sort(indices.begin(), indices.end(), [
this](
size_t i,
size_t j) { return this->m_data[i] < m_data[j]; });
259 std::sort(indices.begin(), indices.end(), [
this](
size_t i,
size_t j) { return this->m_data[i] > m_data[j]; });
267 std::vector<double> data(
size());
268 for (
size_t i = 0; i <
size(); ++i) {
269 data[i] =
m_data[indices[i]];
283 std::ios::fmtflags fflags(ostr.flags());
284 ostr << std::scientific << std::setprecision(6);
285 for (
size_t j = 0; j < v.
size(); ++j) {
286 ostr << std::setw(13) << v[j] <<
' ';
double value
The value of the point.
const std::vector< Type > & m_data
A wrapper around Eigen::Vector.
std::vector< double > m_data
Default element storage.
void set(const size_t i, const double value)
Set an element.
size_t indexOfMinElement() const
Get index of the minimum element.
double dot(const EigenVector &v) const
Calculate the dot product.
size_t indexOfMaxElement() const
Get index of the maximum element.
EigenVector & operator+=(const EigenVector &v)
Add a vector.
EigenVector & operator*=(const EigenVector &v)
Multiply by a vector (per element)
EigenVector & operator-=(const EigenVector &v)
Subtract a vector.
double get(const size_t i) const
Get an element.
vec_map_type & mutator()
Get the map of the eigen vector.
void resize(const size_t n)
Resize the vector.
double norm2() const
Get vector norm squared.
std::pair< size_t, size_t > indicesOfMinMaxElements() const
Get indices of both the minimum and maximum elements.
double norm() const
Get vector norm (length)
void sort(const std::vector< size_t > &indices)
Sort this vector in order defined by an index array.
EigenVector_View m_view
The map to the Eigen vector.
EigenVector()
Constructor.
EigenVector & operator=(const EigenVector &v)
Copy assignment operator.
std::vector< double > toStdVector() const
Copy the values to an std vector of doubles.
std::vector< size_t > sortIndices(bool ascending=true) const
Create an index array that would sort this vector.
void normalize()
Normalise this vector.
const vec_map_type inspector() const
Get the const map of the eigen vector.
std::vector< double > & StdVectorRef()
Return a reference to m_data.
size_t size() const
Size of the vector.
MANTID_API_DLL std::ostream & operator<<(std::ostream &, const AlgorithmHistory &)
Prints a text representation.