Changeset 825 for trunk/yat/utility


Ignore:
Timestamp:
Mar 19, 2007, 1:46:10 PM (15 years ago)
Author:
Peter
Message:

removed minmax functions and moved shuffle into vector.*

Location:
trunk/yat/utility
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/utility.cc

    r737 r825  
    9393
    9494
    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 
    12095
    12196}}} // end of namespace utility, yat and thep
  • trunk/yat/utility/utility.h

    r737 r825  
    6464  bool is_nan(const std::string& s);
    6565
    66   /**
    67      This function returns the indices of the minimum and maximum
    68      values in the sub-vector (defined by \a subset), storing them in
    69      imin and imax. When there are several equal minimum or maximum
    70      elements then the lowest indices are returned. The returned index
    71      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 invec
    82   */
    83   void shuffle(vector& invec);
    8466
    8567
  • trunk/yat/utility/vector.cc

    r810 r825  
    2828#include "matrix.h"
    2929#include "utility.h"
     30#include "yat/random/random.h"
    3031
    3132#include <cassert>
     
    475476
    476477
    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 
    493478  bool nan(const vector& templat, vector& flag)
    494479  {
     
    515500
    516501
     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
    517514  void sort(vector& v)
    518515  {
  • trunk/yat/utility/vector.h

    r811 r825  
    511511
    512512  /**
    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 maximum
    524      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   /**
    531513     \brief Create a vector \a flag indicating NaN's in another vector
    532514     \a templat.
     
    541523     \return True if the \a templat vector contains at least one NaN.
    542524  */
    543   bool nan(const matrix& templat, matrix& flag);
     525  bool nan(const vector& templat, vector& flag);
    544526
    545527  /**
     
    552534
    553535  /**
     536     Randomly shuffles the elements in vector \a invec
     537  */
     538  void shuffle(vector& invec);
     539
     540  /**
    554541     Sort the elements in the vector.
    555542
Note: See TracChangeset for help on using the changeset viewer.