Changeset 1133


Ignore:
Timestamp:
Feb 23, 2008, 9:40:35 PM (13 years ago)
Author:
Peter
Message:

using SmartPtr? in KernelLookup? rather than doing the ref count myself

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/kernel_test.cc

    r1121 r1133  
    3131#include "yat/classifier/Kernel_MEV.h"
    3232#include "yat/classifier/Kernel_SEV.h"
     33#include "yat/classifier/MatrixLookup.h"
    3334
    3435#include <cassert>
  • trunk/test/svm_test.cc

    r1121 r1133  
    2929#include "yat/classifier/Kernel_SEV.h"
    3030#include "yat/classifier/Kernel_MEV.h"
     31#include "yat/classifier/MatrixLookup.h"
    3132#include "yat/classifier/PolynomialKernelFunction.h"
    3233#include "yat/classifier/Target.h"
  • trunk/yat/classifier/KernelLookup.cc

    r1132 r1133  
    3838
    3939  KernelLookup::KernelLookup(const Kernel& kernel, const bool own)
    40     : kernel_(&kernel)
    41   {
    42     if (own)
    43       ref_count_ = new u_int(1);
    44     else
    45       ref_count_ = NULL;
     40    : kernel_(utility::SmartPtr<const Kernel>(&kernel, own))
     41  {
    4642    column_index_.reserve(kernel.size());
    4743    for(size_t i=0; i<kernel.size(); i++)
     
    5551                             const std::vector<size_t>& column,
    5652                             const bool owner)
    57     : column_index_(column), kernel_(&kernel), ref_count_(NULL),
     53    : column_index_(column),
     54      kernel_(utility::SmartPtr<const Kernel>(&kernel, owner)),
    5855      row_index_(row)
    5956  {
     
    8481      column_index_.push_back(other.column_index_[column[i]]);
    8582    }
    86     ref_count_=other.ref_count_;
    87     if (ref_count_)
    88       ++(*ref_count_);
    8983  }
    9084 
     
    10195           *(max_element(column_index_.begin(), column_index_.end()))<
    10296           kernel_->size());
    103     ref_count_=other.ref_count_;
    104     if (ref_count_)
    105       ++(*ref_count_);
    10697  }
    10798 
     
    138129           *(max_element(column_index_.begin(), column_index_.end()))<
    139130           kernel_->size());
    140     ref_count_=other.ref_count_;
    141     if (ref_count_)
    142       ++(*ref_count_);
    143131  }
    144132 
     
    146134  KernelLookup::~KernelLookup(void)
    147135  {
    148     if (ref_count_)
    149       if (!--(*ref_count_))
    150         delete kernel_;
    151136  }
    152137
  • trunk/yat/classifier/KernelLookup.h

    r1132 r1133  
    2828
    2929#include "Kernel.h"
    30 #include "DataLookup2D.h"
    31 #include "MatrixLookup.h"
    3230#include "yat/utility/Container2DIterator.h"
    3331#include "yat/utility/iterator_traits.h"
     32#include "yat/utility/SmartPtr.h"
    3433#include "yat/utility/StrideIterator.h"
    35 
    3634
    3735#include <vector>
     
    4139namespace classifier {
    4240
     41  class DataLookup2D;
    4342  class KernelFunction;
     43  class MatrixLookup;
     44  class MatrixLookupWeighted;
    4445
    4546  ///
     
    337338
    338339    std::vector<size_t> column_index_;
    339     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_;
     340    utility::SmartPtr<const Kernel> kernel_;
    345341    std::vector<size_t> row_index_;
    346342   
  • trunk/yat/utility/SmartPtr.h

    r1125 r1133  
    2626
    2727#include "yat_assert.h"
     28
     29// debug
     30#include <iostream>
    2831
    2932namespace theplu {
     
    7073      if (owner)
    7174        ref_count_ = new u_int(1);
     75      else
     76        ref_count_ = NULL;
    7277    }
    7378
Note: See TracChangeset for help on using the changeset viewer.