BayesOpt
indexvector.hpp
Go to the documentation of this file.
1 
2 /*
3 -------------------------------------------------------------------------
4  This file is part of BayesOpt, an efficient C++ library for
5  Bayesian optimization.
6 
7  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
8 
9  BayesOpt is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Affero General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  BayesOpt is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Affero General Public License for more details.
18 
19  You should have received a copy of the GNU Affero General Public License
20  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
21 ------------------------------------------------------------------------
22 */
23 
24 #ifndef __INDEX_VECTOR_HPP__
25 #define __INDEX_VECTOR_HPP__
26 
27 #include <algorithm>
28 
29 namespace bayesopt
30 {
31  namespace utils
32  {
36  class CUnique
37  {
38  private:
39  int current;
40  public:
41  CUnique(int initial = 1) {current=initial-1;}
42  int operator()() {return ++current;}
43  };
44 
50  inline std::vector<int> return_index_vector(size_t n)
51  {
52  CUnique UniqueNumber;
53  std::vector<int> arr(n);
54  generate (arr.begin(), arr.end(), UniqueNumber);
55  return arr;
56  };
57 
64  inline std::vector<int> return_index_vector(int a, size_t n)
65  {
66  CUnique UniqueNumber(a);
67  std::vector<int> arr(n);
68  generate (arr.begin(), arr.end(), UniqueNumber);
69  return arr;
70  };
71 
72 
77  inline void modify_index_vector(std::vector<int>& arr)
78  {
79  CUnique UniqueNumber;
80  generate (arr.begin(), arr.end(), UniqueNumber);
81  };
82 
83  } //namespace utils
84 } //namespace bayesopt
85 
86 #endif
Namespace of the library interface.
Definition: using.dox:1
Simple class to generate sequences of unique numbers.
Definition: indexvector.hpp:36
std::vector< int > return_index_vector(size_t n)
Generates a vector of indexes (1..n)
Definition: indexvector.hpp:50
void modify_index_vector(std::vector< int > &arr)
Modify a vector of indexes (0..n)
Definition: indexvector.hpp:77