Changeset 825 for trunk/yat/utility
- Timestamp:
- Mar 19, 2007, 1:46:10 PM (16 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/utility.cc
r737 r825 93 93 94 94 95 std::pair<size_t, size_t> minmax_index(const vector& vec,96 const std::vector<size_t>& subset)97 {98 size_t min_index = subset[0];99 size_t max_index = subset[0];100 for (unsigned int i=1; i<subset.size(); i++)101 if (vec[subset[i]] < vec[min_index])102 min_index = subset[i];103 else if (vec[subset[i]] > vec[max_index])104 max_index = subset[i];105 return std::pair<size_t,size_t>(min_index, max_index);106 }107 108 109 void shuffle(vector& invec)110 {111 vector vec(invec);112 random::DiscreteUniform rnd;113 for (size_t i=0; i<vec.size(); i++){114 size_t index = rnd(vec.size()-i);115 invec[i]=vec(index);116 vec(index)=vec(vec.size()-i-1);117 }118 }119 120 95 121 96 }}} // end of namespace utility, yat and thep -
trunk/yat/utility/utility.h
r737 r825 64 64 bool is_nan(const std::string& s); 65 65 66 /**67 This function returns the indices of the minimum and maximum68 values in the sub-vector (defined by \a subset), storing them in69 imin and imax. When there are several equal minimum or maximum70 elements then the lowest indices are returned. The returned index71 is the index from the complete vector (not the sub-vector)72 73 @return Index corresponding to the smallest and largest value.74 75 @note If \a subset is emtpy, the result is undefined.76 */77 std::pair<size_t,size_t> minmax_index(const vector& vec,78 const std::vector<size_t>& subset);79 80 /**81 Randomly shuffles the elements in vector \a invec82 */83 void shuffle(vector& invec);84 66 85 67 -
trunk/yat/utility/vector.cc
r810 r825 28 28 #include "matrix.h" 29 29 #include "utility.h" 30 #include "yat/random/random.h" 30 31 31 32 #include <cassert> … … 475 476 476 477 477 std::pair<double,double> minmax(const vector& v)478 {479 std::pair<double,double> minmax;480 gsl_vector_minmax(v.gsl_vector_p(), &minmax.first, &minmax.second);481 return minmax;482 }483 484 485 std::pair<size_t,size_t> minmax_index(const vector& v)486 {487 std::pair<size_t,size_t> minmax;488 gsl_vector_minmax_index(v.gsl_vector_p(), &minmax.first, &minmax.second);489 return minmax;490 }491 492 493 478 bool nan(const vector& templat, vector& flag) 494 479 { … … 515 500 516 501 502 void shuffle(vector& invec) 503 { 504 vector vec(invec); 505 random::DiscreteUniform rnd; 506 for (size_t i=0; i<vec.size(); i++){ 507 size_t index = rnd(vec.size()-i); 508 invec[i]=vec(index); 509 vec(index)=vec(vec.size()-i-1); 510 } 511 } 512 513 517 514 void sort(vector& v) 518 515 { -
trunk/yat/utility/vector.h
r811 r825 511 511 512 512 /** 513 \brief Get the minimum and maximim values of the vector.514 515 \return The minimum and maximum values of the vector,516 respectively.517 */518 std::pair<double,double> minmax(const vector&);519 520 /**521 \brief Locate the maximum and minumum element in the vector.522 523 \return The indecies to the element with the minimum and maximum524 values of the vector, respectively.525 526 \note Lower index has precedence.527 */528 std::pair<size_t,size_t> minmax_index(const vector&);529 530 /**531 513 \brief Create a vector \a flag indicating NaN's in another vector 532 514 \a templat. … … 541 523 \return True if the \a templat vector contains at least one NaN. 542 524 */ 543 bool nan(const matrix& templat, matrix& flag);525 bool nan(const vector& templat, vector& flag); 544 526 545 527 /** … … 552 534 553 535 /** 536 Randomly shuffles the elements in vector \a invec 537 */ 538 void shuffle(vector& invec); 539 540 /** 554 541 Sort the elements in the vector. 555 542
Note: See TracChangeset
for help on using the changeset viewer.