Skip to content

Commit

Permalink
Merge pull request #9688 from wangkuiyi/cpplint-recordio
Browse files Browse the repository at this point in the history
Fix cpplint errors with paddle/fluid/recordio
  • Loading branch information
wanglei828 authored Apr 7, 2018
2 parents b2a1c9e + c839ec6 commit bcb46f5
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
4 changes: 3 additions & 1 deletion cmake/external/snappystream.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ add_library(snappystream STATIC IMPORTED GLOBAL)
set_property(TARGET snappystream PROPERTY IMPORTED_LOCATION
"${SNAPPYSTREAM_INSTALL_DIR}/lib/libsnappystream.a")

include_directories(${SNAPPYSTREAM_INCLUDE_DIR})
include_directories(${SNAPPYSTREAM_INCLUDE_DIR}) # For snappysteam to include its own headers.
include_directories(${THIRD_PARTY_PATH}/install) # For Paddle to include snappy stream headers.

add_dependencies(snappystream extern_snappystream)
3 changes: 2 additions & 1 deletion cmake/external/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ ELSE(WIN32)
SET(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/libz.a" CACHE FILEPATH "zlib library." FORCE)
ENDIF(WIN32)

INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) # For zlib code to include its own headers.
INCLUDE_DIRECTORIES(${THIRD_PARTY_PATH}/install) # For Paddle code to include zlib.h.

ExternalProject_Add(
extern_zlib
Expand Down
6 changes: 4 additions & 2 deletions paddle/fluid/recordio/chunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

#include "paddle/fluid/recordio/chunk.h"

#include <algorithm>
#include <memory>
#include <sstream>

#include "paddle/fluid/platform/enforce.h"
#include "snappystream.hpp"
#include "zlib.h"
#include "snappy_stream/include/snappystream.hpp"
#include "zlib/include/zlib.h"

namespace paddle {
namespace recordio {
Expand Down
12 changes: 5 additions & 7 deletions paddle/fluid/recordio/chunk_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,27 @@

#include "gtest/gtest.h"

using namespace paddle::recordio;

TEST(Chunk, SaveLoad) {
Chunk ch;
paddle::recordio::Chunk ch;
ch.Add(std::string("12345", 6));
ch.Add(std::string("123", 4));
std::stringstream ss;
ch.Write(ss, Compressor::kNoCompress);
ch.Write(ss, paddle::recordio::Compressor::kNoCompress);
ss.seekg(0);
ch.Parse(ss);
ASSERT_EQ(ch.NumBytes(), 10U);
}

TEST(Chunk, Compressor) {
Chunk ch;
paddle::recordio::Chunk ch;
ch.Add(std::string("12345", 6));
ch.Add(std::string("123", 4));
ch.Add(std::string("123", 4));
ch.Add(std::string("123", 4));
std::stringstream ss;
ch.Write(ss, Compressor::kSnappy);
ch.Write(ss, paddle::recordio::Compressor::kSnappy);
std::stringstream ss2;
ch.Write(ss2, Compressor::kNoCompress);
ch.Write(ss2, paddle::recordio::Compressor::kNoCompress);
ASSERT_LE(ss.tellp(), ss2.tellp()); // Compress should contain less data;

ch.Clear();
Expand Down
6 changes: 2 additions & 4 deletions paddle/fluid/recordio/header_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

#include "gtest/gtest.h"

using namespace paddle::recordio;

TEST(Recordio, ChunkHead) {
Header hdr(0, 1, Compressor::kGzip, 3);
paddle::recordio::Header hdr(0, 1, paddle::recordio::Compressor::kGzip, 3);
std::stringstream ss;
hdr.Write(ss);
ss.seekg(0, std::ios::beg);
Header hdr2;
paddle::recordio::Header hdr2;
hdr2.Parse(ss);
EXPECT_TRUE(hdr == hdr2);
}
4 changes: 4 additions & 0 deletions paddle/fluid/recordio/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
// limitations under the License.

#include "paddle/fluid/recordio/scanner.h"

#include <string>

#include "paddle/fluid/platform/enforce.h"

namespace paddle {
namespace recordio {

Scanner::Scanner(std::unique_ptr<std::istream> &&stream)
: stream_(std::move(stream)) {
Reset();
Expand Down
3 changes: 3 additions & 0 deletions paddle/fluid/recordio/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

#include <fstream>
#include <memory>
#include <string>

#include "paddle/fluid/recordio/chunk.h"

namespace paddle {
namespace recordio {

Expand Down
5 changes: 5 additions & 0 deletions paddle/fluid/recordio/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/recordio/writer.h"

#include <string>

#include "paddle/fluid/platform/enforce.h"

namespace paddle {
namespace recordio {

void Writer::Write(const std::string& record) {
cur_chunk_.Add(record);
if (cur_chunk_.NumRecords() >= max_num_records_in_chunk_) {
Expand Down
4 changes: 3 additions & 1 deletion paddle/fluid/recordio/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <string>

#include "paddle/fluid/recordio/chunk.h"
namespace paddle {
namespace recordio {
Expand Down
7 changes: 4 additions & 3 deletions paddle/fluid/recordio/writer_scanner_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "gtest/gtest.h"

#include <sstream>
#include <string>

#include "gtest/gtest.h"
#include "paddle/fluid/recordio/scanner.h"
#include "paddle/fluid/recordio/writer.h"

Expand Down Expand Up @@ -66,4 +67,4 @@ TEST(WriterScanner, TinyChunk) {
ASSERT_EQ(scanner.Next(), "DEFG");
ASSERT_FALSE(scanner.HasNext());
}
}
}

0 comments on commit bcb46f5

Please sign in to comment.