From fb5d4e140bf87f5a5925322d13146145f955bcd4 Mon Sep 17 00:00:00 2001 From: ssharfraz3 Date: Wed, 12 May 2010 15:23:10 +0000 Subject: [PATCH] Serialization to fastlib/src --- .../branches/fastlib-cmake/src/CMakeLists.txt | 6 +++--- .../branches/fastlib-cmake/src/base/base.h | 8 +++++++ .../fastlib-cmake/src/col/col_string.h | 9 ++++++++ fastlib/branches/fastlib-cmake/src/col/heap.h | 11 ++++++++-- .../branches/fastlib-cmake/src/col/intmap.h | 17 +++++++++++++-- .../branches/fastlib-cmake/src/col/rangeset.h | 12 +++++++++-- .../fastlib-cmake/src/data/dataset.cc | 1 + .../branches/fastlib-cmake/src/data/dataset.h | 14 +++++++++++-- .../branches/fastlib-cmake/src/la/matrix.h | 21 ++++++++++++++++++- .../branches/fastlib-cmake/src/math/kernel.h | 12 ++++++++++- .../fastlib-cmake/src/math/math_lib.h | 12 +++++++++-- .../branches/fastlib-cmake/src/tree/bounds.h | 18 ++++++++++++++-- .../fastlib-cmake/src/tree/spacetree.h | 16 ++++++++++++-- 13 files changed, 138 insertions(+), 19 deletions(-) diff --git a/fastlib/branches/fastlib-cmake/src/CMakeLists.txt b/fastlib/branches/fastlib-cmake/src/CMakeLists.txt index 0076415e0d..f94d564f21 100644 --- a/fastlib/branches/fastlib-cmake/src/CMakeLists.txt +++ b/fastlib/branches/fastlib-cmake/src/CMakeLists.txt @@ -68,8 +68,8 @@ add_executable( otrav_test otrav_test.cc ) target_link_libraries( otrav_test fastlib ) # make sure header files are installed correctly -install(FILES ${CMAKE_BINARY_DIR}/include/fastlib/ - DESTINATION include/fastlib) +#install(FILES ${CMAKE_BINARY_DIR}/include/fastlib/ +# DESTINATION include/fastlib) ## installation install(TARGETS fastlib @@ -78,4 +78,4 @@ install(TARGETS fastlib ARCHIVE DESTINATION lib ) -install(FILES fastlib.h DESTINATION include/fastlib) +#install(FILES fastlib.h DESTINATION include/fastlib) diff --git a/fastlib/branches/fastlib-cmake/src/base/base.h b/fastlib/branches/fastlib-cmake/src/base/base.h index 81c7ea8a4c..9000177e89 100644 --- a/fastlib/branches/fastlib-cmake/src/base/base.h +++ b/fastlib/branches/fastlib-cmake/src/base/base.h @@ -53,6 +53,14 @@ #include "cc.h" #include "ccmem.h" #include "otrav.h" +#include +#include +#include +#include +#include +#include +#include +#include //#include "cc.h" //#include "ccmem.h" //#include "otrav.h" diff --git a/fastlib/branches/fastlib-cmake/src/col/col_string.h b/fastlib/branches/fastlib-cmake/src/col/col_string.h index 7b40258e8c..46a6a93647 100644 --- a/fastlib/branches/fastlib-cmake/src/col/col_string.h +++ b/fastlib/branches/fastlib-cmake/src/col/col_string.h @@ -68,7 +68,16 @@ class String { OT_OBJ(c_str); } + public: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & array_; + } + /** * Implicit conversion constructor. */ diff --git a/fastlib/branches/fastlib-cmake/src/col/heap.h b/fastlib/branches/fastlib-cmake/src/col/heap.h index 1a82170dbd..390256a86c 100644 --- a/fastlib/branches/fastlib-cmake/src/col/heap.h +++ b/fastlib/branches/fastlib-cmake/src/col/heap.h @@ -69,11 +69,18 @@ class MinHeap { ArrayList entries_; - OBJECT_TRAVERSAL(MinHeap) { + /*OBJECT_TRAVERSAL(MinHeap) { OT_OBJ(entries_); - } + }*/ public: + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & entries_; + } + /** * Initializes an empty priority queue. */ diff --git a/fastlib/branches/fastlib-cmake/src/col/intmap.h b/fastlib/branches/fastlib-cmake/src/col/intmap.h index 0020ef1adf..c34c9257cf 100644 --- a/fastlib/branches/fastlib-cmake/src/col/intmap.h +++ b/fastlib/branches/fastlib-cmake/src/col/intmap.h @@ -53,13 +53,26 @@ class DenseIntMap { index_t size_; Value default_value_; - OT_DEF(DenseIntMap) { + /*OT_DEF(DenseIntMap) { OT_MY_OBJECT(size_); OT_MY_OBJECT(default_value_); OT_MALLOC_ARRAY(ptr_, size_); - } + }*/ public: + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + int i; + for(i = 0; i < size_; i++) + { + ar & ptr_[i]; + } + ar & size_; + ar & default_value_; + } + /** Creates a blank mapping. */ void Init() { ptr_ = NULL; diff --git a/fastlib/branches/fastlib-cmake/src/col/rangeset.h b/fastlib/branches/fastlib-cmake/src/col/rangeset.h index f1b03f537d..2cf8287891 100644 --- a/fastlib/branches/fastlib-cmake/src/col/rangeset.h +++ b/fastlib/branches/fastlib-cmake/src/col/rangeset.h @@ -68,11 +68,19 @@ class RangeSet { private: ArrayList ranges_; - OT_DEF(RangeSet) { + /*OT_DEF(RangeSet) { OT_MY_OBJECT(ranges_); - } + }*/ public: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & ranges_; + } + /** * Creates an empty set of ranges. */ diff --git a/fastlib/branches/fastlib-cmake/src/data/dataset.cc b/fastlib/branches/fastlib-cmake/src/data/dataset.cc index fc8e4daa05..ab61fc2245 100644 --- a/fastlib/branches/fastlib-cmake/src/data/dataset.cc +++ b/fastlib/branches/fastlib-cmake/src/data/dataset.cc @@ -666,6 +666,7 @@ void Dataset::SplitTrainTest(int folds, int fold_number, success_t data::Load(const char *fname, Matrix *matrix) { Dataset dataset; + printf("In Load:%s\n", fname); success_t result = dataset.InitFromFile(fname); matrix->Own(&dataset.matrix()); return result; diff --git a/fastlib/branches/fastlib-cmake/src/data/dataset.h b/fastlib/branches/fastlib-cmake/src/data/dataset.h index 9ebc666c53..2019404410 100644 --- a/fastlib/branches/fastlib-cmake/src/data/dataset.h +++ b/fastlib/branches/fastlib-cmake/src/data/dataset.h @@ -78,7 +78,7 @@ class DatasetFeature { /** If nominal, the names of each numbered value. */ ArrayList value_names_; - OBJECT_TRAVERSAL(DatasetFeature) { + /*OBJECT_TRAVERSAL(DatasetFeature) { OT_OBJ(name_); //OT_OBJ(reinterpret_cast(type_)); OT_ENUM_EXPERT(type_, int, @@ -86,7 +86,7 @@ class DatasetFeature { OT_ENUM_VAL(INTEGER) OT_ENUM_VAL(NOMINAL)); OT_OBJ(value_names_); - } + }*/ /** * Initialization common to all features. @@ -99,6 +99,16 @@ class DatasetFeature { } public: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & name_; + ar & type_; + ar & value_names_; + } + /** * Initialize to be a continuous feature. * diff --git a/fastlib/branches/fastlib-cmake/src/la/matrix.h b/fastlib/branches/fastlib-cmake/src/la/matrix.h index a408795cd2..550f58b1fb 100644 --- a/fastlib/branches/fastlib-cmake/src/la/matrix.h +++ b/fastlib/branches/fastlib-cmake/src/la/matrix.h @@ -79,7 +79,16 @@ class GenVector { index_t length_; /** Whether this should be freed, i.e. it is not an alias. */ bool should_free_; - + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & ptr_; + ar & length_; + ar & should_free_; + } + OBJECT_TRAVERSAL_ONLY(GenVector) { OT_OBJ(length_); OT_ALLOC(ptr_, length_); @@ -465,6 +474,16 @@ class GenMatrix { /** Whether I am a strong copy (not an alias). */ bool should_free_; + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & ptr_; + ar & n_rows_; + ar & n_cols_; + ar & should_free_; + } + OBJECT_TRAVERSAL_ONLY(GenMatrix) { OT_OBJ(n_rows_); OT_OBJ(n_cols_); diff --git a/fastlib/branches/fastlib-cmake/src/math/kernel.h b/fastlib/branches/fastlib-cmake/src/math/kernel.h index 03de1cae54..f295afd674 100644 --- a/fastlib/branches/fastlib-cmake/src/math/kernel.h +++ b/fastlib/branches/fastlib-cmake/src/math/kernel.h @@ -55,12 +55,22 @@ class GaussianKernel { double neg_inv_bandwidth_2sq_; double bandwidth_sq_; - OBJECT_TRAVERSAL(GaussianKernel) { + /* OBJECT_TRAVERSAL(GaussianKernel) { OT_OBJ(neg_inv_bandwidth_2sq_); OT_OBJ(bandwidth_sq_); } + */ public: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & neg_inv_bandwidth_2sq_; + ar & bandwidth_sq_; + } + static const bool HAS_CUTOFF = false; public: diff --git a/fastlib/branches/fastlib-cmake/src/math/math_lib.h b/fastlib/branches/fastlib-cmake/src/math/math_lib.h index cc6c965053..384cc855f2 100644 --- a/fastlib/branches/fastlib-cmake/src/math/math_lib.h +++ b/fastlib/branches/fastlib-cmake/src/math/math_lib.h @@ -194,11 +194,19 @@ class MinMaxVal { /** The underlying value. */ Value val; - OBJECT_TRAVERSAL(MinMaxVal) { + /*OBJECT_TRAVERSAL(MinMaxVal) { OT_OBJ(val); - } + }*/ public: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & val; + } + /** * Converts implicitly to the value. */ diff --git a/fastlib/branches/fastlib-cmake/src/tree/bounds.h b/fastlib/branches/fastlib-cmake/src/tree/bounds.h index 0cfd7115c9..cb297a9e7a 100644 --- a/fastlib/branches/fastlib-cmake/src/tree/bounds.h +++ b/fastlib/branches/fastlib-cmake/src/tree/bounds.h @@ -62,12 +62,26 @@ class DHrectBound { DRange *bounds_; index_t dim_; - OBJECT_TRAVERSAL(DHrectBound) { + /*OBJECT_TRAVERSAL(DHrectBound) { OT_OBJ(dim_); OT_ALLOC(bounds_, dim_); - }; + };*/ public: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + int i; + + for(i = 0; i < dim_; i++) + { + ar & bounds_[i]; + } + ar & dim_; + } + /** * Initializes to specified dimensionality with each dimension the empty * set. diff --git a/fastlib/branches/fastlib-cmake/src/tree/spacetree.h b/fastlib/branches/fastlib-cmake/src/tree/spacetree.h index c72262ea4f..55bbde6a53 100644 --- a/fastlib/branches/fastlib-cmake/src/tree/spacetree.h +++ b/fastlib/branches/fastlib-cmake/src/tree/spacetree.h @@ -72,16 +72,28 @@ class BinarySpaceTree { index_t count_; Statistic stat_; - OT_DEF(BinarySpaceTree) { + /*OT_DEF(BinarySpaceTree) { OT_MY_OBJECT(bound_); OT_PTR_NULLABLE(left_); OT_PTR_NULLABLE(right_); OT_MY_OBJECT(begin_); OT_MY_OBJECT(count_); OT_MY_OBJECT(stat_); - } + }*/ public: + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & bound_; + ar & left_; + ar & right_; + ar & begin_; + ar & count_; + ar & stat_; + } + /* BinarySpaceTree() { DEBUG_ONLY(begin_ = BIG_BAD_NUMBER);