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

Functions

void GetIndicesFromLinearIndex (const size_t numDims, const size_t linear_index, const size_t *index_maker, const size_t *index_max, size_t *out_indices)
 Set up a nested for loop by creating an array of counters. More...
 
size_t GetLinearIndex (const size_t numDims, size_t *index, size_t *index_maker)
 Return a linear index from dimensional indices of a nested for loop. More...
 
bool Increment (const size_t numDims, size_t *index, size_t *index_max)
 Utility function for performing arbitrarily nested for loops in a serial way. More...
 
bool Increment (const size_t numDims, size_t *index, size_t *index_max, size_t *index_min)
 Utility function for performing arbitrarily nested for loops in a serial way. More...
 
void SetUp (const size_t numDims, size_t *out, const size_t value=0)
 Set up a nested for loop by setting an array of counters. More...
 
void SetUpIndexMaker (const size_t numDims, size_t *out, const size_t *index_max)
 Set up an "index maker" for a nested for loop. More...
 

Function Documentation

◆ GetIndicesFromLinearIndex()

void Mantid::Kernel::Utils::NestedForLoop::GetIndicesFromLinearIndex ( const size_t  numDims,
const size_t  linear_index,
const size_t *  index_maker,
const size_t *  index_max,
size_t *  out_indices 
)
inline

Set up a nested for loop by creating an array of counters.

Parameters
numDims:: how many levels of nesting do the for loops have?
linear_index:: linear index into the nested for loop.
index_maker:: an array[numDims], result of SetUpIndexMaker()
index_max:: an array[numDims] of the maximum value (exclusive) of the index in each dimension. The minimum must be 0 in each dimension for the algorithm to work
[out]out_indices:: an array, sized numDims, which will be filled with the index for each dimension, given the linear index

Definition at line 144 of file Utils.h.

References Mantid::Geometry::d.

Referenced by Mantid::DataObjects::MDHistoWorkspaceIterator::findNeighbourIndexesByWidth(), Mantid::DataObjects::MDHistoWorkspaceIterator::findNeighbourIndexesByWidth1D(), Mantid::DataObjects::MDHistoWorkspaceIterator::findNeighbourIndexesFaceTouching(), Mantid::DataObjects::MDHistoWorkspaceIterator::getBoxExtents(), Mantid::DataObjects::MDHistoWorkspaceIterator::getCenter(), Mantid::DataObjects::MDHistoWorkspace::getCenter(), Mantid::DataObjects::MDHistoWorkspace::getVertexesArray(), and Mantid::DataObjects::MDHistoWorkspaceIterator::init().

◆ GetLinearIndex()

size_t Mantid::Kernel::Utils::NestedForLoop::GetLinearIndex ( const size_t  numDims,
size_t *  index,
size_t *  index_maker 
)
inline

Return a linear index from dimensional indices of a nested for loop.

linear_index = index_maker[0] * index[0] + index_maker[1] * index[1] + ...

The lowest dimension index (0) will vary the slowest.

Parameters
numDims:: how many levels of nesting do the for loops have?
index:: an array[numDims] of the counter index in each dimension.
index_maker:: result of SetUpIndexMaker()
Returns
the linear index into the array

Definition at line 125 of file Utils.h.

References Mantid::Geometry::d, and index.

Referenced by Mantid::DataObjects::MDHistoWorkspaceIterator::jumpToNearest().

◆ Increment() [1/2]

bool Mantid::Kernel::Utils::NestedForLoop::Increment ( const size_t  numDims,
size_t *  index,
size_t *  index_max 
)
inline

Utility function for performing arbitrarily nested for loops in a serial way.

This version assumes that the minimum in each dimension is 0.

Parameters
numDims:: the number of dimensions (levels of nesting) to loop over
index:: an array[numDims] of the counter index in each dimension.
index_max:: an array[numDims] of the maximum value (exclusive) of the index in each dimension
Returns
true if the end of the loop was reached; false otherwise.

Definition at line 195 of file Utils.h.

References Mantid::Geometry::d, and index.

◆ Increment() [2/2]

bool Mantid::Kernel::Utils::NestedForLoop::Increment ( const size_t  numDims,
size_t *  index,
size_t *  index_max,
size_t *  index_min 
)
inline

Utility function for performing arbitrarily nested for loops in a serial way.

Parameters
numDims:: the number of dimensions (levels of nesting) to loop over
index:: an array[numDims] of the current counter index in each dimension. The index at the lowest dimension will be incremented, carrying over to higher dimensions.
index_max:: an array[numDims] of the maximum value (exclusive) of the index in each dimension
index_min:: an array[numDims] of the minimum value of the index in each dimension.
Returns
true if the end of the loop was reached; false otherwise.

Definition at line 165 of file Utils.h.

References Mantid::Geometry::d, and index.

Referenced by Mantid::DataObjects::MDEventsTestHelper::feedMDBox(), and Mantid::DataObjects::MDHistoWorkspaceIterator::next().

◆ SetUp()

void Mantid::Kernel::Utils::NestedForLoop::SetUp ( const size_t  numDims,
size_t *  out,
const size_t  value = 0 
)
inline

Set up a nested for loop by setting an array of counters.

Parameters
numDims:: how many levels of nesting do the for loops have?
out:: a size-numDims array that will be modified
value:: fill the array to this.

Definition at line 82 of file Utils.h.

References Mantid::Geometry::d, and value.

Referenced by Mantid::DataObjects::MDEventsTestHelper::feedMDBox(), and Mantid::DataObjects::MDHistoWorkspaceIterator::init().

◆ SetUpIndexMaker()

void Mantid::Kernel::Utils::NestedForLoop::SetUpIndexMaker ( const size_t  numDims,
size_t *  out,
const size_t *  index_max 
)
inline

Set up an "index maker" for a nested for loop.

Makes an array of size [numDims] that is used to make a linearized index out of dimensional indices. If the output is "out" and the array of indices is "index": linear_index = out[0] * index[0] + out[1] * index[1] + ...

The lowest dimension index (0) will vary the slowest.

Parameters
numDims:: how many levels of nesting do the for loops have?
out:: a size-numDims array that will be modified
index_max:: an array[numDims] of the maximum value (exclusive) of the index in each dimension. The minimum must be 0 in each dimension for the algorithm to work

Definition at line 104 of file Utils.h.

References Mantid::Geometry::d.

Referenced by Mantid::MDAlgorithms::ReplicateMD::exec(), Mantid::DataObjects::MDHistoWorkspaceIterator::init(), and Mantid::DataObjects::MDHistoWorkspace::initVertexesArray().