9#include "MantidKernel/DllConfig.h"
37inline long round(
double x) {
return long(
x + (
x < 0 ? -0.5 : +0.5)); }
46inline double rounddbl(
double r) {
return (r > 0.0) ? std::floor(r + 0.5) : std::ceil(r - 0.5); }
57 double factor = pow(10.0, f - ceil(log10(
fabs(r))));
58 return rounddbl(r * factor) / factor;
70 double m = pow(10.0,
d);
71 return (
int)r + (1.0 /
m) *
rounddbl((r - (
int)r) *
m);
74namespace NestedForLoop {
82inline void SetUp(
const size_t numDims,
size_t *out,
const size_t value = 0) {
84 for (
size_t d = 0;
d < numDims;
d++)
104inline void SetUpIndexMaker(
const size_t numDims,
size_t *out,
const size_t *index_max) {
106 for (
size_t d = 0;
d < numDims;
d++)
109 for (
size_t d = 1;
d < numDims;
d++)
110 out[
d] = out[
d - 1] * index_max[
d - 1];
127 for (
size_t d = 0;
d < numDims;
d++)
128 out +=
index[
d] * index_maker[
d];
145 const size_t *index_max,
size_t *out_indices) {
146 for (
size_t d = 0;
d < numDims;
d++) {
147 out_indices[
d] = (linear_index / index_maker[
d]) % index_max[
d];
165inline bool Increment(
const size_t numDims,
size_t *
index,
size_t *index_max,
size_t *index_min) {
167 while (
d < numDims) {
169 if (++
index[
d] >= index_max[
d]) {
197 while (
d < numDims) {
199 if (++
index[
d] >= index_max[
d]) {
229 size_t *
const out_indices) {
231 size_t nBins = *(numBins + 0);
233 size_t ind = linear_index % nBins;
234 *(out_indices + 0) = ind;
236 size_t rest = linear_index / nBins;
237 for (
size_t d = 1;
d < numDims;
d++) {
238 nBins = *(numBins +
d);
240 *(out_indices +
d) = ind;
256 std::vector<size_t> out_indices;
257 if (!num_bins.empty()) {
258 size_t nBins = num_bins.size();
259 out_indices.resize(nBins);
283inline bool isNeighbourOfSubject(
const size_t ndims,
const size_t neighbour_linear_index,
const size_t *subject_indices,
284 const size_t *num_bins,
const size_t *index_max,
const std::vector<int> &widths) {
285 for (
size_t ind = 0; ind < ndims; ++ind) {
286 size_t neigh_index = (neighbour_linear_index / num_bins[ind]) % index_max[ind];
287 const long double subj =
static_cast<long double>(subject_indices[ind]);
288 const long double neigh =
static_cast<long double>(neigh_index);
289 const long double diff = std::abs(subj - neigh);
290 if (diff > (widths[ind] >> 1))
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
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.
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.
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.
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.
void SetUpIndexMaker(const size_t numDims, size_t *out, const size_t *index_max)
Set up an "index maker" for a nested for loop.
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 (poin...
double rounddbl(double r)
Custom rounding method for a double->double because none is portable in C++ (!)
double roundToDP(double r, int d)
Custom rounding method for a double->double because none is portable in C++ (!)
double roundToSF(double r, int f)
Custom rounding method for a double->double because none is portable in C++ (!)
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...
long round(double x)
Custom rounding method for a double->long because none is portable in C++ (!)
Helper class which provides the Collimation Length for SANS instruments.