31 template <
typename T, u
int32 DIM>
33 const uint32 num_samples,
36 const T inv = T(1.0) / T(num_samples);
38 for (uint32 i = 0; i < num_samples; ++i)
40 for (uint32 d = 0; d < DIM; ++d)
41 samples[i][d] = (T(i) + m_random.next()) * inv;
44 for (uint32 d = 0; d < DIM; ++d)
46 for (uint32 i = 0; i < num_samples; i++)
48 const float r = m_random.next();
49 const uint32 j = min(uint32(
float(r) * (num_samples - i)) + i, num_samples - 1u);
50 std::swap(samples[i][d], samples[j][d]);
56 template <
bool SOA,
typename T>
58 const uint32 num_samples,
59 const uint32 num_dims,
62 const T inv = T(1.0) / T(num_samples);
64 for (uint32 i = 0; i < num_samples; ++i)
66 for (uint32 d = 0; d < num_dims; ++d)
67 samples[SOA ? i + d*num_samples : i * num_dims + d] = (T(i) + m_random.next()) * inv;
70 for (uint32 d = 0; d < num_dims; ++d)
72 for (uint32 i = 0; i < num_samples; i++)
74 const float r = m_random.next();
75 const uint32 j = min(uint32(
float(r) * (num_samples - i)) + i, num_samples - 1u);
76 std::swap(samples[SOA ? i + d*num_samples : i * num_dims + d], samples[SOA ? j + d*num_samples : j * num_dims + d]);
void sample(const uint32 n_samples, Vector< T, DIM > *samples)
Definition: latin_hypercube_inline.h:32
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38