various fix of page

This commit is contained in:
tqchen 2014-08-29 20:54:24 -07:00
parent ce772c2f3e
commit 7bc1c3ee79
4 changed files with 14 additions and 9 deletions

View File

@ -38,7 +38,6 @@ DataMatrix* LoadDataMatrix(const char *fname, bool silent, bool savebuffer) {
void SaveDataMatrix(const DataMatrix &dmat, const char *fname, bool silent) {
if (!strcmp(fname + strlen(fname) - 5, ".page")) {
DMatrixPage::Save(fname, dmat, silent);
return;
}
@ -46,7 +45,9 @@ void SaveDataMatrix(const DataMatrix &dmat, const char *fname, bool silent) {
const DMatrixSimple *p_dmat = static_cast<const DMatrixSimple*>(&dmat);
p_dmat->SaveBinary(fname, silent);
} else {
utils::Error("not implemented");
DMatrixSimple smat;
smat.CopyFrom(dmat);
smat.SaveBinary(fname, silent);
}
}

View File

@ -32,7 +32,7 @@ struct RowBatchPage {
const size_t dsize = row.length * sizeof(RowBatch::Entry);
if (FreeBytes() < dsize+ sizeof(int)) return false;
row_ptr(Size() + 1) = row_ptr(Size()) + row.length;
memcpy(data_ptr(Size()) , row.data, dsize);
memcpy(data_ptr(row_ptr(Size())) , row.data, dsize);
++ data_[0];
return true;
}
@ -55,6 +55,11 @@ struct RowBatchPage {
batch.ind_ptr = &rptr[0];
return batch;
}
/*! \brief get i-th row from the batch */
inline RowBatch::Inst operator[](size_t i) {
return RowBatch::Inst(data_ptr(0) + row_ptr(i),
static_cast<bst_uint>(row_ptr(i+1) - row_ptr(i)));
}
/*!
* \brief clear the page, cleanup the content
*/
@ -77,7 +82,7 @@ struct RowBatchPage {
return data_[0];
}
/*! \brief page size 64 MB */
static const size_t kPageSize = 64 << 18;
static const size_t kPageSize = 64 << 8;
private:
/*! \return number of elements */
@ -112,7 +117,6 @@ class ThreadRowPageIterator: public utils::IIterator<RowBatch> {
itr.BeforeFirst();
isend_ = false;
base_rowid_ = 0;
utils::Assert(this->LoadNextPage(), "ThreadRowPageIterator");
}
virtual bool Next(void) {
if(!this->LoadNextPage()) return false;

View File

@ -44,8 +44,8 @@ class DMatrixSimple : public DataMatrix {
}
/*! \brief copy content data from source matrix */
inline void CopyFrom(const DataMatrix &src) {
this->info = src.info;
this->Clear();
this->info = src.info;
// clone data content in thos matrix
utils::IIterator<RowBatch> *iter = src.fmat()->RowIterator();
iter->BeforeFirst();