forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NDRandomNumberGenerator.cpp
51 lines (47 loc) · 1.57 KB
/
NDRandomNumberGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
//
// Includes
//
#include "MantidKernel/NDRandomNumberGenerator.h"
#include <cassert>
namespace Mantid {
namespace Kernel {
/**
* Construct an object
*/
NDRandomNumberGenerator::NDRandomNumberGenerator(const unsigned int ndims) : m_ndims(ndims), m_nextPoint(ndims, 0.0) {}
/**
* Generate the next set of values that form a point in ND space
* @returns A vector containing the ND random numbers
*/
const std::vector<double> &NDRandomNumberGenerator::nextPoint() {
this->generateNextPoint();
return m_nextPoint;
}
/**
* Cache a value for a given dimension index, i.e. 0->ND-1
* @param index :: An index for the dimension of the value generated
* @param value :: value to be cached
*
*/
void NDRandomNumberGenerator::cacheGeneratedValue(const size_t index, const double value) {
assert(index < m_ndims);
m_nextPoint[index] = value;
}
/**
* Cache the next point. Should be called by the concrete implementation at the
* end of generateNextPoint
* Avoids returning the vectors by value and copying.
* @param nextPoint :: A vector containing the new set of points
*/
void NDRandomNumberGenerator::cacheNextPoint(const std::vector<double> &nextPoint) {
assert(nextPoint.size() == m_ndims);
m_nextPoint = nextPoint;
}
} // namespace Kernel
} // namespace Mantid