21#ifndef vtkReservoirSampler_h 
   22#define vtkReservoirSampler_h 
   25#include "vtkCommonMathModule.h" 
   34VTK_ABI_NAMESPACE_BEGIN
 
   39  using SeedType = 
typename std::random_device::result_type;
 
   44template <
typename Integer, 
bool Monotonic = true>
 
   51  const std::vector<Integer>& 
operator()(Integer kk, Integer nn)
 const 
   53    VTK_THREAD_LOCAL 
static std::vector<Integer> data;
 
   63    VTK_THREAD_LOCAL 
static std::vector<Integer> data;
 
   66      throw std::invalid_argument(
"Null arrays are disallowed.");
 
   70      throw std::invalid_argument(
"Array size would overflow integer type.");
 
   77  void GenerateSample(Integer kk, Integer nn, std::vector<Integer>& data)
 const 
   85      throw std::invalid_argument(
 
   86        "You must choose a non-negative number of values from a proper sequence.");
 
   95    for (ii = 0; ii < kk; ++ii)
 
  105    std::uniform_real_distribution<> unitUniform(0., 1.);
 
  106    std::uniform_int_distribution<Integer> randomIndex(0, kk - 1);
 
  107    double w = exp(log(unitUniform(generator)) / kk);
 
  111      double delta = floor(log(unitUniform(generator)) / log(1.0 - w)) + 1.0;
 
  117      Integer intDelta = 
static_cast<Integer
>(delta);
 
  120      if (nn - ii > intDelta)
 
  122        Integer jj = randomIndex(generator);
 
  124        std::cout << 
"      i " << ii << 
" δ " << intDelta << 
" w " << w << 
" → j " << jj << 
"\n";
 
  128        w *= exp(log(unitUniform(generator)) / kk);
 
  139      std::sort(data.begin(), data.end());
 
Abstract superclass for all arrays.
 
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
 
static SeedType RandomSeed()
 
typename std::random_device::result_type SeedType
 
void GenerateSample(Integer kk, Integer nn, std::vector< Integer > &data) const
 
const std::vector< Integer > & operator()(Integer kk, Integer nn) const
Choose kk items from a sequence of (0, nn - 1).
 
const std::vector< Integer > & operator()(Integer kk, vtkAbstractArray *array) const
Choose kk items from a sequence of (0, array->GetNumberOfTuples() - 1).
 
Template defining traits of native types used by VTK.