Changeset 63


Ignore:
Timestamp:
Apr 19, 2004, 1:21:28 PM (17 years ago)
Author:
Peter
Message:

minmax function added

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/vector.cc

    r48 r63  
    55#include <string>
    66#include <vector>
     7#include <utility>
    78
    89#include "vector.h"
     
    125126  }
    126127
     128//Peter, add default checking all elements using GSL
     129  std::pair<u_int,u_int> vector::minmax_index(const std::vector<u_int>& subset ) const
     130  {
     131    u_int min_index = subset[0];
     132    u_int max_index = subset[0];
     133    for (unsigned int i=1; i<subset.size(); i++) {
     134      if (gsl_vector_get( v_, subset[i]) < gsl_vector_get( v_, min_index))
     135        min_index = subset[i];
     136      else if (gsl_vector_get( v_, subset[i]) > gsl_vector_get( v_, max_index))
     137        max_index = subset[i];
     138    }
     139    return std::pair<u_int,u_int>(min_index, max_index);
     140  }
     141
    127142
    128143
  • trunk/src/vector.h

    r62 r63  
    55
    66#include <iostream>
     7#include <vector>
     8#include <utility>
    79
    810#include <gsl/gsl_vector.h>
     
    8688    /// @return A pointer to the internal GSL vector,
    8789    ///
    88     inline gsl_vector* gsl_vector_pointer(void) { return v_; };
     90    inline gsl_vector* gsl_vector_pointer(void) { return v_; }
     91
     92    ///This function returns the indices of the minimum and maximum values in
     93    ///the sub-vector (defined by subset), storing them in imin and imax. When
     94    ///there are several equal minimum or maximum elements then the lowest
     95    ///indices are returned. The returned index is the index from the complete vector (not the sub-vector)  @return Index corresponding to the smallest
     96    ///and largest value.
     97    ///
     98    std::pair<u_int,u_int> vector::minmax_index(const std::vector<u_int>& subset ) const;
    8999
    90100    ///
Note: See TracChangeset for help on using the changeset viewer.