From 04070ccd9dc71505adbae9bd0db1be3b54f611ad Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sun, 21 Jul 2019 18:03:40 +0000 Subject: [PATCH] Address review comments Signed-off-by: Yong Tang --- tensorflow_io/core/kernels/file_input.cc | 11 ++++------- tensorflow_io/core/ops/file_ops.cc | 2 +- tensorflow_io/core/python/ops/data_ops.py | 2 +- tensorflow_io/image/python/ops/image_dataset_ops.py | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tensorflow_io/core/kernels/file_input.cc b/tensorflow_io/core/kernels/file_input.cc index 6155c9de5b..5d8e067800 100644 --- a/tensorflow_io/core/kernels/file_input.cc +++ b/tensorflow_io/core/kernels/file_input.cc @@ -1,4 +1,4 @@ -/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -42,10 +42,12 @@ class FileContentInput: public FileInput { } std::vector entries; Status status = Status::OK(); + int64 total_size = 0; while (status.ok()) { string buffer; status = s->ReadNBytes(chunk_size, &buffer); if (status.ok() || errors::IsOutOfRange(status)) { + total_size += buffer.size(); entries.emplace_back(std::move(buffer)); } } @@ -57,12 +59,8 @@ class FileContentInput: public FileInput { value_tensor.flat()((*record_read)) = std::move(entries[0]); } else { string buffer; - int64 total_size = 0; - for (size_t i = 0; i < entries.size(); i++) { - total_size += entries[i].size(); - } buffer.reserve(total_size); - for (size_t i = 0; i < entries.size(); i++) { + for (size_t i = 0; i < entries.size(); ++i) { buffer.append(entries[i]); } value_tensor.flat()((*record_read)) = std::move(buffer); @@ -79,7 +77,6 @@ class FileContentInput: public FileInput { bool DecodeAttributes(const VariantTensorData& data) override { return true; } - protected: }; REGISTER_UNARY_VARIANT_DECODE_FUNCTION(FileContentInput, "tensorflow::data::FileContentInput"); diff --git a/tensorflow_io/core/ops/file_ops.cc b/tensorflow_io/core/ops/file_ops.cc index 8445121ee6..1f36c6de44 100644 --- a/tensorflow_io/core/ops/file_ops.cc +++ b/tensorflow_io/core/ops/file_ops.cc @@ -1,4 +1,4 @@ -/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/tensorflow_io/core/python/ops/data_ops.py b/tensorflow_io/core/python/ops/data_ops.py index ec366c4ce8..bd08f5883c 100644 --- a/tensorflow_io/core/python/ops/data_ops.py +++ b/tensorflow_io/core/python/ops/data_ops.py @@ -63,7 +63,7 @@ def __init__(self, fn, data_input, batch, dtypes, shapes): output_shapes=self._shapes), self._batch, self._dtypes, self._shapes) class FileDataset(BaseDataset): - """A FileDataset that read file content as string""" + """A FileDataset that reads file content as string""" def __init__(self, filename): """Create a FileDataset.""" diff --git a/tensorflow_io/image/python/ops/image_dataset_ops.py b/tensorflow_io/image/python/ops/image_dataset_ops.py index 0617621fc2..cb154ddce4 100644 --- a/tensorflow_io/image/python/ops/image_dataset_ops.py +++ b/tensorflow_io/image/python/ops/image_dataset_ops.py @@ -21,7 +21,7 @@ from tensorflow import dtypes from tensorflow.compat.v1 import data from tensorflow_io import _load_library -from tensorflow_io.core.python.ops import data_ops as data_ops +from tensorflow_io.core.python.ops import data_ops image_ops = _load_library('_image_ops.so') class TIFFDataset(data.Dataset):