[R] enable R compile

[R] Enable R build for windows and linux
This commit is contained in:
tqchen
2016-01-10 23:15:18 -08:00
parent 72347e2d45
commit 2dc6c2dc52
16 changed files with 625 additions and 540 deletions

View File

@@ -107,7 +107,7 @@ int XGDMatrixCreateFromCSR(const bst_ulong* indptr,
for (bst_ulong i = 0; i < nelem; ++i) {
mat.row_data_[i] = RowBatch::Entry(indices[i], data[i]);
mat.info.num_col = std::max(mat.info.num_col,
static_cast<size_t>(indices[i] + 1));
static_cast<uint64_t>(indices[i] + 1));
}
mat.info.num_row = nindptr - 1;
mat.info.num_nonzero = static_cast<uint64_t>(nelem);

View File

@@ -103,7 +103,7 @@ inline static bool CmpSecond(const std::pair<float, unsigned> &a,
return a.second > b.second;
}
#ifdef XGBOOST_STRICT_R_MODE_
#if XGBOOST_STRICT_R_MODE
// check nan
bool CheckNAN(double v);
double LogGamma(double v);

View File

@@ -6,7 +6,10 @@
#ifndef XGBOOST_COMMON_THREAD_LOCAL_H_
#define XGBOOST_COMMON_THREAD_LOCAL_H_
#if DMLC_ENABLE_STD_THREAD
#include <mutex>
#endif
#include <memory>
#include <vector>
@@ -63,12 +66,19 @@ class ThreadLocalStore {
* \param str the string pointer
*/
void RegisterDelete(T *str) {
#if DMLC_ENABLE_STD_THREAD
std::unique_lock<std::mutex> lock(mutex_);
data_.push_back(str);
lock.unlock();
#else
data_.push_back(str);
#endif
}
#if DMLC_ENABLE_STD_THREAD
/*! \brief internal mutex */
std::mutex mutex_;
#endif
/*!\brief internal data */
std::vector<T*> data_;
};

View File

@@ -8,9 +8,12 @@
#include "./sparse_batch_page.h"
#include "./simple_dmatrix.h"
#include "./simple_csr_source.h"
#include "../common/io.h"
#if DMLC_ENABLE_STD_THREAD
#include "./sparse_page_source.h"
#include "./sparse_page_dmatrix.h"
#include "../common/io.h"
#endif
namespace xgboost {
// implementation of inline functions
@@ -194,11 +197,16 @@ DMatrix* DMatrix::Create(dmlc::Parser<uint32_t>* parser,
source->CopyFrom(parser);
return DMatrix::Create(std::move(source), cache_prefix);
} else {
#if DMLC_ENABLE_STD_THREAD
if (!data::SparsePageSource::CacheExist(cache_prefix)) {
data::SparsePageSource::Create(parser, cache_prefix);
}
std::unique_ptr<data::SparsePageSource> source(new data::SparsePageSource(cache_prefix));
return DMatrix::Create(std::move(source), cache_prefix);
#else
LOG(FATAL) << "External memory is not enabled in mingw";
return nullptr;
#endif
}
}
@@ -214,7 +222,12 @@ DMatrix* DMatrix::Create(std::unique_ptr<DataSource>&& source,
if (cache_prefix.length() == 0) {
return new data::SimpleDMatrix(std::move(source));
} else {
#if DMLC_ENABLE_STD_THREAD
return new data::SparsePageDMatrix(std::move(source), cache_prefix);
#else
LOG(FATAL) << "External memory is not enabled in mingw";
return nullptr;
#endif
}
}
} // namespace xgboost

View File

@@ -51,7 +51,7 @@ void SimpleCSRSource::CopyFrom(dmlc::Parser<uint32_t>* parser) {
bst_float fvalue = batch.value == nullptr ? 1.0f : batch.value[i];
row_data_.push_back(SparseBatch::Entry(index, fvalue));
this->info.num_col = std::max(this->info.num_col,
static_cast<size_t>(index + 1));
static_cast<uint64_t>(index + 1));
}
size_t top = row_ptr_.size();
row_ptr_.resize(top + batch.size);

View File

@@ -4,15 +4,15 @@
* \brief In-memory version of DMatrix.
* \author Tianqi Chen
*/
#ifndef XGBOOST_SPARSE_PAGE_DMATRIX_H_
#define XGBOOST_SPARSE_PAGE_DMATRIX_H_
#ifndef XGBOOST_DATA_SPARSE_PAGE_DMATRIX_H_
#define XGBOOST_DATA_SPARSE_PAGE_DMATRIX_H_
#include <xgboost/base.h>
#include <xgboost/data.h>
#include <dmlc/threadediter.h>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include "./sparse_batch_page.h"
namespace xgboost {
@@ -125,4 +125,4 @@ class SparsePageDMatrix : public DMatrix {
};
} // namespace data
} // namespace xgboost
#endif // XGBOOST_SPARSE_PAGE_DMATRIX_H_
#endif // XGBOOST_DATA_SPARSE_PAGE_DMATRIX_H_