TTK
Loading...
Searching...
No Matches
InitDictRandomly.cpp
Go to the documentation of this file.
1#include <InitDictRandomly.h>
2#include <Shuffle.h>
3
4#include <numeric>
5#include <random>
6
7using namespace ttk;
8
9void InitRandomDict::execute(std::vector<ttk::DiagramType> &DictDiagrams,
10 const std::vector<ttk::DiagramType> &datas,
11 const int nbAtom,
12 const int seed) {
13 int nDiags = datas.size();
14 DictDiagrams.resize(nbAtom);
15 std::vector<int> indices(nDiags);
16 std::iota(indices.begin(), indices.end(), 0);
17 std::mt19937 random_engine{};
18 random_engine.seed(seed);
19 ttk::shuffle(indices, random_engine);
20 for(int i = 0; i < nbAtom; ++i) {
21 const auto &atom = datas[indices[i]];
22 DictDiagrams[i] = atom;
23 }
24}
void execute(std::vector< ttk::DiagramType > &DictDiagrams, const std::vector< ttk::DiagramType > &datas, const int nbAtoms, const int seed)
TTK base package defining the standard types.
void shuffle(std::vector< T > &toShuffle, U &&rng)
Platform-independent alternative to std::shuffle implementing the Fisher-Yates shuffle algorithm.
Definition Shuffle.h:13