Mantid
Loading...
Searching...
No Matches
Classes | Functions
Mantid::Kernel::VectorHelper Namespace Reference

Classes

struct  AddVariance
 Functor to deal with the increase in the error when adding (or subtracting) a number of counts. More...
 
struct  DividesNonNull
 Divide functor with result reset to 0 if the denominator is null. More...
 
struct  Log
 Log functor. More...
 
struct  LogNoThrow
 
struct  SimpleAverage
 A binary functor to compute the simple average of 2 numbers. More...
 
struct  Squares
 Square functor. More...
 
struct  SumGaussError
 Functor used for computing the sum of the square values of a vector, using the accumulate algorithm. More...
 
struct  SumSquares
 Functor to accumulate a sum of squares. More...
 
struct  TimesSquares
 Functor giving the product of the squares of the arguments. More...
 

Functions

void MANTID_KERNEL_DLL convertToBinBoundary (const std::vector< double > &bin_centers, std::vector< double > &bin_edges)
 Convert an array of bin centers to bin boundary values. More...
 
void MANTID_KERNEL_DLL convertToBinCentre (const std::vector< double > &bin_edges, std::vector< double > &bin_centres)
 Convert an array of bin boundaries to bin center values. More...
 
int MANTID_KERNEL_DLL createAxisFromRebinParams (const std::vector< double > &params, std::vector< double > &xnew, const bool resize_xnew, const bool full_bins_only, const double xMinHint, const double xMaxHint, const bool useReverseLogarithmic, const double power)
 Creates a new output X array given a 'standard' set of rebinning parameters. More...
 
template<typename T >
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. More...
 
MANTID_KERNEL_DLL int getBinIndex (const std::vector< double > &bins, const double value)
 Return the index into a vector of bin boundaries for a particular X value. More...
 
size_t MANTID_KERNEL_DLL indexOfValueFromCenters (const std::vector< double > &bin_centers, const double value)
 Gets the bin of a value from a vector of bin centers and throws exception if out of range. More...
 
int MANTID_KERNEL_DLL indexOfValueFromCentersNoThrow (const std::vector< double > &bin_centers, const double value)
 Gets the bin of a value from a vector of bin centers and returns -1 if out of range. More...
 
size_t MANTID_KERNEL_DLL indexOfValueFromEdges (const std::vector< double > &bin_edges, const double value)
 Gets the bin of a value from a vector of bin edges. More...
 
bool MANTID_KERNEL_DLL isConstantValue (const std::vector< double > &arra)
 Assess if all the values in the vector are equal or if there are some different values. More...
 
template<typename 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 components. More...
 
template<typename T >
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. More...
 
void MANTID_KERNEL_DLL rebin (const std::vector< double > &xold, const std::vector< double > &yold, const std::vector< double > &eold, const std::vector< double > &xnew, std::vector< double > &ynew, std::vector< double > &enew, bool distribution, bool addition)
 Rebins data according to a new output X array. More...
 
void MANTID_KERNEL_DLL rebinHistogram (const std::vector< double > &xold, const std::vector< double > &yold, const std::vector< double > &eold, const std::vector< double > &xnew, std::vector< double > &ynew, std::vector< double > &enew, bool addition)
 Rebins histogram data according to a new output X array. More...
 
template<typename T >
scalar_prod (const std::vector< T > &v1, const std::vector< T > &v2)
 
template<typename T , typename U >
double scalar_prod (const std::vector< T > &v1, const std::vector< U > &v2)
 
MANTID_KERNEL_DLL void smoothInRange (const std::vector< double > &input, std::vector< double > &output, const double avrgInterval, std::vector< double > const *const binBndrs, size_t startIndex, size_t endIndex, std::vector< double > *const outBins)
 Basic running average of input vector within specified range, considering variable bin-boundaries if such boundaries are provided. More...
 
template<typename NumT >
MANTID_KERNEL_DLL std::vector< NumT > splitStringIntoVector (std::string listString)
 Take a string of comma or space-separated values, and splits it into a vector of doubles. More...
 
template<typename NumT >
std::vector< NumT > splitStringIntoVector (std::string listString)
 Take a string of comma or space-separated values, and splits it into a vector of doubles. More...
 
template DLLExport std::vector< double > splitStringIntoVector< double > (std::string listString)
 
