Slight problem, so need to fix it.

This commit is contained in:
Dongryeol Lee
2010-10-17 18:05:54 +00:00
parent 223ef2afb8
commit 1979d69aed
6 changed files with 65 additions and 15 deletions
@@ -51,6 +51,7 @@ include(CMake/TargetDistclean.cmake OPTIONAL)
#include_directories( ${FASTLIB_INCLUDE_DIRS} )
include_directories(${CMAKE_BINARY_DIR}/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
@@ -6,13 +6,17 @@
#ifndef CORE_TABLE_DENSE_MATRIX_H
#define CORE_TABLE_DENSE_MATRIX_H
#include "core/table/dense_point.h"
#include "core/table/memory_mapped_file.h"
#include "dense_point.h"
#include "memory_mapped_file.h"
namespace core {
namespace table {
class DenseMatrix {
public:
static core::table::MemoryMappedFile *global_m_file_;
private:
double *ptr_;
@@ -34,7 +38,7 @@ class DenseMatrix {
double *first_ptr = ptr_ + first_col * n_rows_;
double *second_ptr = ptr_ + second_col * n_rows_;
for(int i = 0; i < n_rows_; first_ptr++, second_ptr++, i++) {
std::swap(first_ptr[i], second_ptr[i]);
std::swap(*first_ptr, *second_ptr);
}
}
@@ -56,7 +60,12 @@ class DenseMatrix {
}
~DenseMatrix() {
delete ptr_;
if(global_m_file_) {
global_m_file_->Deallocate(ptr_);
}
else {
delete ptr_;
}
Reset();
}
@@ -65,7 +74,8 @@ class DenseMatrix {
core::table::MemoryMappedFile *m_file_in = NULL) {
ptr_ = (m_file_in) ?
(double *)m_file_in->Allocate(n_rows_in * n_cols_in * sizeof(double)) :
(double *)m_file_in->Allocate(
n_rows_in * n_cols_in * sizeof(double)) :
new double[n_rows_in * n_cols_in];
n_rows_ = n_rows_in;
n_cols_ = n_cols_in;
@@ -10,8 +10,8 @@
#include <armadillo>
#include <boost/serialization/serialization.hpp>
#include "core/table/abstract_point.h"
#include "core/table/memory_mapped_file.h"
#include "abstract_point.h"
#include "memory_mapped_file.h"
namespace core {
namespace table {
@@ -29,7 +29,6 @@ class DenseConstPoint: public core::table::AbstractPoint {
}
virtual ~DenseConstPoint() {
// A const point is always defined as an alias to a part of an
// already-existing memory block, so you do not free it.
Reset();
@@ -104,6 +103,7 @@ class DensePoint: public DenseConstPoint {
BOOST_SERIALIZATION_SPLIT_MEMBER()
void Reset() {
DenseConstPoint::Reset();
is_alias_ = false;
}
@@ -113,9 +113,13 @@ class DensePoint: public DenseConstPoint {
virtual ~DensePoint() {
if(DenseConstPoint::ptr_ != NULL && is_alias_ == false) {
delete DenseConstPoint::ptr_;
if(global_m_file_) {
global_m_file_->Deallocate(ptr_);
}
else {
delete DenseConstPoint::ptr_;
}
}
DenseConstPoint::Reset();
Reset();
}
@@ -129,6 +133,7 @@ class DensePoint: public DenseConstPoint {
(double *) global_m_file_->Allocate(sizeof(double) * length_in) :
new double[length_in];
DenseConstPoint::n_rows_ = length_in;
is_alias_ = false;
}
void Init(const std::vector<double> &vector_in) {
@@ -140,17 +145,20 @@ class DensePoint: public DenseConstPoint {
for(unsigned int i = 0; i < vector_in.size(); i++) {
ptr_[i] = vector_in[i];
}
is_alias_ = false;
}
void Copy(const DenseConstPoint &point_in) {
DenseConstPoint::ptr_ =
(global_m_file_) ?
(double *) global_m_file_->Allocate(sizeof(double) * point_in.length()) :
(double *) global_m_file_->Allocate(
sizeof(double) * point_in.length()) :
new double[point_in.length()];
memcpy(
DenseConstPoint::ptr_, point_in.ptr(),
sizeof(double) * point_in.length());
DenseConstPoint::n_rows_ = point_in.length();
is_alias_ = false;
}
void SetZero() {
@@ -164,7 +172,11 @@ class DensePoint: public DenseConstPoint {
}
void operator=(const core::table::DenseConstPoint &point_in) {
if(ptr_ == NULL) {
this->Init(point_in.length());
}
memcpy(ptr_, point_in.ptr(), sizeof(double) * point_in.length());
is_alias_ = false;
}
void operator+=(const core::table::DenseConstPoint &point_in) {
@@ -3,7 +3,13 @@
* @author Dongryeol Lee (dongryel@cc.gatech.edu)
*/
#include "core/table/memory_mapped_file.h"
#include "core/table/dense_point.h"
#include "memory_mapped_file.h"
#include "dense_matrix.h"
#include "dense_point.h"
#include "table.h"
core::table::MemoryMappedFile *core::table::DenseMatrix::global_m_file_ = NULL;
core::table::MemoryMappedFile *core::table::DensePoint::global_m_file_ = NULL;
core::table::MemoryMappedFile *core::table::Table::global_m_file_ = NULL;
@@ -23,6 +23,8 @@ class Table: public boost::noncopyable {
typedef core::tree::GeneralBinarySpaceTree < core::tree::BallBound <
core::table::DensePoint > > TreeType;
static core::table::MemoryMappedFile *global_m_file_;
public:
class TreeIterator {
@@ -145,7 +147,12 @@ class Table: public boost::noncopyable {
}
~Table() {
delete tree_;
if(global_m_file_) {
RecursiveDeallocate_(tree_);
}
else {
delete tree_;
}
tree_ = NULL;
}
@@ -255,6 +262,14 @@ class Table: public boost::noncopyable {
private:
void RecursiveDeallocate_(TreeType *node) {
if(node->is_leaf() == false) {
RecursiveDeallocate_(node->left());
RecursiveDeallocate_(node->right());
}
global_m_file_->Deallocate(node);
}
void direct_get_(int point_id, double *entry) const {
if(this->IsIndexed() == false) {
data_.CopyColumnVector(point_id, entry);
@@ -5,6 +5,9 @@
* @author Dongryeol Lee (dongryel@cc.gatech.edu)
*/
#ifndef CORE_TREE_GEN_METRIC_TREE_IMPL_H
#define CORE_TREE_GEN_METRIC_TREE_IMPL_H
#include <armadillo>
#include <deque>
#include "core/metric_kernels/abstract_metric.h"
@@ -105,9 +108,10 @@ int MatrixPartition(
return left_count;
}
template<typename PointType>
int FurthestColumnIndex(
const core::metric_kernels::AbstractMetric &metric_in,
const core::table::AbstractPoint &pivot,
const PointType &pivot,
const core::table::DenseMatrix &matrix,
int begin, int count,
double *furthest_distance) {
@@ -265,3 +269,5 @@ void SplitGenMetricTree(
}
};
};
#endif