Changeset 936


Ignore:
Timestamp:
Oct 6, 2007, 1:02:08 AM (16 years ago)
Author:
Peter
Message:

reimplementing yat_assert as a throwing function

Location:
trunk/yat
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/IGP.h

    r925 r936  
    3434#include <cmath>
    3535#include <limits>
     36#include <stdexcept>
    3637
    3738namespace theplu {
     
    8283    : matrix_(data), target_(target)
    8384  {   
    84     yat_assert(target_.size()==matrix_.columns());
     85    utility::yat_assert<std::runtime_error>(target_.size()==matrix_.columns());
    8586   
    8687    // Calculate IGP for each class
  • trunk/yat/classifier/KNN.h

    r931 r936  
    1414#include <cmath>
    1515#include <map>
     16#include <stdexcept>
    1617
    1718namespace theplu {
     
    129130        for(size_t j=0; j<input.columns(); j++) {
    130131          classifier::DataLookupWeighted1D test(*weighted_input,j,false);
    131           yat_assert(training.size()==test.size());
    132           (*distances)(i,j)=statistics::vector_distance(training.begin(),training.end(),test.begin(),typename statistics::vector_distance_traits<Distance>::distance());
    133           yat_assert(!std::isnan((*distances)(i,j)));
     132          utility::yat_assert<std::runtime_error>(training.size()==test.size());
     133          (*distances)(i,j) =
     134            statistics::vector_distance(training.begin(),training.end(),
     135                                        test.begin(), typename statistics::vector_distance_traits<Distance>::distance());
     136          utility::yat_assert<std::runtime_error>(!std::isnan((*distances)(i,j)));
    134137        }
    135138      }
  • trunk/yat/classifier/NCC.h

    r931 r936  
    5050#include <map>
    5151#include <cmath>
    52 
     52#include <stdexcept>
    5353
    5454namespace theplu {
     
    234234        for(size_t k=0; k<centroids_->columns();k++) {
    235235          DataLookup1D centroid(unweighted_centroids,k,false);           
    236           yat_assert(in.size()==centroid.size());
     236          utility::yat_assert<std::runtime_error>(in.size()==centroid.size());
    237237          prediction(k,j)=statistics::
    238238            vector_distance(in.begin(),in.end(),centroid.begin(),
     
    252252          for(size_t k=0; k<centroids_->columns();k++) {
    253253            DataLookupWeighted1D centroid(weighted_centroids,k,false);
    254             yat_assert(in.size()==centroid.size());
     254            utility::yat_assert<std::runtime_error>(in.size()==centroid.size());
    255255            prediction(k,j)=statistics::
    256256              vector_distance(in.begin(),in.end(),centroid.begin(),
     
    267267          for(size_t k=0; k<centroids_->columns();k++) {
    268268            DataLookupWeighted1D centroid(weighted_centroids,k,false);
    269             yat_assert(in.size()==centroid.size());
     269            utility::yat_assert<std::runtime_error>(in.size()==centroid.size());
    270270            prediction(k,j)=statistics::
    271271              vector_distance(in.begin(),in.end(),centroid.begin(),
  • trunk/yat/statistics/AveragerPairWeighted.h

    r916 r936  
    3333
    3434#include <cmath>
     35#include <stdexcept>
    3536
    3637namespace theplu{
     
    200201  {
    201202    for (size_t i=0; i<x.size(); ++i){
    202       yat_assert(!std::isnan(x[i]));
     203      utility::yat_assert<std::runtime_error>(!std::isnan(x[i]));
    203204      add(x[i],y[i],wx[i],wy[i]);
    204205    }
  • trunk/yat/statistics/utility.h

    r934 r936  
    3535#include <algorithm>
    3636#include <cmath>
     37#include <stdexcept>
    3738#include <vector>
    3839
     
    161162  double percentile(T first, T last, double p, bool sorted=false)
    162163  {
    163     yat_assert(first<last && "range is invalid");
    164     yat_assert(p>=0);
    165     yat_assert(p<=100);
     164    utility::yat_assert<std::range_error>(first<last);
     165    utility::yat_assert<std::runtime_error>(p>=0, "percentage is negative");
     166    utility::yat_assert<std::runtime_error>(p<=100,
     167                                            "percentage is larger than 100");
    166168    if (sorted){
    167169      if (p>=100)
  • trunk/yat/utility/Iterator.h

    r932 r936  
    2929#include <iterator>
    3030#include <stddef.h>
     31#include <stdexcept>
    3132
    3233namespace theplu {
     
    6566     */
    6667    return_type operator*(void) const
    67     { yat_assert(index_<container_->size());
     68    { yat_assert<std::out_of_range>(index_<container_->size());
    6869      return container_->operator()(index_); }
    6970
     
    7273     */
    7374    return_type operator[](difference_type n) const
    74     { yat_assert(index_+n < container_->size());
     75    { yat_assert<std::out_of_range>(index_+n < container_->size());
    7576      return container_->operator()(index_+n); }
    7677
  • trunk/yat/utility/IteratorWeighted.h

    r916 r936  
    88#include <iterator>
    99#include <stddef.h>
     10#include <stdexcept>
    1011
    1112namespace theplu {
     
    4546    return_type operator*(void) const
    4647    {
    47       yat_assert(index_<container_->size());
     48      yat_assert<std::out_of_range>(index_<container_->size());
    4849      return container_->operator()(index_);
    4950    }
     
    5354    */
    5455    return_type data(void) const
    55     { yat_assert(index_<container_->size()); return container_->data(index_); }
     56    { yat_assert<std::out_of_range>(index_<container_->size());
     57      return container_->data(index_); }
    5658
    5759    /**
     
    5961    */
    6062    return_type weight(void) const
    61     { yat_assert(index_<container_->size());return container_->weight(index_); }
     63    { yat_assert<std::out_of_range>(index_<container_->size());
     64      return container_->weight(index_); }
    6265
    6366
  • trunk/yat/utility/yat_assert.h

    r921 r936  
    2424*/
    2525
    26 #include <cassert>
     26#include <string>
     27
     28namespace theplu {
     29namespace yat {
     30namespace utility {
     31
     32  template<class X> inline void yat_assert(bool assertion, std::string msg="")
    2733#ifdef YAT_DEBUG
    28 # define yat_assert(expr)   (assert(expr))
     34  { if (YAT_DEBUG && !assertion) throw X(msg); }
    2935#else
    30 # define yat_assert(expr)
     36  { }
    3137#endif
    3238
     39}}}
     40  /*
     41  */
    3342#endif
Note: See TracChangeset for help on using the changeset viewer.