Ignore:
Timestamp:
Sep 26, 2006, 3:44:24 PM (15 years ago)
Author:
Peter
Message:

fixes #147 and #136

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/classifier/Kernel.cc

    r658 r659  
    1515  Kernel::Kernel(const MatrixLookup& data, const KernelFunction& kf,
    1616                 const bool own)
    17     : data_(&data), data_w_(0), kf_(&kf), data_owner_(own),
    18       weight_owner_(false)
     17    : data_(&data), data_w_(0), kf_(&kf), ref_count_w_(NULL)
    1918  {
     19    if (own)
     20      ref_count_ = new u_int(1);
     21    else
     22      ref_count_ = NULL;
    2023  }
    2124
     
    2326  Kernel::Kernel(const MatrixLookupWeighted& data, const KernelFunction& kf,
    2427                 const bool own)
    25     : data_(&data), data_w_(&data), kf_(&kf), data_owner_(own),
    26       weight_owner_(own)
     28    : data_(&data), data_w_(&data), kf_(&kf)
    2729  {
     30    if (own){
     31      ref_count_ = new u_int(1);
     32      ref_count_w_ = new u_int(1);
     33    }
     34    else {
     35      ref_count_ = NULL;
     36      ref_count_w_ = NULL;
     37    }
    2838  }
    2939
    3040
    3141  Kernel::Kernel(const Kernel& other, const std::vector<size_t>& index)
    32     : kf_(other.kf_), data_owner_(true)
     42    : kf_(other.kf_)
    3343  {
    3444    data_ = other.data_->selected(index);
     45    ref_count_ = new u_int(1);
     46   
    3547    if (other.data_w_){
    3648      data_w_ = other.data_w_->selected(index);
    37       weight_owner_=true;
     49      ref_count_w_ = new u_int(1);
    3850    }
    3951    else{
    4052      data_w_=NULL;
    41       weight_owner_=false;
     53      ref_count_w_ = NULL;
    4254    }
    4355
     
    4658  Kernel::~Kernel()
    4759  {
    48     if (data_owner_)
    49       delete data_;
    50      
    51     if (weight_owner_)
    52       if (data_w_)
     60    if (ref_count_)
     61      if (!--(*ref_count_))
     62        delete data_;
     63
     64    if (ref_count_w_)
     65      if (!--(*ref_count_w_))
    5366        delete data_w_;
    54       else
    55         std::cerr << "Error in Kernel implementation: probably a constructor"
    56                   << std::endl;
    57    
     67
    5868  }
    5969
Note: See TracChangeset for help on using the changeset viewer.