12#include "MantidKernel/DllConfig.h"
28namespace VectorHelper {
32std::size_t MANTID_KERNEL_DLL
estimateNumberOfBins(std::vector<double>
const ¶ms,
double const power = -1);
35 const std::vector<double> ¶ms, std::vector<double> &xnew,
const bool resize_xnew =
true,
36 const bool full_bins_only =
false,
const double xMinHint = std::nan(
""),
const double xMaxHint = std::nan(
""),
37 const bool useReverseLogarithmic =
false,
const double power = -1);
42void MANTID_KERNEL_DLL
rebin(std::span<double const> xold, std::span<double const> yold, std::span<double const> eold,
43 std::span<double const> xnew, std::span<double> ynew, std::span<double> enew,
44 bool distribution,
bool addition =
false);
47void MANTID_KERNEL_DLL
rebinHistogram(std::span<double const> xold, std::span<double const> yold,
48 std::span<double const> eold, std::span<double const> xnew,
49 std::span<double> ynew, std::span<double> enew,
bool addition);
52void MANTID_KERNEL_DLL
convertToBinCentre(std::span<double const> bin_edges, std::vector<double> &bin_centres);
55void MANTID_KERNEL_DLL
convertToBinBoundary(std::span<double const> bin_centers, std::vector<double> &bin_edges);
77template <
typename T> std::vector<T>
flattenVector(
const std::vector<std::vector<T>> &v) {
78 std::vector<T> flattened;
80 for (
const auto &subVector : v) {
81 flattened.insert(flattened.end(), subVector.begin(), subVector.end());
87template <
typename NumT>
88MANTID_KERNEL_DLL std::vector<NumT> splitStringIntoVector(std::string listString,
const std::string &separators =
", ");
90MANTID_KERNEL_DLL
int getBinIndex(std::span<double const> bins,
const double value);
95MANTID_KERNEL_DLL
void smoothInRange(std::span<double const> input, std::vector<double> &output,
double avrgInterval,
96 std::span<double const> binBndrs = {},
size_t startIndex = 0,
size_t endIndex = 0,
97 std::vector<double> *
const outBins =
nullptr);
100template <
class T>
struct SumSquares;
110 T total = std::accumulate(
x.cbegin(),
x.cend(),
static_cast<T
>(0),
SumSquares<T>());
116template <
typename T> T
scalar_prod(
const std::vector<T> &v1,
const std::vector<T> &v2) {
117 if (v1.size() != v2.size())
118 throw std::invalid_argument(
" scalar product is defined only for the "
119 "vectors of the equivalent length");
121 for (
size_t i = 0; i < v1.size(); i++)
122 total += v1[i] * v2[i];
128template <
typename T,
typename U>
double scalar_prod(
const std::vector<T> &v1,
const std::vector<U> &v2) {
129 if (v1.size() != v2.size())
130 throw std::invalid_argument(
" scalar product is defined only for the "
131 "vectors of the equivalient length");
133 for (
size_t i = 0; i < v1.size(); i++)
134 total +=
double(v1[i]) * double(v2[i]);
150 std::vector<T> out(
x.size(), 0);
153 for (
size_t i = 0; i <
x.size(); i++)
154 out[i] =
x[i] / length;
163 inline T
operator()(
const T &l,
const T &r)
const {
return sqrt(l * l + r * r); }
190 T
operator()(
const T &l,
const T &r)
const {
return (r * r * l * l); }
201template <
class T>
struct Log {
207 throw std::range_error(
"Attempt to take logarithm of zero or negative number.");
224 if (std::fabs(r) < 1e-12)
234 T
operator()(
const T &
x,
const T &
y)
const {
return static_cast<T
>(0.5) * (
x +
y); }
double value
The value of the point.
std::vector< T > flattenVector(const std::vector< std::vector< T > > &v)
A convenience function to "flatten" the given vector of vectors into a single vector.
MANTID_KERNEL_DLL void smoothInRange(std::span< double const > input, std::vector< double > &output, double avrgInterval, std::span< double const > binBndrs={}, size_t startIndex=0, size_t endIndex=0, std::vector< double > *const outBins=nullptr)
Basic running average of input vector within specified range, considering variable bin-boundaries if ...
std::vector< T > normalizeVector(const std::vector< T > &x)
Normalize a vector of any size to unity, using the sum of the squares of the components.
void MANTID_KERNEL_DLL rebin(std::span< double const > xold, std::span< double const > yold, std::span< double const > eold, std::span< double const > xnew, std::span< double > ynew, std::span< double > enew, bool distribution, bool addition=false)
The input and output ranges are taken as spans so that the size-checked histogram data types,...
std::size_t MANTID_KERNEL_DLL estimateNumberOfBins(std::vector< double > const ¶ms, double const power=-1)
Returns a size_t with the estimated number of bins that would be needed for a rebinning operation.
T lengthVector(const std::vector< T > &x)
Return the length of the vector (in the physical sense), the sqrt of the sum of the squares of the co...
int MANTID_KERNEL_DLL indexOfValueFromCentersNoThrow(std::span< double const > bin_centers, const double value)
Gets the bin of a value from a vector of bin centers and returns -1 if out of range.
MANTID_KERNEL_DLL int getBinIndex(std::span< double const > bins, const double value)
Return the index into a vector of bin boundaries for a particular X value.
void MANTID_KERNEL_DLL rebinHistogram(std::span< double const > xold, std::span< double const > yold, std::span< double const > eold, std::span< double const > xnew, std::span< double > ynew, std::span< double > enew, bool addition)
Rebins histogram data according to a new output X array.
void MANTID_KERNEL_DLL convertToBinBoundary(std::span< double const > bin_centers, std::vector< double > &bin_edges)
Convert an array of bin centers to bin boundary values.
T scalar_prod(const std::vector< T > &v1, const std::vector< T > &v2)
bool MANTID_KERNEL_DLL isConstantValue(std::span< double const > arra)
Assess if all the values in the vector are equal or if there are some different values.
void MANTID_KERNEL_DLL convertToBinCentre(std::span< double const > bin_edges, std::vector< double > &bin_centres)
Convert an array of bin boundaries to bin center values.
void MANTID_KERNEL_DLL validateRebinParameters(std::vector< double > const &, bool const =false)
Validate rebinning parameters, throwing an error if any assumptions are invalidated.
size_t MANTID_KERNEL_DLL indexOfValueFromEdges(std::span< double const > bin_edges, const double value)
Gets the bin of a value from a vector of bin edges.
size_t MANTID_KERNEL_DLL indexOfValueFromCenters(std::span< double const > bin_centers, const double value)
Gets the bin of a value from a vector of bin centers and throws exception if out of range.
std::size_t MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
Helper class which provides the Collimation Length for SANS instruments.
Functor to deal with the increase in the error when adding (or subtracting) a number of counts.
T operator()(const T &r, const T &x) const
adds the square of the left-hand argument to the right hand argument and takes the square root
Divide functor with result reset to 0 if the denominator is null.
T operator()(const T &l, const T &r) const
Returns l/r if r is non-zero, otherwise returns l.
T operator()(const T &x) const
T operator()(const T &x) const
Returns the logarithm of the argument.
A binary functor to compute the simple average of 2 numbers.
T operator()(const T &x, const T &y) const
Return the average of the two arguments.
T operator()(const T &x) const
Returns the square of the argument.
Functor used for computing the sum of the square values of a vector, using the accumulate algorithm.
T operator()(const T &l, const T &r) const
Sums the arguments in quadrature.
Functor to accumulate a sum of squares.
T operator()(const T &r, const T &x) const
Adds the square of the right-hand argument to the left hand one.
Functor giving the product of the squares of the arguments.
T operator()(const T &l, const T &r) const
Multiplies the squares of the arguments.