瀏覽代碼

data cleanup

Erik Rodner 9 年之前
父節點
當前提交
f8ef96581b
共有 3 個文件被更改,包括 40 次插入3 次删除
  1. 37 1
      GMHIKernelRaw.cpp
  2. 2 1
      GMHIKernelRaw.h
  3. 1 1
      tests/TestFastHIK.cpp

+ 37 - 1
GMHIKernelRaw.cpp

@@ -18,12 +18,48 @@ using namespace std;
 
 
 GMHIKernelRaw::GMHIKernelRaw( const std::vector< const NICE::SparseVector *> &_examples, const double _d_noise )
 GMHIKernelRaw::GMHIKernelRaw( const std::vector< const NICE::SparseVector *> &_examples, const double _d_noise )
 {
 {
+    this->examples_raw = NULL;
+    this->nnz_per_dimension = NULL;
+    this->table_A = NULL;
+    this->table_B = NULL;
+
     initData(_examples);
     initData(_examples);
     this->d_noise = _d_noise;
     this->d_noise = _d_noise;
 }
 }
 
 
 GMHIKernelRaw::~GMHIKernelRaw()
 GMHIKernelRaw::~GMHIKernelRaw()
 {
 {
+    cleanupData();
+}
+
+void GMHIKernelRaw::cleanupData()
+{
+    if ( this->examples_raw != NULL ) {
+        for ( uint d = 0; d < this->num_dimension; d++ )
+            if (examples_raw[d] != NULL)
+                delete [] examples_raw[d];
+        delete [] this->examples_raw;
+        this->examples_raw = NULL;
+    }
+    if ( this->nnz_per_dimension != NULL ) {
+        delete [] this->nnz_per_dimension;
+        this->nnz_per_dimension = NULL;
+    }
+    if ( this->table_A != NULL ) {
+        for ( uint d = 0; d < this->num_dimension; d++ )
+            if (table_A[d] != NULL)
+                delete [] table_A[d];
+        delete [] this->table_A;
+        this->table_A = NULL;
+    }
+    if ( this->table_B != NULL ) {
+        for ( uint d = 0; d < this->num_dimension; d++ )
+            if (table_B[d] != NULL)
+                delete [] table_B[d];
+        delete [] this->table_B;
+        this->table_B = NULL;
+    }
+
 }
 }
 
 
 void GMHIKernelRaw::initData ( const std::vector< const NICE::SparseVector *> &_examples )
 void GMHIKernelRaw::initData ( const std::vector< const NICE::SparseVector *> &_examples )
@@ -31,7 +67,7 @@ void GMHIKernelRaw::initData ( const std::vector< const NICE::SparseVector *> &_
     if (_examples.size() == 0 )
     if (_examples.size() == 0 )
         fthrow(Exception, "No examples given for learning");
         fthrow(Exception, "No examples given for learning");
 
 
-    // TODO: clean up data if it exists
+    cleanupData();
 
 
     this->num_dimension = _examples[0]->getDim();
     this->num_dimension = _examples[0]->getDim();
     this->examples_raw = new sparseVectorElement *[num_dimension];
     this->examples_raw = new sparseVectorElement *[num_dimension];

+ 2 - 1
GMHIKernelRaw.h

@@ -44,13 +44,14 @@ class GMHIKernelRaw : public GenericMatrix
     double d_noise;
     double d_noise;
 
 
     void initData ( const std::vector< const NICE::SparseVector *> & examples );
     void initData ( const std::vector< const NICE::SparseVector *> & examples );
+    void cleanupData ();
 
 
   public:
   public:
 
 
     /** simple constructor */
     /** simple constructor */
     GMHIKernelRaw( const std::vector< const NICE::SparseVector *> & examples, const double d_noise = 0.1 );
     GMHIKernelRaw( const std::vector< const NICE::SparseVector *> & examples, const double d_noise = 0.1 );
 
 
-    /** multiply with a vector: A*x = y */
+    /** multiply with a vector: A*x = y; this is not really const anymore!! */
     virtual void multiply (NICE::Vector & y, const NICE::Vector & x) const;
     virtual void multiply (NICE::Vector & y, const NICE::Vector & x) const;
 
 
     /** get the number of rows in A */
     /** get the number of rows in A */

+ 1 - 1
tests/TestFastHIK.cpp

@@ -24,7 +24,7 @@ const bool b_debug = true;
 const bool verbose = true;
 const bool verbose = true;
 const bool verboseStartEnd = true;
 const bool verboseStartEnd = true;
 const bool solveLinWithoutRand = false;
 const bool solveLinWithoutRand = false;
-const uint n = 15000;//1500;//1500;//10;
+const uint n = 500;//1500;//1500;//10;
 const uint d = 200;//200;//2;
 const uint d = 200;//200;//2;
 const uint numBins = 11;//1001;//1001;
 const uint numBins = 11;//1001;//1001;
 const uint solveLinMaxIterations = 1000;
 const uint solveLinMaxIterations = 1000;