Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: cpplint code style #2888

Merged
merged 4 commits into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmake/cpplint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ set(IGNORE_PATTERN
.*cblas\\.h.*
.*\\.pb\\.txt
.*LtrDataProvider.*
.*MultiDataProvider.*)
.*MultiDataProvider.*
.*pb.*)

# add_style_check_target
#
Expand All @@ -52,14 +53,13 @@ macro(add_style_check_target TARGET_NAME)
endif()
endforeach()
if(LINT MATCHES ON)
# cpplint code style
get_filename_component(base_filename ${filename} NAME)
set(CUR_GEN ${CMAKE_CURRENT_BINARY_DIR}/${base_filename}.cpplint)
add_custom_command(OUTPUT ${CUR_GEN}
PRE_BUILD
COMMAND env ${py_env} "${PYTHON_EXECUTABLE}" "${PROJ_ROOT}/paddle/scripts/cpplint.py"
"--filter=${STYLE_FILTER}"
"--write-success=${CUR_GEN}" ${filename}
DEPENDS ${filename}
add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD
COMMAND "${PYTHON_EXECUTABLE}" "${PROJ_ROOT}/paddle/scripts/cpplint.py"
"--filter=${STYLE_FILTER}"
"--write-success=${CUR_GEN}" ${filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
endforeach()
Expand Down
4 changes: 4 additions & 0 deletions cmake/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ function(cc_library TARGET_NAME)
add_dependencies(${TARGET_NAME} ${cc_library_DEPS})
target_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
endif()

# cpplint code style
add_style_check_target(${TARGET_NAME} ${cc_library_SRCS})

else(cc_library_SRCS)
if (cc_library_DEPS)
merge_static_libs(${TARGET_NAME} ${cc_library_DEPS})
Expand Down
42 changes: 28 additions & 14 deletions paddle/framework/ddim.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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. */

#include "paddle/framework/ddim.h"

namespace paddle {
namespace framework {

///@cond HIDDEN
/// @cond HIDDEN

template <int i>
Dim<i> make_dim(const int* d) {
Expand Down Expand Up @@ -50,7 +64,7 @@ void make_ddim(DDim& ddim, const int* dims, int n) {
}
}

///@endcond
/// @endcond

DDim make_ddim(std::initializer_list<int> dims) {
DDim result(make_dim(0));
Expand All @@ -64,11 +78,11 @@ DDim make_ddim(const std::vector<int>& dims) {
return result;
}

///@cond HIDDEN
/// @cond HIDDEN
// XXX For some reason, putting this in an anonymous namespace causes errors
class DynamicMutableIndexer : public boost::static_visitor<int&> {
public:
DynamicMutableIndexer(int idx) : idx_(idx) {}
explicit DynamicMutableIndexer(int idx) : idx_(idx) {}

template <int D>
int& operator()(Dim<D>& dim) const {
Expand All @@ -81,7 +95,7 @@ class DynamicMutableIndexer : public boost::static_visitor<int&> {

class DynamicConstIndexer : public boost::static_visitor<int> {
public:
DynamicConstIndexer(int idx) : idx_(idx) {}
explicit DynamicConstIndexer(int idx) : idx_(idx) {}

template <int D>
int operator()(const Dim<D>& dim) const {
Expand All @@ -92,7 +106,7 @@ class DynamicConstIndexer : public boost::static_visitor<int> {
int idx_;
};

///@endcond
/// @endcond

int& DDim::operator[](int idx) {
return boost::apply_visitor(DynamicMutableIndexer(idx), var);
Expand Down Expand Up @@ -155,11 +169,11 @@ int get(const DDim& ddim, int idx) { return ddim[idx]; }

void set(DDim& ddim, int idx, int value) { ddim[idx] = value; }

///@cond HIDDEN
/// @cond HIDDEN
struct VectorizeVisitor : public boost::static_visitor<> {
std::vector<int>& vector;

VectorizeVisitor(std::vector<int>& v) : vector(v) {}
explicit VectorizeVisitor(std::vector<int>& v) : vector(v) {}

template <typename T>
void operator()(const T& t) {
Expand All @@ -169,7 +183,7 @@ struct VectorizeVisitor : public boost::static_visitor<> {

void operator()(const Dim<1>& t) { vector.push_back(t.head); }
};
///@endcond
/// @endcond

std::vector<int> vectorize(const DDim& ddim) {
std::vector<int> result;
Expand All @@ -187,7 +201,7 @@ ssize_t product(const DDim& ddim) {
return result;
}

///\cond HIDDEN
/// \cond HIDDEN

struct ArityVisitor : boost::static_visitor<int> {
template <int D>
Expand All @@ -196,23 +210,23 @@ struct ArityVisitor : boost::static_visitor<int> {
}
};

///\endcond
/// \endcond

int arity(const DDim& d) { return boost::apply_visitor(ArityVisitor(), d); }

///\cond HIDDEN
/// \cond HIDDEN

struct DDimPrinter : boost::static_visitor<void> {
std::ostream& os;
DDimPrinter(std::ostream& os_) : os(os_) {}
explicit DDimPrinter(std::ostream& os_) : os(os_) {}

template <typename T>
void operator()(const T& t) {
os << t;
}
};

///\endcond
/// \endcond

std::ostream& operator<<(std::ostream& os, const DDim& ddim) {
DDimPrinter printer(os);
Expand Down
2 changes: 1 addition & 1 deletion paddle/framework/ddim.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct DDim {
DDim() : var(Dim<1>()) {}

template <int D>
DDim(const Dim<D>& in) : var(in) {}
explicit DDim(const Dim<D>& in) : var(in) {}

template <int D>
DDim& operator=(const Dim<D>& in) {
Expand Down
16 changes: 16 additions & 0 deletions paddle/framework/net.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/

#include "paddle/framework/net.h"

namespace paddle {
Expand Down
16 changes: 15 additions & 1 deletion paddle/framework/op_registry.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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. */

#include <paddle/framework/op_registry.h>

namespace paddle {
Expand Down Expand Up @@ -33,4 +47,4 @@ void AttrTypeHelper::SetAttrType<std::vector<std::string>>(AttrProto* attr) {
attr->set_type(paddle::framework::AttrType::STRINGS);
}
} // namespace framework
} // namespace paddle
} // namespace paddle
2 changes: 1 addition & 1 deletion paddle/framework/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ std::string OperatorBase::DebugString() const {
}

} // namespace framework
} // namespace paddle
} // namespace paddle
9 changes: 3 additions & 6 deletions paddle/function/GemmConvOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ class GemmConvFunction : public ConvFunctionBase {
ConvFunctionBase::init(config);
}

virtual void check(const BufferArgs& inputs,
const BufferArgs& outputs) override {
void check(const BufferArgs& inputs, const BufferArgs& outputs) override {
const TensorShape& input = inputs[0].shape();
const TensorShape& filter = inputs[1].shape();
const TensorShape& output = outputs[0].shape();
Expand Down Expand Up @@ -217,8 +216,7 @@ class GemmConvGradInputFunction : public ConvFunctionBase {
ConvFunctionBase::init(config);
}

virtual void check(const BufferArgs& inputs,
const BufferArgs& outputs) override {
void check(const BufferArgs& inputs, const BufferArgs& outputs) override {
const TensorShape& output = inputs[0].shape();
const TensorShape& filter = inputs[1].shape();
const TensorShape& input = outputs[0].shape();
Expand Down Expand Up @@ -311,8 +309,7 @@ class GemmConvGradFilterFunction : public ConvFunctionBase {
ConvFunctionBase::init(config);
}

virtual void check(const BufferArgs& inputs,
const BufferArgs& outputs) override {
void check(const BufferArgs& inputs, const BufferArgs& outputs) override {
const TensorShape& output = inputs[0].shape();
const TensorShape& input = inputs[1].shape();
const TensorShape& filter = outputs[0].shape();
Expand Down
3 changes: 1 addition & 2 deletions paddle/function/NaiveConvOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class NaiveConvFunction : public ConvFunctionBase {
ConvFunctionBase::init(config);
}

virtual void check(const BufferArgs& inputs,
const BufferArgs& outputs) override {
void check(const BufferArgs& inputs, const BufferArgs& outputs) override {
const TensorShape& input = inputs[0].shape();
const TensorShape& filter = inputs[1].shape();
const TensorShape& output = outputs[0].shape();
Expand Down
2 changes: 1 addition & 1 deletion paddle/gserver/gradientmachines/NeuralNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class SubnetEvaluator : public CombinedEvaluator {
: layerName_(layerName) {
addEvaluator(std::move(evaluator));
}
virtual void eval(const NeuralNetwork& nn) override {
void eval(const NeuralNetwork& nn) override {
const LayerPtr& layer = nn.getLayer(layerName_);
CHECK(layer) << "Nonexisted layer: " << layerName_ << " in submodel "
<< nn.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void lenToStarts(std::vector<int>& starts) {
}
starts.back() = pos;
}
}
} // namespace

void RecurrentGradientMachine::calcSequenceStartPositions() {
std::vector<int> starts(commonSeqInfo_.size() + 1);
Expand Down
2 changes: 1 addition & 1 deletion paddle/gserver/layers/AgentLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void copyElements(const IVector& srcVec,
dest[index[i]] = src[i];
}
}
}
} // namespace

void GatherAgentLayer::forwardIds(PassType passType) {
IVectorPtr realId = realLayers_[0]->getOutputLabel();
Expand Down
6 changes: 3 additions & 3 deletions paddle/memory/detail/memory_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ MemoryBlock* MemoryBlock::metadata() const {
reinterpret_cast<const Metadata*>(this) - 1));
}

} // detail
} // memory
} // paddle
} // namespace detail
} // namespace memory
} // namespace paddle
2 changes: 0 additions & 2 deletions paddle/memory/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License. */
#include "paddle/memory/detail/system_allocator.h"
#include "paddle/platform/assert.h"

#include <boost/variant.hpp>

namespace paddle {
namespace memory {

Expand Down
18 changes: 16 additions & 2 deletions paddle/operators/add_op.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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. */

#include <paddle/framework/op_registry.h>
#include <paddle/framework/tensor.h>
#include <paddle/operators/add_op.h>
Expand Down Expand Up @@ -36,9 +50,9 @@ The equation is: Out = X + Y
)DOC");
}
};
} // namespace op
} // namespace operators
} // namespace paddle

REGISTER_OP(add_two, paddle::operators::AddOp, paddle::operators::AddOpMaker);
REGISTER_OP_CPU_KERNEL(
add_two, ::paddle::operators::AddKernel<::paddle::platform::CPUPlace>);
add_two, ::paddle::operators::AddKernel<::paddle::platform::CPUPlace>);
Loading