Changeset 1132 for trunk/yat/classifier


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/yat/classifier
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.