template DLLExport std::vector< float > splitStringIntoVector< float > (std::string listString)
 
template DLLExport std::vector< int32_t > splitStringIntoVector< int32_t > (std::string listString)
 Declare all version of this. More...
 
template DLLExport std::vector< int64_t > splitStringIntoVector< int64_t > (std::string listString)
 
template DLLExport std::vector< size_t > splitStringIntoVector< size_t > (std::string listString)
 
template DLLExport std::vector< std::string > splitStringIntoVector< std::string > (std::string listString)
 

Function Documentation

◆ convertToBinBoundary()

void Mantid::Kernel::VectorHelper::convertToBinBoundary ( const std::vector< double > &  bin_centers,
std::vector< double > &  bin_edges 
)

Convert an array of bin centers to bin boundary values.

Convert the given set of bin centers into bin boundary values.

NOTE: the first and last bin boundaries are calculated so that the first and last bin centers are in the center of the first and last bins, respectively. For a particular set of bin centers, this may not be correct, but it is the best that can be done, lacking any other information. For an empty input vector, an empty output is returned. For an input vector of size 1, i.e., a single bin, there is no information about a proper bin size, so it is set to 1.0.

Parameters
bin_centers:: A vector of values specifying bin centers.
bin_edges:: An output vector of values specifying bin boundaries

Definition at line 404 of file VectorHelper.cpp.

References n.

Referenced by Mantid::API::NumericAxis::createBinBoundaries(), Mantid::DataObjects::Workspace2D::generateHistogram(), Mantid::DataHandling::LoadILLSANS::getVariableTimeBinning(), Mantid::Algorithms::DiscusMultipleScatteringCorrection::integrateQSQ(), and Mantid::Algorithms::DiscusMultipleScatteringCorrection::sampleQWUniform().

◆ convertToBinCentre()

void Mantid::Kernel::VectorHelper::convertToBinCentre ( const std::vector< double > &  bin_edges,
std::vector< double > &  bin_centres 
)

Convert an array of bin boundaries to bin center values.

Convert the given set of bin boundaries into bin centre values.

Parameters
bin_edges:: A vector of values specifying bin boundaries
bin_centres:: An output vector of bin centre values.

Definition at line 372 of file VectorHelper.cpp.

Referenced by Mantid::DataHandling::LoadRKH::binCenter(), Mantid::Algorithms::DiscusMultipleScatteringCorrection::convertWsBothAxesToPoints(), and Mantid::Algorithms::InterpolatingRebin::cubicInterpolation().

◆ createAxisFromRebinParams()

int DLLExport Mantid::Kernel::VectorHelper::createAxisFromRebinParams ( const std::vector< double > &  params,
std::vector< double > &  xnew,
const bool  resize_xnew,
const bool  full_bins_only,
const double  xMinHint,
const double  xMaxHint,
const bool  useReverseLogarithmic,
const double  power 
)

Creates a new output X array given a 'standard' set of rebinning parameters.

Parameters
[in]paramsRebin parameters input [x_1, delta_1,x_2, ... ,x_n-1,delta_n-1,x_n]
[out]xnewThe newly created axis resulting from the input params
[in]resize_xnewIf false then the xnew vector is NOT resized. Useful if the number of bins needs determining. (Default=True)
[in]full_bins_onlyIf true, bins of the size less than the current step are not included. (Default=True)
[in]xMinHintx_1 if params contains only delta_1.
[in]xMaxHintx_2 if params contains only delta_1.
[in]useReverseLogarithmicwheter or not to use reverse logarithmic for bins
[in]powerthe power in case of inverse power sum. Must be between 0 and 1 or is ignored.
Returns
The number of bin boundaries in the new axis

Definition at line 34 of file VectorHelper.cpp.

References fabs, and tmp.

Referenced by Mantid::Algorithms::Q1DWeighted::bootstrap(), Mantid::Algorithms::MergeRuns::checkRebinning(), Mantid::DataHandling::CreateSimulationWorkspace::createBinBoundaries(), Mantid::Algorithms::SumEventsByLogValue::createBinnedOutput(), Mantid::Algorithms::Bin2DPowderDiffraction::createOutputWorkspace(), Mantid::Algorithms::Rebin2D::createOutputWorkspace(), WorkspaceCreationHelper::createRebinnedOutputWorkspace(), Mantid::Algorithms::ResampleX::determineBinning(), Mantid::Algorithms::InterpolatingRebin::exec(), Mantid::Algorithms::Rebin::exec(), Mantid::Algorithms::RebinByTimeBase::exec(), Mantid::DataObjects::ReflectometryTransform::executeNormPoly(), Mantid::Algorithms::SofQW::setUpOutputWorkspace(), and Mantid::Algorithms::Q1D2::setUpOutputWorkspace().

