提交 60857f49 编写于 作者: Y Yu Yang

Unify clang-format and add some missing clang-format

上级 5fb1b407
---
Language: Cpp
BasedOnStyle: Google
Standard: Cpp11
...
../framework/.clang-format
\ No newline at end of file
---
Language: Cpp
BasedOnStyle: Google
Standard: Cpp11
...
../framework/.clang-format
\ No newline at end of file
../framework/.clang-format
\ No newline at end of file
...@@ -169,8 +169,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -169,8 +169,7 @@ All parameter, weight, gradient are variables in Paddle.
py::return_value_policy::reference) py::return_value_policy::reference)
.def("find_var", &Scope::FindVar, py::return_value_policy::reference) .def("find_var", &Scope::FindVar, py::return_value_policy::reference)
.def(py::init<>()) .def(py::init<>())
.def("new_scope", .def("new_scope", [](Scope &self) -> Scope * { return &self.NewScope(); },
[](Scope &self) -> Scope * { return &self.NewScope(); },
py::return_value_policy::reference) py::return_value_policy::reference)
.def("drop_kids", &Scope::DropKids); .def("drop_kids", &Scope::DropKids);
...@@ -238,8 +237,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -238,8 +237,7 @@ All parameter, weight, gradient are variables in Paddle.
}) })
.def("infer_shape", &OperatorBase::InferShape) .def("infer_shape", &OperatorBase::InferShape)
.def("run", .def("run",
[](OperatorBase &self, [](OperatorBase &self, const Scope &scope,
const Scope &scope,
const platform::DeviceContext &dev_ctx) { const platform::DeviceContext &dev_ctx) {
self.Run(scope, dev_ctx); self.Run(scope, dev_ctx);
dev_ctx.Wait(); dev_ctx.Wait();
...@@ -267,10 +265,8 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -267,10 +265,8 @@ All parameter, weight, gradient are variables in Paddle.
retv->SetType("plain_net"); retv->SetType("plain_net");
return retv; return retv;
}) })
.def("append_op", .def("append_op", [](operators::NetOp &self,
[](operators::NetOp &self, const OperatorBase &op) { const OperatorBase &op) { self.AppendOp(op); })
self.AppendOp(op);
})
.def("complete_add_op", &operators::NetOp::CompleteAddOp) .def("complete_add_op", &operators::NetOp::CompleteAddOp)
.def("complete_add_op", [](std::shared_ptr<operators::NetOp> &self) { .def("complete_add_op", [](std::shared_ptr<operators::NetOp> &self) {
self->CompleteAddOp(); self->CompleteAddOp();
...@@ -290,9 +286,10 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -290,9 +286,10 @@ All parameter, weight, gradient are variables in Paddle.
auto rnn_op = OpRegistry::CreateOp(desc); auto rnn_op = OpRegistry::CreateOp(desc);
return static_cast<operators::RecurrentOp *>(rnn_op.release()); return static_cast<operators::RecurrentOp *>(rnn_op.release());
}) })
.def("set_stepnet", .def("set_stepnet", [](operators::RecurrentOp &self,
[](operators::RecurrentOp &self, const operators::NetOp &net) const operators::NetOp &net) -> void {
-> void { self.set_stepnet(net.Clone()); }); self.set_stepnet(net.Clone());
});
// cond_op // cond_op
py::class_<operators::CondOp, OperatorBase>(m, "CondOp") py::class_<operators::CondOp, OperatorBase>(m, "CondOp")
......
...@@ -63,11 +63,8 @@ struct CastToPyBufferImpl<true, I, ARGS...> { ...@@ -63,11 +63,8 @@ struct CastToPyBufferImpl<true, I, ARGS...> {
} }
return py::buffer_info( return py::buffer_info(
dst_tensor.mutable_data<CUR_TYPE>(dst_tensor.holder_->place()), dst_tensor.mutable_data<CUR_TYPE>(dst_tensor.holder_->place()),
sizeof(CUR_TYPE), sizeof(CUR_TYPE), py::format_descriptor<CUR_TYPE>::format(),
py::format_descriptor<CUR_TYPE>::format(), (size_t)framework::arity(dst_tensor.dims()), dims_outside, strides);
(size_t)framework::arity(dst_tensor.dims()),
dims_outside,
strides);
} else { } else {
constexpr bool less = I + 1 < std::tuple_size<std::tuple<ARGS...>>::value; constexpr bool less = I + 1 < std::tuple_size<std::tuple<ARGS...>>::value;
return CastToPyBufferImpl<less, I + 1, ARGS...>()(tensor); return CastToPyBufferImpl<less, I + 1, ARGS...>()(tensor);
...@@ -110,8 +107,8 @@ void PyCUDATensorSetFromArray( ...@@ -110,8 +107,8 @@ void PyCUDATensorSetFromArray(
self.Resize(framework::make_ddim(dims)); self.Resize(framework::make_ddim(dims));
auto *dst = self.mutable_data<T>(place); auto *dst = self.mutable_data<T>(place);
paddle::platform::GpuMemcpySync( paddle::platform::GpuMemcpySync(dst, array.data(), sizeof(T) * array.size(),
dst, array.data(), sizeof(T) * array.size(), cudaMemcpyHostToDevice); cudaMemcpyHostToDevice);
} }
#endif #endif
......
../framework/.clang-format
\ No newline at end of file
...@@ -30,7 +30,7 @@ namespace string { ...@@ -30,7 +30,7 @@ namespace string {
// its syntax is simple as it doesn't own/manage the string, it is // its syntax is simple as it doesn't own/manage the string, it is
// cheap to construct Pieces and pass them around. // cheap to construct Pieces and pass them around.
class Piece { class Piece {
public: public:
static const size_t npos = static_cast<size_t>(-1); static const size_t npos = static_cast<size_t>(-1);
// We provide non-explicit singleton constructors so users can // We provide non-explicit singleton constructors so users can
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
// Return a string that contains the copy of the referenced data. // Return a string that contains the copy of the referenced data.
std::string ToString() const { return std::string(data_, size_); } std::string ToString() const { return std::string(data_, size_); }
private: private:
const char* data_; const char* data_;
size_t size_; size_t size_;
......
...@@ -11,6 +11,6 @@ TEST(StringPrintf, StringPrintf) { ...@@ -11,6 +11,6 @@ TEST(StringPrintf, StringPrintf) {
long hour = 14; long hour = 14;
int min = 44; int min = 44;
EXPECT_EQ(std::string("Wednesday, July 27, 14:44"), EXPECT_EQ(std::string("Wednesday, July 27, 14:44"),
paddle::string::Sprintf( paddle::string::Sprintf("%s, %s %d, %.2d:%.2d", weekday, month, day,
"%s, %s %d, %.2d:%.2d", weekday, month, day, hour, min)); hour, min));
} }
...@@ -133,7 +133,7 @@ namespace detail { ...@@ -133,7 +133,7 @@ namespace detail {
// Test whether type T1 is convertible to type T2 // Test whether type T1 is convertible to type T2
template <typename T1, typename T2> template <typename T1, typename T2>
struct is_convertible { struct is_convertible {
private: private:
// two types of different size // two types of different size
struct fail { struct fail {
char dummy[2]; char dummy[2];
...@@ -146,7 +146,7 @@ private: ...@@ -146,7 +146,7 @@ private:
static succeed tryConvert(const T2 &); static succeed tryConvert(const T2 &);
static const T1 &makeT1(); static const T1 &makeT1();
public: public:
// Standard trick: the (...) version of tryConvert will be chosen from // Standard trick: the (...) version of tryConvert will be chosen from
// the overload set only if the version taking a T2 doesn't match. // the overload set only if the version taking a T2 doesn't match.
// Then we compare the sizes of the return types to check which // Then we compare the sizes of the return types to check which
...@@ -156,8 +156,7 @@ public: ...@@ -156,8 +156,7 @@ public:
// Format the value by casting to type fmtT. This default implementation // Format the value by casting to type fmtT. This default implementation
// should never be called. // should never be called.
template <typename T, template <typename T, typename fmtT,
typename fmtT,
bool convertible = is_convertible<T, fmtT>::value> bool convertible = is_convertible<T, fmtT>::value>
struct formatValueAsType { struct formatValueAsType {
static void invoke(std::ostream & /*out*/, const T & /*value*/) { assert(0); } static void invoke(std::ostream & /*out*/, const T & /*value*/) { assert(0); }
...@@ -227,11 +226,8 @@ TINYFORMAT_DEFINE_FORMAT_TRUNCATED_CSTR(char) ...@@ -227,11 +226,8 @@ TINYFORMAT_DEFINE_FORMAT_TRUNCATED_CSTR(char)
/// operator<< to format the type T, with special cases for the %c and %p /// operator<< to format the type T, with special cases for the %c and %p
/// conversions. /// conversions.
template <typename T> template <typename T>
inline void formatValue(std::ostream &out, inline void formatValue(std::ostream &out, const char * /*fmtBegin*/,
const char * /*fmtBegin*/, const char *fmtEnd, int ntrunc, const T &value) {
const char *fmtEnd,
int ntrunc,
const T &value) {
// The mess here is to support the %c and %p conversions: if these // The mess here is to support the %c and %p conversions: if these
// conversions are active we try to convert the type to a char or const // conversions are active we try to convert the type to a char or const
// void* respectively and format that instead of the value itself. For the // void* respectively and format that instead of the value itself. For the
...@@ -253,25 +249,22 @@ inline void formatValue(std::ostream &out, ...@@ -253,25 +249,22 @@ inline void formatValue(std::ostream &out,
} }
// Overloaded version for char types to support printing as an integer // Overloaded version for char types to support printing as an integer
#define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \ #define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \
inline void formatValue(std::ostream &out, \ inline void formatValue(std::ostream &out, const char * /*fmtBegin*/, \
const char * /*fmtBegin*/, \ const char *fmtEnd, int /**/, charType value) { \
const char *fmtEnd, \ switch (*(fmtEnd - 1)) { \
int /**/, \ case 'u': \
charType value) { \ case 'd': \
switch (*(fmtEnd - 1)) { \ case 'i': \
case 'u': \ case 'o': \
case 'd': \ case 'X': \
case 'i': \ case 'x': \
case 'o': \ out << static_cast<int>(value); \
case 'X': \ break; \
case 'x': \ default: \
out << static_cast<int>(value); \ out << value; \
break; \ break; \
default: \ } \
out << value; \
break; \
} \
} }
// per 3.9.1: char, signed char and unsigned char are all distinct types // per 3.9.1: char, signed char and unsigned char are all distinct types
TINYFORMAT_DEFINE_FORMATVALUE_CHAR(char) TINYFORMAT_DEFINE_FORMATVALUE_CHAR(char)
...@@ -468,7 +461,7 @@ namespace detail { ...@@ -468,7 +461,7 @@ namespace detail {
// each argument to be allocated as a homogenous array inside FormatList // each argument to be allocated as a homogenous array inside FormatList
// whereas a naive implementation based on inheritance does not. // whereas a naive implementation based on inheritance does not.
class FormatArg { class FormatArg {
public: public:
FormatArg() {} FormatArg() {}
template <typename T> template <typename T>
...@@ -477,22 +470,17 @@ public: ...@@ -477,22 +470,17 @@ public:
m_formatImpl(&formatImpl<T>), m_formatImpl(&formatImpl<T>),
m_toIntImpl(&toIntImpl<T>) {} m_toIntImpl(&toIntImpl<T>) {}
void format(std::ostream &out, void format(std::ostream &out, const char *fmtBegin, const char *fmtEnd,
const char *fmtBegin,
const char *fmtEnd,
int ntrunc) const { int ntrunc) const {
m_formatImpl(out, fmtBegin, fmtEnd, ntrunc, m_value); m_formatImpl(out, fmtBegin, fmtEnd, ntrunc, m_value);
} }
int toInt() const { return m_toIntImpl(m_value); } int toInt() const { return m_toIntImpl(m_value); }
private: private:
template <typename T> template <typename T>
static void formatImpl(std::ostream &out, static void formatImpl(std::ostream &out, const char *fmtBegin,
const char *fmtBegin, const char *fmtEnd, int ntrunc, const void *value) {
const char *fmtEnd,
int ntrunc,
const void *value) {
formatValue(out, fmtBegin, fmtEnd, ntrunc, *static_cast<const T *>(value)); formatValue(out, fmtBegin, fmtEnd, ntrunc, *static_cast<const T *>(value));
} }
...@@ -502,11 +490,8 @@ private: ...@@ -502,11 +490,8 @@ private:
} }
const void *m_value; const void *m_value;
void (*m_formatImpl)(std::ostream &out, void (*m_formatImpl)(std::ostream &out, const char *fmtBegin,
const char *fmtBegin, const char *fmtEnd, int ntrunc, const void *value);
const char *fmtEnd,
int ntrunc,
const void *value);
int (*m_toIntImpl)(const void *value); int (*m_toIntImpl)(const void *value);
}; };
...@@ -555,12 +540,10 @@ inline const char *printFormatStringLiteral(std::ostream &out, ...@@ -555,12 +540,10 @@ inline const char *printFormatStringLiteral(std::ostream &out,
// necessary to pull out variable width and precision . The function returns a // necessary to pull out variable width and precision . The function returns a
// pointer to the character after the end of the current format spec. // pointer to the character after the end of the current format spec.
inline const char *streamStateFromFormat(std::ostream &out, inline const char *streamStateFromFormat(std::ostream &out,
bool &spacePadPositive, bool &spacePadPositive, int &ntrunc,
int &ntrunc,
const char *fmtStart, const char *fmtStart,
const detail::FormatArg *formatters, const detail::FormatArg *formatters,
int &argIndex, int &argIndex, int numFormatters) {
int numFormatters) {
if (*fmtStart != '%') { if (*fmtStart != '%') {
TINYFORMAT_ERROR( TINYFORMAT_ERROR(
"tinyformat: Not enough conversion specifiers in format string"); "tinyformat: Not enough conversion specifiers in format string");
...@@ -736,10 +719,8 @@ inline const char *streamStateFromFormat(std::ostream &out, ...@@ -736,10 +719,8 @@ inline const char *streamStateFromFormat(std::ostream &out,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
inline void formatImpl(std::ostream &out, inline void formatImpl(std::ostream &out, const char *fmt,
const char *fmt, const detail::FormatArg *formatters, int numFormatters) {
const detail::FormatArg *formatters,
int numFormatters) {
// Saved stream state // Saved stream state
std::streamsize origWidth = out.width(); std::streamsize origWidth = out.width();
std::streamsize origPrecision = out.precision(); std::streamsize origPrecision = out.precision();
...@@ -751,13 +732,9 @@ inline void formatImpl(std::ostream &out, ...@@ -751,13 +732,9 @@ inline void formatImpl(std::ostream &out,
fmt = printFormatStringLiteral(out, fmt); fmt = printFormatStringLiteral(out, fmt);
bool spacePadPositive = false; bool spacePadPositive = false;
int ntrunc = -1; int ntrunc = -1;
const char *fmtEnd = streamStateFromFormat(out, const char *fmtEnd =
spacePadPositive, streamStateFromFormat(out, spacePadPositive, ntrunc, fmt, formatters,
ntrunc, argIndex, numFormatters);
fmt,
formatters,
argIndex,
numFormatters);
if (argIndex >= numFormatters) { if (argIndex >= numFormatters) {
// Check args remain after reading any variable width/precision // Check args remain after reading any variable width/precision
TINYFORMAT_ERROR("tinyformat: Not enough format arguments"); TINYFORMAT_ERROR("tinyformat: Not enough format arguments");
...@@ -806,15 +783,14 @@ inline void formatImpl(std::ostream &out, ...@@ -806,15 +783,14 @@ inline void formatImpl(std::ostream &out,
/// information has been stripped from the arguments, leaving just enough of a /// information has been stripped from the arguments, leaving just enough of a
/// common interface to perform formatting as required. /// common interface to perform formatting as required.
class FormatList { class FormatList {
public: public:
FormatList(detail::FormatArg *formatters, int N) FormatList(detail::FormatArg *formatters, int N)
: m_formatters(formatters), m_N(N) {} : m_formatters(formatters), m_N(N) {}
friend void vformat(std::ostream &out, friend void vformat(std::ostream &out, const char *fmt,
const char *fmt,
const FormatList &list); const FormatList &list);
private: private:
const detail::FormatArg *m_formatters; const detail::FormatArg *m_formatters;
int m_N; int m_N;
}; };
...@@ -827,7 +803,7 @@ namespace detail { ...@@ -827,7 +803,7 @@ namespace detail {
// Format list subclass with fixed storage to avoid dynamic allocation // Format list subclass with fixed storage to avoid dynamic allocation
template <int N> template <int N>
class FormatListN : public FormatList { class FormatListN : public FormatList {
public: public:
template <typename... Args> template <typename... Args>
FormatListN(const Args &... args) FormatListN(const Args &... args)
: FormatList(&m_formatterStore[0], N), : FormatList(&m_formatterStore[0], N),
...@@ -835,14 +811,14 @@ public: ...@@ -835,14 +811,14 @@ public:
static_assert(sizeof...(args) == N, "Number of args must be N"); static_assert(sizeof...(args) == N, "Number of args must be N");
} }
private: private:
FormatArg m_formatterStore[N]; FormatArg m_formatterStore[N];
}; };
// Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard // Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard
template <> template <>
class FormatListN<0> : public FormatList { class FormatListN<0> : public FormatList {
public: public:
FormatListN() : FormatList(0, 0) {} FormatListN() : FormatList(0, 0) {}
}; };
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
constexpr char kOutputString[] = "User Defined Output"; constexpr char kOutputString[] = "User Defined Output";
class UserDefinedClass { class UserDefinedClass {
public: public:
}; };
std::ostream& operator<<(std::ostream& s, const UserDefinedClass& ins) { std::ostream& operator<<(std::ostream& s, const UserDefinedClass& ins) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册