Mantid
Loading...
Searching...
No Matches
Namespaces | Functions
Mantid::Kernel::Utils Namespace Reference

Utils: General-purpose utility functions that do not belong anywhere else. More...

Namespaces

namespace  NestedForLoop
 

Functions

std::vector< size_t > getIndicesFromLinearIndex (const size_t linear_index, const std::vector< size_t > &num_bins)
 Convert an linear index in nDim workspace into vector of loop indexes of nDim depth loop. More...
 
void getIndicesFromLinearIndex (const size_t linear_index, size_t const *const numBins, const size_t numDims, size_t *const out_indices)
 Convert an linear index in nDim workspace into vector of loop indexes of nDim depth loop Unsafe (pointers) version, used by safe vectors version. More...
 
bool isNeighbourOfSubject (const size_t ndims, const size_t neighbour_linear_index, const size_t *subject_indices, const size_t *num_bins, const size_t *index_max, const std::vector< int > &widths)
 Determine, using an any-vertex touching type approach, whether the neighbour linear index corresponds to a true neighbour of the subject, which is already decomposed into it's constituent dimension indices. More...
 
long round (double x)
 Custom rounding method for a double->long because none is portable in C++ (!) More...
 
double rounddbl (double r)
 Custom rounding method for a double->double because none is portable in C++ (!) More...
 
double roundToDP (double r, int d)
 Custom rounding method for a double->double because none is portable in C++ (!) More...
 
double roundToSF (double r, int f)
 Custom rounding method for a double->double because none is portable in C++ (!) More...
 

Detailed Description

Utils: General-purpose utility functions that do not belong anywhere else.

NOTE! There are other places to put specific functions:

VectorHelper.h Strings.h Statistics.h Memory.h

Author
Janik Zikovsky
Date
2011-03-29 14:36:20.460710

Function Documentation

◆ getIndicesFromLinearIndex() [1/2]

std::vector< size_t > Mantid::Kernel::Utils::getIndicesFromLinearIndex ( const size_t  linear_index,
const std::vector< size_t > &  num_bins 
)
inline

Convert an linear index in nDim workspace into vector of loop indexes of nDim depth loop.

Parameters
linear_index:: linear index into the nested for loop.
num_bins:: a vector of [numDims] size, where numDims is the loop depth and each element equal to number of bins in the correspondent dimension
Returns
:: a vector, sized numDims, which will be filled with the index for each dimension, given the linear index

Definition at line 255 of file Utils.h.

References getIndicesFromLinearIndex().

◆ getIndicesFromLinearIndex() [2/2]

void Mantid::Kernel::Utils::getIndicesFromLinearIndex ( const size_t  linear_index,
size_t const *const  numBins,
const size_t  numDims,
size_t *const  out_indices 
)
inline

Convert an linear index in nDim workspace into vector of loop indexes of nDim depth loop Unsafe (pointers) version, used by safe vectors version.

Parameters
linear_index:: linear index into the nested for loop.
numBins:: an array[numDims], with number of bins in each dimension
numDims:: how many levels of nesting do the for loops have and the size of the numBins array above
[out]out_indices:: an array, sized numDims, which will be filled with the index for each dimension, given the linear index

Definition at line 228 of file Utils.h.

References Mantid::Geometry::d.

Referenced by Mantid::DataObjects::FakeMD::addFakeRegularData(), and getIndicesFromLinearIndex().

◆ isNeighbourOfSubject()

bool Mantid::Kernel::Utils::isNeighbourOfSubject ( const size_t  ndims,
const size_t  neighbour_linear_index,
const size_t *  subject_indices,
const size_t *  num_bins,
const size_t *  index_max,
const std::vector< int > &  widths 
)
inline

Determine, using an any-vertex touching type approach, whether the neighbour linear index corresponds to a true neighbour of the subject, which is already decomposed into it's constituent dimension indices.

subject is already expressed in it's constituent indices for speed.

The approach used here is to determine if a dimension index differ by any more than 1 in any dimension. If it does, then the neighbour does not represent a valid neighbour of the subject.

Parameters
ndims
neighbour_linear_index
subject_indices
num_bins
index_max
widths: width in pixels per dimension
Returns
True if the are neighbours, otherwise false.

Definition at line 283 of file Utils.h.

Referenced by Mantid::DataObjects::MDHistoWorkspaceIterator::findNeighbourIndexesByWidth(), Mantid::DataObjects::MDHistoWorkspaceIterator::findNeighbourIndexesByWidth1D(), and Mantid::DataObjects::MDHistoWorkspaceIterator::findNeighbourIndexesFaceTouching().

◆ round()

long Mantid::Kernel::Utils::round ( double  x)
inline

Custom rounding method for a double->long because none is portable in C++ (!)

Parameters
x:: floating point value to round
Returns
closest integer as a long (positive or negative)

Definition at line 37 of file Utils.h.

References Mantid::Geometry::x.

Referenced by Mantid::Crystal::SaveHKL::exec(), Mantid::Crystal::SaveIsawPeaks::exec(), Mantid::Crystal::SaveLauenorm::exec(), Mantid::MDAlgorithms::IntegratePeaksMD::integrate(), and Mantid::MDAlgorithms::IntegratePeaksMD2::integrate().

◆ rounddbl()

double Mantid::Kernel::Utils::rounddbl ( double  r)
inline

Custom rounding method for a double->double because none is portable in C++ (!)

Parameters
r:: floating point value to round
Returns
closest integer as a double (positive or negative)

Definition at line 46 of file Utils.h.

Referenced by roundToDP(), and roundToSF().

◆ roundToDP()

double Mantid::Kernel::Utils::roundToDP ( double  r,
int  d 
)
inline

Custom rounding method for a double->double because none is portable in C++ (!)

Parameters
r:: floating point value to round
d:: number of digits after decimal point to preserve
Returns
r rounded to d decimal places

Definition at line 69 of file Utils.h.

References Mantid::Geometry::d, Mantid::Geometry::m, and rounddbl().

◆ roundToSF()

double Mantid::Kernel::Utils::roundToSF ( double  r,
int  f 
)
inline

Custom rounding method for a double->double because none is portable in C++ (!)

Parameters
r:: floating point value to round
f:: number of significant figures to preserve
Returns
r rounded to f significant figures

Definition at line 56 of file Utils.h.

References fabs, and rounddbl().