Changeset 259
- Timestamp:
- Mar 4, 2005, 2:09:55 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gslapi_utility.cc
r257 r259 4 4 #include <utility> 5 5 6 #include "random_singleton.h" 6 7 #include "vector.h" 7 8 … … 26 27 } 27 28 29 30 31 void shuffle(vector& invec) 32 { 33 vector vec(invec); 34 theplu::cpptools::random_singleton* 35 rnd=theplu::cpptools::random_singleton::get_instance(); 36 for (size_t i=0; i<vec.size(); i++){ 37 size_t index = rnd->get_uniform_int(vec.size()-i); 38 invec[i]=vec(index); 39 vec(index)=vec(vec.size()-i-1); 40 } 41 } 42 28 43 }} // of namespace gslapi and namespace thep -
trunk/src/gslapi_utility.h
r257 r259 34 34 const std::vector<size_t>& subset); 35 35 36 /// 37 /// Randomly shuffles the elements in vector \a invec 38 /// 39 void shuffle(vector& invec); 40 36 41 }} // of namespace gslapi and namespace theplu 37 42 -
trunk/src/vector.cc
r257 r259 2 2 3 3 #include "vector.h" 4 #include "random_singleton.h"5 4 6 5 #include <iostream> … … 170 169 171 170 172 void vector::shuffle(void) const173 {174 vector vec(*this);175 theplu::cpptools::random_singleton*176 rnd=theplu::cpptools::random_singleton::get_instance();177 for (size_t i=0; i<vec.size(); i++){178 size_t index = rnd->get_uniform_int(vec.size()-i);179 gsl_vector_set(v_,i,vec(index));180 vec(index)=vec(vec.size()-i-1);181 }182 }183 184 171 double vector::sum(void) const 185 172 { -
trunk/src/vector.h
r257 r259 243 243 244 244 /// 245 /// Randomly shuffles the elements in vector @return resulting246 /// vector247 ///248 void vector::shuffle(void) const;249 250 ///251 245 /// @return the number of elements in the vector. 252 246 /// -
trunk/test/test_vector.cc
r257 r259 2 2 3 3 #include "vector.h" 4 #include "gslapi_utility.h" 4 5 5 6 int main(const int argc,const char* argv[]) … … 13 14 // checking that shuffle works 14 15 double sum_before = vec.sum(); 15 vec.shuffle();16 shuffle(vec); 16 17 double sum_after = vec.sum(); 17 18 if (sum_after != sum_before)
Note: See TracChangeset
for help on using the changeset viewer.