◆ flattenVector()

template<typename T >
std::vector< T > Mantid::Kernel::VectorHelper::flattenVector ( const std::vector< std::vector< T > > &  v)

A convenience function to "flatten" the given vector of vectors into a single vector.

For example:

((1), (2, 3), (4), (5, 6)) becomes (1, 2, 3, 4, 5, 6)

Parameters
v:: the vector of vectors to be flattened.
Returns
a single vector containing all elements in v.

Definition at line 69 of file VectorHelper.h.

Referenced by Mantid::MDAlgorithms::LoadDNSSCD::exec(), Mantid::MDAlgorithms::MergeMDFiles::exec(), MantidQt::API::FindFilesWorker::getFilesFromAlgorithm(), and Mantid::API::MultipleFileProperty::setValueAsMultipleFiles().

◆ getBinIndex()

int Mantid::Kernel::VectorHelper::getBinIndex ( const std::vector< double > &  bins,
const double  value 
)

Return the index into a vector of bin boundaries for a particular X value.

The index returned is the one for the left edge of the bin. If beyond the range of the vector, it will return either 0 or bins.size()-2.

Parameters
binsA reference to the set of bin boundaries to search. It is assumed that they are monotonically increasing values and this is NOT checked
valueThe value whose boundaries should be found

Definition at line 583 of file VectorHelper.cpp.

References value.

Referenced by Mantid::Algorithms::SumEventsByLogValue::createBinnedOutput(), Mantid::Algorithms::StripVanadiumPeaks::exec(), Mantid::Crystal::PeakIntegration::exec(), Mantid::API::Run::histogramBinBoundaries(), Mantid::Crystal::CentroidPeaks::integrate(), and Mantid::Algorithms::GetAllEi::peakGuess().

◆ indexOfValueFromCenters()

size_t Mantid::Kernel::VectorHelper::indexOfValueFromCenters ( const std::vector< double > &  bin_centers,
const double  value 
)

Gets the bin of a value from a vector of bin centers and throws exception if out of range.

Finds the bin index of a value from the vector of bin centers without converting the whole array to bin edges.

Assumes the vector is already sorted ascending.

Parameters
bin_centers: vector of bin centers
value: input value
Returns
: the bin index of the value
Exceptions
std::out_of_range: if vector is empty or value is out of it's range (in bin edge representation)

Definition at line 442 of file VectorHelper.cpp.

References index, indexOfValueFromCentersNoThrow(), and value.

Referenced by Mantid::API::MatrixWorkspace::getSignalAtCoord(), Mantid::API::NumericAxis::indexOfValue(), Mantid::API::TextAxis::indexOfValue(), and Mantid::Algorithms::SumOverlappingTubes::performBinning().

◆ indexOfValueFromCentersNoThrow()

int Mantid::Kernel::VectorHelper::indexOfValueFromCentersNoThrow ( const std::vector< double > &  bin_centers,
const double  value 
)

Gets the bin of a value from a vector of bin centers and returns -1 if out of range.

Definition at line 450 of file VectorHelper.cpp.

References n, and value.

Referenced by indexOfValueFromCenters(), Mantid::Algorithms::DiscusMultipleScatteringCorrection::Interpolate2D(), and Mantid::Algorithms::DiscusMultipleScatteringCorrection::sampleQWUniform().

◆ indexOfValueFromEdges()

size_t Mantid::Kernel::VectorHelper::indexOfValueFromEdges ( const std::vector< double > &  bin_edges,
const double  value 
)

Gets the bin of a value from a vector of bin edges.

Finds the bin index of a value from the vector of bin edges.

Assumes the vector is already sorted ascending.

Parameters
bin_edges: vector of bin centers
value: input value
Returns
: the bin index of the value
Exceptions
std::out_of_range: if vector is empty, contains one element, or value is out of it's range

