extent: add uniform sampler
This commit is contained in:
parent
5dadd8eb38
commit
78dd62283b
20
extent.hpp
20
extent.hpp
@ -21,6 +21,7 @@
|
||||
#include "coord/base.hpp"
|
||||
#include "vector.hpp"
|
||||
#include "point.hpp"
|
||||
#include "random.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@ -165,6 +166,25 @@ namespace util {
|
||||
};
|
||||
|
||||
|
||||
template <size_t S, typename T>
|
||||
util::point<S,T>
|
||||
sample (util::extent<S,T> shape)
|
||||
{
|
||||
return sample (shape, util::random::generator ());
|
||||
}
|
||||
|
||||
|
||||
template <size_t S, typename T, typename GeneratorT>
|
||||
util::point<S,T>
|
||||
sample (util::extent<S,T> shape, GeneratorT &&gen)
|
||||
{
|
||||
util::point<S,T> p;
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
p[i] = util::random::uniform (0, shape[i], gen);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// convenience typedefs
|
||||
template <typename T> using extent2 = extent<2,T>;
|
||||
|
Loading…
Reference in New Issue
Block a user