Changeset 1039


Ignore:
Timestamp:
Feb 6, 2008, 1:20:31 AM (14 years ago)
Author:
Peter
Message:

fixes #276

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/statistics_test.cc

    r1000 r1039  
    4646  if (m!=4.5 || m!=m_gsl)
    4747    return -1;
     48  statistics::percentile(data.begin(), data.end(), 100);
     49  data.resize(1);
     50  statistics::median(data.begin(), data.end());
    4851
    4952  double tolerance=1e-10;
  • trunk/yat/statistics/utility.h

    r1025 r1039  
    181181    std::copy(first, last, std::back_inserter(v_copy));
    182182    double j = p/100 * (v_copy.size()-1);
    183     int i = static_cast<int>(j);
    184     std::partial_sort(v_copy.begin(),v_copy.begin()+i+2 , v_copy.end());
     183    size_t i = static_cast<size_t>(j);
     184    if (i+2 < v_copy.size()) {
     185      utility::yat_assert<std::out_of_range>(i+2 < v_copy.size(),
     186                                             "in utility::percentile");
     187      std::partial_sort(v_copy.begin(), v_copy.begin()+i+2, v_copy.end());
     188    }
     189    else
     190      std::sort(v_copy.begin(), v_copy.end());
     191     
    185192    return percentile(v_copy.begin(), v_copy.end(), p, true);
    186193  }
Note: See TracChangeset for help on using the changeset viewer.