Definition at line 490 of file VectorHelper.cpp.

References value.

Referenced by Mantid::Algorithms::Q1DWeighted::calculate(), Mantid::API::MatrixWorkspace::getSignalAtCoord(), Mantid::API::BinEdgeAxis::indexOfValue(), and Mantid::API::SpectraAxis::indexOfValue().

◆ isConstantValue()

bool Mantid::Kernel::VectorHelper::isConstantValue ( const std::vector< double > &  arra)

Assess if all the values in the vector are equal or if there are some different values.

Parameters
[in]arrathe vector to examine

Definition at line 518 of file VectorHelper.cpp.

Referenced by Mantid::Algorithms::InterpolatingRebin::cubicInterpolation().

◆ lengthVector()

template<typename T >
T Mantid::Kernel::VectorHelper::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 components.

Parameters
x:: input vector, x should be float or double.
Returns
length of the vector

Definition at line 97 of file VectorHelper.h.

References Mantid::Geometry::x.

Referenced by normalizeVector().

◆ normalizeVector()

template<typename T >
std::vector< T > Mantid::Kernel::VectorHelper::normalizeVector ( const std::vector< T > &  x)

Normalize a vector of any size to unity, using the sum of the squares of the components.

Parameters
x:: input vector, x should be float or double. Length 1+
Returns
the vector, normalized to 1.

Definition at line 136 of file VectorHelper.h.

References lengthVector(), and Mantid::Geometry::x.

◆ rebin()

void Mantid::Kernel::VectorHelper::rebin ( const std::vector< double > &  xold,
const std::vector< double > &  yold,
const std::vector< double > &  eold,
const std::vector< double > &  xnew,
std::vector< double > &  ynew,
std::vector< double > &  enew,
bool  distribution,
bool  addition 
)

Rebins data according to a new output X array.

Parameters
[in]xoldOld X array of data.
[in]yoldOld Y array of data. Must be 1 element shorter than xold.
[in]eoldOld error array of data. Must be same length as yold.
[in]xnewX array of data to rebin to.
[out]ynewRebinned data. Must be 1 element shorter than xnew.
[out]enewRebinned errors. Must be same length as ynew.
[in]distributionFlag defining if distribution data (true) or not (false).
[in]additionIf true, rebinned values are added to the existing ynew/enew vectors. NOTE THAT, IN THIS CASE THE RESULTING enew WILL BE THE SQUARED ERRORS AND THE ynew WILL NOT HAVE THE BIN WIDTH DIVISION PUT IN!
Exceptions
runtime_errorThrown if algorithm cannot execute.
invalid_argumentThrown if input to function is incorrect.

Definition at line 163 of file VectorHelper.cpp.

References Mantid::Kernel::delta.

Referenced by Mantid::Algorithms::ApplyFloodWorkspace::exec(), Mantid::Algorithms::CrossCorrelate::exec(), Mantid::Algorithms::DiffractionFocussing2::exec(), Mantid::Algorithms::ResampleX::exec(), Mantid::DataObjects::Workspace2D::generateHistogram(), Mantid::Algorithms::VesuvioL1ThetaResolution::processDistribution(), and Mantid::Algorithms::MergeRuns::rebinInput().

◆ rebinHistogram()

void Mantid::Kernel::VectorHelper::rebinHistogram ( const std::vector< double > &  xold,
const std::vector< double > &  yold,
const std::vector< double > &  eold,
const std::vector< double > &  xnew,
std::vector< double > &  ynew,
std::vector< double > &  enew,
bool  addition 
)

Rebins histogram data according to a new output X array.

Should be faster than previous one.

Author
Laurent Chapon 10/03/2009
Parameters
[in]xoldOld X array of data.
[in]yoldOld Y array of data. Must be 1 element shorter than xold.
[in]eoldOld error array of data. Must be same length as yold.
[in]xnewX array of data to rebin to.
[out]ynewRebinned data. Must be 1 element shorter than xnew.
[out]enewRebinned errors. Must be same length as ynew.
[in]additionIf true, rebinned values are added to the existing ynew/enew vectors. NOTE THAT, IN THIS CASE THE RESULTING enew WILL BE THE SQUARED ERRORS!
Exceptions
runtime_errorThrown if vector sizes are inconsistent

