MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetNumLinesInTextFile

Function GetNumLinesInTextFile

tensorflow/core/kernels/lookup_util.cc:31–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29static const int kWholeLine = -2;
30
31Status GetNumLinesInTextFile(Env* env, const string& vocab_file,
32 int64* num_lines) {
33 std::unique_ptr<RandomAccessFile> file;
34 TF_RETURN_IF_ERROR(env->NewRandomAccessFile(vocab_file, &file));
35
36 io::InputBuffer input_buffer(file.get(), kInputBufferSize);
37 string line;
38 Status s = input_buffer.ReadLine(&line);
39 int64 next_id = 0;
40 while (s.ok()) {
41 next_id++;
42 s = input_buffer.ReadLine(&line);
43 }
44 if (!errors::IsOutOfRange(s)) {
45 return s;
46 }
47 *num_lines = next_id;
48 return Status::OK();
49}
50
51// Iterator that reads a text file. Each iteration process one line, it parses
52// the line and populates the keys and values tensors used for initialization

Callers 1

total_sizeMethod · 0.85

Calls 4

NewRandomAccessFileMethod · 0.45
getMethod · 0.45
ReadLineMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected