From 84e5fc285b5c3ce766f048ee3d89c0ba1e076413 Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Tue, 26 Aug 2014 20:32:33 -0700 Subject: [PATCH] bst_ulong supported by sparsematrix builder --- R-package/src/xgboost_R.cpp | 4 ++-- src/utils/matrix_csr.h | 12 ++++++------ wrapper/xgboost_R.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R-package/src/xgboost_R.cpp b/R-package/src/xgboost_R.cpp index 63b74df31..1ca232509 100644 --- a/R-package/src/xgboost_R.cpp +++ b/R-package/src/xgboost_R.cpp @@ -62,9 +62,9 @@ extern "C" { int ncol = length(indptr) - 1; int ndata = length(data); // transform into CSR format - std::vector row_ptr; + std::vector row_ptr; std::vector< std::pair > csr_data; - utils::SparseCSRMBuilder< std::pair > builder(row_ptr, csr_data); + utils::SparseCSRMBuilder, false, bst_ulong> builder(row_ptr, csr_data); builder.InitBudget(); for (int i = 0; i < ncol; ++i) { for (int j = col_ptr[i]; j < col_ptr[i+1]; ++j) { diff --git a/src/utils/matrix_csr.h b/src/utils/matrix_csr.h index 31022553b..0f3b20a14 100644 --- a/src/utils/matrix_csr.h +++ b/src/utils/matrix_csr.h @@ -17,26 +17,26 @@ namespace utils { * \tparam IndexType type of index used to store the index position, usually unsigned or size_t * \tparam whether enabling the usage of aclist, this option must be enabled manually */ -template +template struct SparseCSRMBuilder { private: /*! \brief dummy variable used in the indicator matrix construction */ std::vector dummy_aclist; /*! \brief pointer to each of the row */ - std::vector &rptr; + std::vector &rptr; /*! \brief index of nonzero entries in each row */ std::vector &findex; /*! \brief a list of active rows, used when many rows are empty */ std::vector &aclist; public: - SparseCSRMBuilder(std::vector &p_rptr, + SparseCSRMBuilder(std::vector &p_rptr, std::vector &p_findex) :rptr(p_rptr), findex(p_findex), aclist(dummy_aclist) { Assert(!UseAcList, "enabling bug"); } /*! \brief use with caution! rptr must be cleaned before use */ - SparseCSRMBuilder(std::vector &p_rptr, + SparseCSRMBuilder(std::vector &p_rptr, std::vector &p_findex, std::vector &p_aclist) :rptr(p_rptr), findex(p_findex), aclist(p_aclist) { @@ -62,7 +62,7 @@ struct SparseCSRMBuilder { * \param row_id the id of the row * \param nelem number of element budget add to this row */ - inline void AddBudget(size_t row_id, size_t nelem = 1) { + inline void AddBudget(size_t row_id, SizeType nelem = 1) { if (rptr.size() < row_id + 2) { rptr.resize(row_id + 2, 0); } @@ -101,7 +101,7 @@ struct SparseCSRMBuilder { * element to each row, the number of calls shall be exactly same as add_budget */ inline void PushElem(size_t row_id, IndexType col_id) { - size_t &rp = rptr[row_id + 1]; + SizeType &rp = rptr[row_id + 1]; findex[rp++] = col_id; } /*! diff --git a/wrapper/xgboost_R.cpp b/wrapper/xgboost_R.cpp index 88a320a4a..4be565d1a 100644 --- a/wrapper/xgboost_R.cpp +++ b/wrapper/xgboost_R.cpp @@ -62,9 +62,9 @@ extern "C" { int ncol = length(indptr) - 1; int ndata = length(data); // transform into CSR format - std::vector row_ptr; + std::vector row_ptr; std::vector< std::pair > csr_data; - utils::SparseCSRMBuilder< std::pair > builder(row_ptr, csr_data); + utils::SparseCSRMBuilder, false, bst_ulong> builder(row_ptr, csr_data); builder.InitBudget(); for (int i = 0; i < ncol; ++i) { for (int j = col_ptr[i]; j < col_ptr[i+1]; ++j) {