shuffle.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <algorithm>
20 #include <cstddef>
21 #include <random>
22 
23 namespace ML {
24 namespace Solver {
25 
26 template <typename math_t>
27 void initShuffle(std::vector<math_t>& rand_indices, std::mt19937& g, math_t random_state = 0)
28 {
29  g.seed((int)random_state);
30  for (std::size_t i = 0; i < rand_indices.size(); ++i)
31  rand_indices[i] = i;
32 }
33 
34 template <typename math_t>
35 void shuffle(std::vector<math_t>& rand_indices, std::mt19937& g)
36 {
37  std::shuffle(rand_indices.begin(), rand_indices.end(), g);
38 }
39 
40 }; // namespace Solver
41 }; // namespace ML
42 // end namespace ML
void shuffle(std::vector< math_t > &rand_indices, std::mt19937 &g)
Definition: shuffle.h:35
void initShuffle(std::vector< math_t > &rand_indices, std::mt19937 &g, math_t random_state=0)
Definition: shuffle.h:27
Definition: dbscan.hpp:30