Medial Code Documentation
Loading...
Searching...
No Matches
basic_row_iter.h
Go to the documentation of this file.
1
8#ifndef DMLC_DATA_BASIC_ROW_ITER_H_
9#define DMLC_DATA_BASIC_ROW_ITER_H_
10#include <dmlc/io.h>
11#include <dmlc/logging.h>
12#include <dmlc/data.h>
13#include <dmlc/timer.h>
14#include "./row_block.h"
15#include "./parser.h"
16
17namespace dmlc {
18namespace data {
23template<typename IndexType, typename DType = real_t>
24class BasicRowIter: public RowBlockIter<IndexType, DType> {
25 public:
27 : at_head_(true) {
28 this->Init(parser);
29 delete parser;
30 }
31 virtual ~BasicRowIter() {}
32 virtual void BeforeFirst(void) {
33 at_head_ = true;
34 }
35 virtual bool Next(void) {
36 if (at_head_) {
37 at_head_ = false;
38 return true;
39 } else {
40 return false;
41 }
42 }
43 virtual const RowBlock<IndexType, DType> &Value(void) const {
44 return row_;
45 }
46 virtual size_t NumCol(void) const {
47 return static_cast<size_t>(data_.max_index) + 1;
48 }
49
50 private:
51 // at head
52 bool at_head_;
53 // row block to store
55 // back end data
57 // initialize
58 inline void Init(Parser<IndexType, DType> *parser);
59};
60
61template<typename IndexType, typename DType>
62inline void BasicRowIter<IndexType, DType>::Init(Parser<IndexType, DType> *parser) {
63 data_.Clear();
64 double tstart = GetTime();
65 size_t bytes_expect = 10UL << 20UL;
66 while (parser->Next()) {
67 data_.Push(parser->Value());
68 double tdiff = GetTime() - tstart;
69 size_t bytes_read = parser->BytesRead();
70 if (bytes_read >= bytes_expect) {
71 bytes_read = bytes_read >> 20UL;
72 LOG(INFO) << bytes_read << "MB read,"
73 << bytes_read / tdiff << " MB/sec";
74 bytes_expect += 10UL << 20UL;
75 }
76 }
77 row_ = data_.GetBlock();
78 double tdiff = GetTime() - tstart;
79 LOG(INFO) << "finish reading at "
80 << (parser->BytesRead() >> 20UL) / tdiff
81 << " MB/sec";
82}
83} // namespace data
84} // namespace dmlc
85#endif // DMLC_DATA_BASIC_ROW_ITER_H__
parser interface that parses input data used to load dmlc data format into your own data format Diffe...
Definition data.h:293
Data structure that holds the data Row block iterator interface that gets RowBlocks Difference betwee...
Definition data.h:254
basic set of row iterators that provides
Definition basic_row_iter.h:24
virtual void BeforeFirst(void)
set before first of the item
Definition basic_row_iter.h:32
virtual bool Next(void)
move to next item
Definition basic_row_iter.h:35
virtual size_t NumCol(void) const
Definition basic_row_iter.h:46
virtual const RowBlock< IndexType, DType > & Value(void) const
get current data
Definition basic_row_iter.h:43
defines common input data structure, and interface for handling the input data
defines serializable interface of dmlc
defines logging macros of dmlc allows use of GLOG, fall back to internal implementation when disabled
cross platform timer for timing
namespace for dmlc
Definition array_view.h:12
double GetTime(void)
return time in seconds
Definition timer.h:27
additional data structure to support RowBlock data structure
a block of data, containing several rows in sparse matrix This is useful for (streaming-sxtyle) algor...
Definition data.h:175
dynamic data structure that holds a row block of data
Definition row_block.h:27