Initialize iterator. Prepares the file 'filename' and sets the data types to return the keys and values tensors. It requires the indices of the tokens in the line given a delimiter to specify where to pick the data from. - Index -2 means the entire line as string. - Index -1 means the line number stored in int64. - Index >= 0 represent index (starting at zero) of the split line based on delimite
| 73 | // - Index >= 0 represent index (starting at zero) of the split line based on |
| 74 | // delimiter. |
| 75 | Status Init(const string& filename, int64 vocab_size, char delimiter, |
| 76 | DataType key_dtype, int64 key_index, DataType value_dtype, |
| 77 | int64 value_index, Env* env) { |
| 78 | filename_ = filename; |
| 79 | vocab_size_ = vocab_size; |
| 80 | delimiter_ = delimiter; |
| 81 | key_ = Tensor(key_dtype, TensorShape({})); |
| 82 | value_ = Tensor(value_dtype, TensorShape({})); |
| 83 | key_index_ = key_index; |
| 84 | value_index_ = value_index; |
| 85 | env_ = env; |
| 86 | |
| 87 | status_ = env->NewRandomAccessFile(filename_, &file_); |
| 88 | if (!status_.ok()) return status_; |
| 89 | |
| 90 | input_buffer_.reset(new io::InputBuffer(file_.get(), kInputBufferSize)); |
| 91 | valid_ = true; |
| 92 | next_id_ = 0; |
| 93 | ignore_split_ = std::max(key_index_, value_index_) < 0; |
| 94 | Next(); |
| 95 | return status_; |
| 96 | } |
| 97 | |
| 98 | void Next() override { |
| 99 | if (!valid_) return; |
no test coverage detected