Changeset 1132
- Timestamp:
- Feb 23, 2008, 9:16:22 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/ncc_test.cc
r1121 r1132 219 219 *error << "done\n"; 220 220 221 //////////////////////////////////////////////////////////////////////////222 // Testing rejection of KernelLookups223 //////////////////////////////////////////////////////////////////////////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 here230 *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 here241 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 252 221 if(ok) 253 222 *error << "OK" << std::endl; -
trunk/test/vector_test.cc
r1120 r1132 314 314 } 315 315 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 316 342 // test for ticket:285 317 343 { -
trunk/yat/classifier/KernelLookup.cc
r1127 r1132 38 38 39 39 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; 42 46 column_index_.reserve(kernel.size()); 43 47 for(size_t i=0; i<kernel.size(); i++) … … 51 55 const std::vector<size_t>& column, 52 56 const bool owner) 53 : DataLookup2D(row,column,owner), kernel_(&kernel) 57 : column_index_(column), kernel_(&kernel), ref_count_(NULL), 58 row_index_(row) 54 59 { 55 60 // Checking that each row index is less than kernel.rows() … … 65 70 const std::vector<size_t>& row, 66 71 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 } 69 86 ref_count_=other.ref_count_; 70 87 if (ref_count_) … … 74 91 75 92 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_) 77 95 { 78 96 // Checking that no index is out of range … … 92 110 const std::vector<size_t>& index, 93 111 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 } 96 131 assert(kernel_->size()); 97 132 … … 138 173 139 174 175 size_t KernelLookup::columns(void) const 176 { 177 return column_index_.size(); 178 } 179 180 140 181 const DataLookup2D* KernelLookup::data(void) const 141 182 { … … 173 214 { 174 215 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(); 175 222 } 176 223 -
trunk/yat/classifier/KernelLookup.h
r1127 r1132 66 66 /// constructors and assignments. 67 67 /// 68 class KernelLookup : public DataLookup2D68 class KernelLookup 69 69 { 70 70 … … 199 199 const_row_iterator begin_row(size_t) const; 200 200 201 /** 202 \return number of columns 203 */ 204 size_t columns(void) const; 205 201 206 /// 202 207 /// Each column in returned DataLookup corresponds to the column … … 243 248 */ 244 249 const_row_iterator end_row(size_t) const; 250 251 /** 252 \return number of rows 253 */ 254 size_t rows(void) const; 245 255 246 256 /** … … 326 336 const KernelLookup& operator=(const KernelLookup&); 327 337 338 std::vector<size_t> column_index_; 328 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_; 345 std::vector<size_t> row_index_; 329 346 330 347 }; // class KernelLookup
Note: See TracChangeset
for help on using the changeset viewer.