Changeset 1875


Ignore:
Timestamp:
Mar 19, 2009, 1:35:47 PM (13 years ago)
Author:
Peter
Message:

fixes #504. Also added pp macro YAT_ASSERT that calls yat_assert with an appropriate msg

Location:
trunk/yat
Files:
3 edited

Legend:

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

    r1487 r1875  
    66/*
    77  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
     8  Copyright (C) 2009 Peter Johansson
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    212213        (*distances)(i,j) = distance_(training.begin_column(i), training.end_column(i),
    213214                                      test.begin_column(j));
    214         utility::yat_assert<std::runtime_error>(!std::isnan((*distances)(i,j)));
     215        YAT_ASSERT(!std::isnan((*distances)(i,j)));
    215216      }
    216217    }
  • trunk/yat/classifier/SubsetGenerator.h

    r1487 r1875  
    77  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    88  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     9  Copyright (C) 2009 Peter Johansson
    910
    1011  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    217218    : f_selector_(NULL), sampler_(sampler)
    218219  {
    219     utility::yat_assert<std::runtime_error>(target().size()==data.columns());
     220    YAT_ASSERT(target().size()==data.columns());
    220221
    221222    training_data_.reserve(sampler_.size());
    222223    validation_data_.reserve(sampler_.size());
    223224    build(data);
    224     utility::yat_assert<std::runtime_error>(training_data_.size()==size());
    225     utility::yat_assert<std::runtime_error>(training_target_.size()==size());
    226     utility::yat_assert<std::runtime_error>(validation_data_.size()==size());
    227     utility::yat_assert<std::runtime_error>(validation_target_.size()==size());
     225    YAT_ASSERT(training_data_.size()==size());
     226    YAT_ASSERT(training_target_.size()==size());
     227    YAT_ASSERT(validation_data_.size()==size());
     228    YAT_ASSERT(validation_target_.size()==size());
    228229  }
    229230
     
    235236    : f_selector_(&fs), sampler_(sampler)
    236237  {
    237     utility::yat_assert<std::runtime_error>(target().size()==data.columns());
     238    YAT_ASSERT(target().size()==data.columns());
    238239    features_.reserve(size());
    239240    training_data_.reserve(size());
    240241    validation_data_.reserve(size());
    241242    build(data);
    242     utility::yat_assert<std::runtime_error>(training_data_.size()==size());
    243     utility::yat_assert<std::runtime_error>(training_target_.size()==size());
    244     utility::yat_assert<std::runtime_error>(validation_data_.size()==size());
    245     utility::yat_assert<std::runtime_error>(validation_target_.size()==size());
     243    YAT_ASSERT(training_data_.size()==size());
     244    YAT_ASSERT(training_target_.size()==size());
     245    YAT_ASSERT(validation_data_.size()==size());
     246    YAT_ASSERT(validation_target_.size()==size());
    246247  }
    247248
     
    250251  SubsetGenerator<Data>::~SubsetGenerator()
    251252  {
    252     utility::yat_assert<std::runtime_error>(training_data_.size()==validation_data_.size());
     253    YAT_ASSERT(training_data_.size()==validation_data_.size());
    253254    for (size_t i=0; i<training_data_.size(); i++)
    254255      delete training_data_[i];
     
    272273          new MatrixLookup(ml, training_index(k), false);
    273274        // use these data to create feature selection
    274         utility::yat_assert<std::runtime_error>(train_data_all_feat);
     275        YAT_ASSERT(train_data_all_feat);
    275276        f_selector_->update(*train_data_all_feat, training_target(k));
    276277        // get features
    277278        features_.push_back(f_selector_->features());
    278         utility::yat_assert<std::runtime_error>(train_data_all_feat);
     279        YAT_ASSERT(train_data_all_feat);
    279280        delete train_data_all_feat;
    280281      }
  • trunk/yat/utility/yat_assert.h

    r1797 r1875  
    55/*
    66  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2009 Peter Johansson
    78
    89  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2223*/
    2324
     25#include <sstream>
     26#include <stdexcept>
    2427#include <string>
    2528
     
    3639     X is thrown using constructor X(\a msg ).
    3740   */
    38   template<class X> inline void yat_assert(bool assertion, std::string msg="")
     41  template<class X> inline void yat_assert(bool assertion, std::string msg)
    3942#ifdef YAT_DEBUG
    4043  { if (!assertion) throw X(std::string("yat_assert:")+msg); }
     
    4447
    4548}}}
     49
     50
     51#ifdef YAT_DEBUG
     52// Peter, this is a bit clumsy, but I wanna keep the stringstream
     53// invisible outside macro, or multiple calls to macro would result in
     54// multiple declaration of the stringstream. Also the macro is
     55// supposed to be called with a trailing `;', and that's why we need
     56// to end with something that allows that.
     57#define YAT_ASSERT(expr) \
     58  if (expr) { \
     59    std::stringstream yat_msg_;                                 \
     60    yat_msg_ << __FILE__ << ":" << __LINE__ << " failed assertion `" \
     61             << #expr << "'";                                           \
     62    theplu::yat::utility::yat_assert<std::runtime_error>(expr,          \
     63                                                         yat_msg_.str()); \
     64  } \
     65  else theplu::yat::utility::yat_assert<std::runtime_error>(expr, "")
     66#else
     67// This could be anything empty, but why not use the empty yat_assert
     68#define YAT_ASSERT(expr) theplu::yat::utility::yat_assert<std::runtime_error>(expr, "")
     69#endif
    4670  /*
    4771  */
Note: See TracChangeset for help on using the changeset viewer.