Changeset 1132


Ignore:
Timestamp:
Feb 23, 2008, 9:16:22 PM (16 years ago)
Author:
Peter
Message:

KernelLookup? is not inherited from DataLookup2D - fixes #234

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/ncc_test.cc

    r1121 r1132  
    219219  *error << "done\n";
    220220
    221   //////////////////////////////////////////////////////////////////////////
    222   // Testing rejection of KernelLookups
    223   //////////////////////////////////////////////////////////////////////////
    224   classifier::PolynomialKernelFunction kf;
    225   classifier::Kernel_MEV kernel(ml,kf);
    226   classifier::DataLookup2D* dl_kernel = new classifier::KernelLookup(kernel);
    227   bool catch_error=false;
    228   try {
    229     catch_error=false; // should catch error here
    230     *error << ncc.make_classifier(*dl_kernel,target) << std::endl;
    231   }
    232   catch (std::runtime_error) {   
    233     *error << "caught expected bad cast runtime_error" << std::endl;
    234     catch_error=true;
    235   }
    236   if(!catch_error) {
    237     ok=false;
    238   }
    239   try {
    240     catch_error=false; // should catch error here
    241     ncc.predict(*dl_kernel,prediction);
    242   }
    243   catch (std::runtime_error) {   
    244     *error << "caught expected bad cast runtime_error" << std::endl;
    245     catch_error=true;
    246   }
    247   if(!catch_error) {
    248     ok=false;
    249   }
    250   delete dl_kernel;
    251  
    252221  if(ok)
    253222    *error << "OK" << std::endl;
  • trunk/test/vector_test.cc

    r1120 r1132  
    314314  }
    315315
     316  /*
     317  {
     318    utility::Vector vec(10, 2.3);
     319    utility::VectorView vv(vec);
     320    vec = vv;
     321    if (vec.size()!=10){
     322      *message << "indirect self-assignment failed - size should be 10\n";
     323      ok = false;
     324    }
     325    if (vec(0)!=2.3){
     326      *message << "indirect self-assignment failed - vec(0) should be 2.3\n";
     327      ok = false;
     328    }
     329    utility::VectorView vv2(vec, 0, 5);
     330    vec = vv2;
     331    if (vec.size()!=5){
     332      *message << "indirect self-assignment failed - size should be 5\n";
     333      ok = false;
     334    }
     335    if (vec(0)!=2.3){
     336      *message << "indirect self-assignment failed - vec(0) should be 2.3\n";
     337      ok = false;
     338    }
     339  }
     340  */
     341
    316342  // test for ticket:285
    317343  {
  • trunk/yat/classifier/KernelLookup.cc

    r1127 r1132  
    3838
    3939  KernelLookup::KernelLookup(const Kernel& kernel, const bool own)
    40     : DataLookup2D(own), kernel_(&kernel)
    41   {
     40    : kernel_(&kernel)
     41  {
     42    if (own)
     43      ref_count_ = new u_int(1);
     44    else
     45      ref_count_ = NULL;
    4246    column_index_.reserve(kernel.size());
    4347    for(size_t i=0; i<kernel.size(); i++)
     
    5155                             const std::vector<size_t>& column,
    5256                             const bool owner)
    53     : DataLookup2D(row,column,owner), kernel_(&kernel)
     57    : column_index_(column), kernel_(&kernel), ref_count_(NULL),
     58      row_index_(row)
    5459  {
    5560    // Checking that each row index is less than kernel.rows()
     
    6570                             const std::vector<size_t>& row,
    6671                             const std::vector<size_t>& column)
    67     : DataLookup2D(other,row,column), kernel_(other.kernel_)
    68   {
     72    : kernel_(other.kernel_)
     73  {
     74    assert(row_index_.empty());
     75    row_index_.reserve(row.size());
     76    for (size_t i=0; i<row.size(); i++) {
     77      assert(row[i]<other.row_index_.size());
     78      row_index_.push_back(other.row_index_[row[i]]);
     79    }
     80    assert(column_index_.empty());
     81    column_index_.reserve(column.size());
     82    for (size_t i=0; i<column.size(); i++) {
     83      assert(column[i]<other.column_index_.size());
     84      column_index_.push_back(other.column_index_[column[i]]);
     85    }
    6986    ref_count_=other.ref_count_;
    7087    if (ref_count_)
     
    7491
    7592  KernelLookup::KernelLookup(const KernelLookup& other)
    76     : DataLookup2D(other), kernel_(other.kernel_)
     93    : column_index_(other.column_index_), kernel_(other.kernel_),
     94      row_index_(other.row_index_)
    7795  {
    7896    // Checking that no index is out of range
     
    92110                             const std::vector<size_t>& index,
    93111                             const bool row)
    94     : DataLookup2D(other,index,row), kernel_(other.kernel_)
    95   {
     112    : kernel_(other.kernel_)
     113  {
     114    if (row){
     115      assert(row_index_.empty());
     116      row_index_.reserve(index.size());
     117      for (size_t i=0; i<index.size(); i++) {
     118        assert(index[i]<other.row_index_.size());
     119        row_index_.push_back(other.row_index_[index[i]]);
     120      }
     121      column_index_= other.column_index_;
     122    }
     123    else{
     124      assert(column_index_.empty());
     125      column_index_.reserve(index.size());
     126      for (size_t i=0; i<index.size(); i++) {
     127        column_index_.push_back(other.column_index_[index[i]]);
     128      }
     129      row_index_= other.row_index_;
     130    }
    96131    assert(kernel_->size());
    97132
     
    138173
    139174
     175  size_t KernelLookup::columns(void) const
     176  {
     177    return column_index_.size();
     178  }
     179
     180
    140181  const DataLookup2D* KernelLookup::data(void) const
    141182  {
     
    173214  {
    174215    return const_row_iterator(const_row_iterator::iterator_type(*this,i+1,0),1);
     216  }
     217
     218
     219  size_t KernelLookup::rows(void) const
     220  {
     221    return row_index_.size();
    175222  }
    176223
  • trunk/yat/classifier/KernelLookup.h

    r1127 r1132  
    6666  /// constructors and assignments.
    6767  ///
    68   class KernelLookup : public DataLookup2D
     68  class KernelLookup
    6969  {
    7070
     
    199199    const_row_iterator begin_row(size_t) const;
    200200
     201    /**
     202       \return number of columns
     203    */
     204    size_t columns(void) const;
     205
    201206    ///
    202207    /// Each column in returned DataLookup corresponds to the column
     
    243248     */
    244249    const_row_iterator end_row(size_t) const;
     250
     251    /**
     252       \return number of rows
     253    */
     254    size_t rows(void) const;
    245255
    246256    /**
     
    326336    const KernelLookup& operator=(const KernelLookup&);
    327337
     338    std::vector<size_t> column_index_;
    328339    const Kernel* kernel_;
     340    ///
     341    /// poiter telling how many owners to underlying data. NULL if
     342    /// this is not an owner.
     343    ///
     344    u_int* ref_count_;
     345    std::vector<size_t> row_index_;
    329346   
    330347  }; // class KernelLookup
Note: See TracChangeset for help on using the changeset viewer.