-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract RowBuffer class for SparseRowMatrix. #863
Extract RowBuffer class for SparseRowMatrix. #863
Conversation
* The original SparseRowMatrix use two fields to store each rows, which let code very confusing. Try to extract a RowBuffer class, for SparseRowMatrix data storage, and manage auto-growth logic.
…sparse_row_matrix
dade0ec
to
f63fbcd
Compare
*/ | ||
inline void resize(int rowCnt) { | ||
if (preallocatedBuf_) { | ||
CHECK(preallocatedBuf_->getSize() < rowCnt * width_ * sizeof(real)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里写反了吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
private: | ||
CpuMemHandlePtr preallocatedBuf_; | ||
std::vector<real, AlignedAllocator<real, 32>> rowStore_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rowStore_是不是直接用CpuMemoryHandle就可以了,只是resize greater的时候需要一次copy。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有道理,不过再下一个PR里面加吧。
加了一个TODO注释
*/ | ||
inline size_t getRowCount() const { | ||
if (preallocatedBuf_) { | ||
return preallocatedBuf_->getSize() / sizeof(float) / width_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeof(real)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
* @brief get is this buffer can automatically grow or not. | ||
* @return ture if can automacitally grow. | ||
*/ | ||
inline bool isAutoGrowth() const { return preallocatedBuf_ == nullptr; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return !preallocatedBuf_;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
* optimize the time cost for the wordtag * update the optimize code for the predictor
which make code very confusing. Try to extract a RowBuffer class,
for SparseRowMatrix data storage, and manage auto-growth logic.