Definition at line 280 of file VectorHelper.cpp.

Referenced by Mantid::Algorithms::DiffractionFocussing2::exec(), and Mantid::Algorithms::NormaliseToMonitor::normaliseBinByBin().

◆ scalar_prod() [1/2]

template<typename T >
T Mantid::Kernel::VectorHelper::scalar_prod ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)

Definition at line 106 of file VectorHelper.h.

◆ scalar_prod() [2/2]

template<typename T , typename U >
double Mantid::Kernel::VectorHelper::scalar_prod ( const std::vector< T > &  v1,
const std::vector< U > &  v2 
)

Definition at line 118 of file VectorHelper.h.

◆ smoothInRange()

void Mantid::Kernel::VectorHelper::smoothInRange ( const std::vector< double > &  input,
std::vector< double > &  output,
const double  avrgInterval,
std::vector< double > const *const  binBndrs,
size_t  startIndex,
size_t  endIndex,
std::vector< double > *const  outBins 
)

Basic running average of input vector within specified range, considering variable bin-boundaries if such boundaries are provided.

The algorithm performs trapezium integration, so some peak shift related to the first derivative of the integrated function can be observed.

Parameters
input,:input vector to smooth
output,:resulting vector (can not coincide with input)
avrgInterval,:the interval to average function in. the function is averaged within +-0.5*avrgInterval
binBndrs:: pointer to the vector, containing bin boundaries. If provided, its length has to be input.size()+1, if not, equal size bins of size 1 are assumed, so avrgInterval becomes the number of points to average over. Bin boundaries array have to increase and can not contain equal boundaries.
startIndex,:if provided, its start index to run averaging from. if not, averaging starts from the index 0
endIndex:: final index to run average to, if provided. If not, or higher then number of elements in input array, averaging is performed to the end point of the input array
outBins:: if present, pointer to a vector to return bin boundaries for output array.

Definition at line 716 of file VectorHelper.cpp.

Referenced by Mantid::Algorithms::GetAllEi::peakGuess().

◆ splitStringIntoVector() [1/2]

template<typename NumT >
MANTID_KERNEL_DLL std::vector< NumT > Mantid::Kernel::VectorHelper::splitStringIntoVector ( std::string  listString)

Take a string of comma or space-separated values, and splits it into a vector of doubles.

Parameters
listString:: a string like "0.0 1.2" or "2.4, 5.67, 88"
Returns
a vector of doubles
Exceptions
anerror if there was a string that could not convert to a double.

Definition at line 554 of file VectorHelper.cpp.

References splitStringIntoVector().

Referenced by splitStringIntoVector().

◆ splitStringIntoVector() [2/2]

template<typename NumT >
std::vector< NumT > Mantid::Kernel::VectorHelper::splitStringIntoVector ( std::string  listString)

Take a string of comma or space-separated values, and splits it into a vector of doubles.

Parameters
listString:: a string like "0.0 1.2" or "2.4, 5.67, 88"
Returns
a vector of doubles
Exceptions
anerror if there was a string that could not convert to a double.

Definition at line 554 of file VectorHelper.cpp.

References splitStringIntoVector().

Referenced by splitStringIntoVector().

◆ splitStringIntoVector< double >()

template DLLExport std::vector< double > Mantid::Kernel::VectorHelper::splitStringIntoVector< double > ( std::string  listString)

◆ splitStringIntoVector< float >()

template DLLExport std::vector< float > Mantid::Kernel::VectorHelper::splitStringIntoVector< float > ( std::string  listString)

◆ splitStringIntoVector< int32_t >()

template DLLExport std::vector< int32_t > Mantid::Kernel::VectorHelper::splitStringIntoVector< int32_t > ( std::string  listString)

Declare all version of this.

◆ splitStringIntoVector< int64_t >()

template DLLExport std::vector< int64_t > Mantid::Kernel::VectorHelper::splitStringIntoVector< int64_t > ( std::string  listString)

◆ splitStringIntoVector< size_t >()

template DLLExport std::vector< size_t > Mantid::Kernel::VectorHelper::splitStringIntoVector< size_t > ( std::string  listString)

◆ splitStringIntoVector< std::string >()

template DLLExport std::vector< std::string > Mantid::Kernel::VectorHelper::splitStringIntoVector< std::string > ( std::string  listString)