diff --git a/paddle/CMakeLists.txt b/paddle/CMakeLists.txt index c7deba2ab475d3c4f2c95327af77af7031b591fd..a7b249d43bf3ad9924749d5e66618750f19d8bf7 100644 --- a/paddle/CMakeLists.txt +++ b/paddle/CMakeLists.txt @@ -11,7 +11,6 @@ if(MOBILE_INFERENCE) else() add_subdirectory(pserver) add_subdirectory(trainer) - add_subdirectory(string) add_subdirectory(scripts) if(WITH_C_API) diff --git a/paddle/fluid/CMakeLists.txt b/paddle/fluid/CMakeLists.txt index a6b4191518c45d0579f800ecb901dcd9667e17d5..7405ef17d3e01e4837412c96385e13a9e605a75b 100644 --- a/paddle/fluid/CMakeLists.txt +++ b/paddle/fluid/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(framework) add_subdirectory(operators) add_subdirectory(pybind) add_subdirectory(inference) +add_subdirectory(string) diff --git a/paddle/fluid/framework/init.cc b/paddle/fluid/framework/init.cc index cb2d740d8609210064a06cccc5d45c84275e9709..ad806a8cd791bc164d974d21aec92beff1f8106f 100644 --- a/paddle/fluid/framework/init.cc +++ b/paddle/fluid/framework/init.cc @@ -20,7 +20,7 @@ limitations under the License. */ #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/place.h" -#include "paddle/string/piece.h" +#include "paddle/fluid/string/piece.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/framework/scope.cc b/paddle/fluid/framework/scope.cc index 6006ed16bd4a9aece5772bad58dc75c8b0847206..91a8617d6615d31e1c7cfe1bc5457dd69dbf31f7 100644 --- a/paddle/fluid/framework/scope.cc +++ b/paddle/fluid/framework/scope.cc @@ -18,7 +18,7 @@ limitations under the License. */ #include // for call_once #include "glog/logging.h" #include "paddle/fluid/framework/threadpool.h" -#include "paddle/string/printf.h" +#include "paddle/fluid/string/printf.h" DEFINE_bool(benchmark, false, "Doing memory benchmark. It will make deleting scope synchronized, " diff --git a/paddle/fluid/operators/listen_and_serv_op.cc b/paddle/fluid/operators/listen_and_serv_op.cc index c456c692eea611a25636035992ff00d67df6ef97..3730ae161fdf729272e911500fe7f38f99d05ad2 100644 --- a/paddle/fluid/operators/listen_and_serv_op.cc +++ b/paddle/fluid/operators/listen_and_serv_op.cc @@ -27,7 +27,7 @@ limitations under the License. */ #include "paddle/fluid/operators/detail/grpc_server.h" #include "paddle/fluid/operators/detail/sendrecvop_utils.h" #include "paddle/fluid/operators/detail/simple_block_queue.h" -#include "paddle/string/printf.h" +#include "paddle/fluid/string/printf.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/operators/send_recv_op_test.cc b/paddle/fluid/operators/send_recv_op_test.cc index 716f687044a85d46676141ee125baf398e9e695d..37a3d246d713adb68ffa20e8b2faad32843b1eaa 100644 --- a/paddle/fluid/operators/send_recv_op_test.cc +++ b/paddle/fluid/operators/send_recv_op_test.cc @@ -22,7 +22,7 @@ limitations under the License. */ #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/operators/math/math_function.h" #include "paddle/fluid/operators/math/selected_rows_functor.h" -#include "paddle/string/printf.h" +#include "paddle/fluid/string/printf.h" USE_NO_KERNEL_OP(send); USE_NO_KERNEL_OP(listen_and_serv); diff --git a/paddle/fluid/platform/cpu_info_test.cc b/paddle/fluid/platform/cpu_info_test.cc index d1fdba13b80629902faf2bcebb646572b36b459e..046758c594ff59ade06ae9904bb67b8418a539fe 100644 --- a/paddle/fluid/platform/cpu_info_test.cc +++ b/paddle/fluid/platform/cpu_info_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "paddle/fluid/platform/cpu_info.h" -#include "paddle/string/printf.h" +#include "paddle/fluid/string/printf.h" #include #include diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index b22893c0a56f39347894924b3cd6ea64180aa8b6..86e1792801598793f4963f70b4e4c927a9d71893 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -23,8 +23,8 @@ limitations under the License. */ #include #include "paddle/fluid/platform/macros.h" -#include "paddle/string/printf.h" -#include "paddle/string/to_string.h" +#include "paddle/fluid/string/printf.h" +#include "paddle/fluid/string/to_string.h" #ifdef __GNUC__ #include // for __cxa_demangle diff --git a/paddle/fluid/platform/enforce_test.cc b/paddle/fluid/platform/enforce_test.cc index 896a9a04eca80f22bebf87859d277458d9bdb092..baa34a5c7b453cf4e142147b22515e08d6ea7127 100644 --- a/paddle/fluid/platform/enforce_test.cc +++ b/paddle/fluid/platform/enforce_test.cc @@ -15,7 +15,7 @@ limitations under the License. */ #include "gtest/gtest.h" #include "paddle/fluid/platform/enforce.h" -#include "paddle/string/piece.h" +#include "paddle/fluid/string/piece.h" using StringPiece = paddle::string::Piece; using paddle::string::HasPrefix; diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 8924aabd17b18504a863990e1196e664905bbb52..85a6700a61405b2e3b40455fe96b54e810ff86b5 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -35,7 +35,7 @@ limitations under the License. */ #include "paddle/fluid/pybind/exception.h" #include "paddle/fluid/pybind/pybind.h" #include "paddle/fluid/pybind/tensor_py.h" -#include "paddle/string/to_string.h" +#include "paddle/fluid/string/to_string.h" #ifdef PADDLE_WITH_CUDA #include "paddle/fluid/operators/nccl/nccl_gpu_common.h" diff --git a/paddle/string/.clang-format b/paddle/fluid/string/.clang-format similarity index 100% rename from paddle/string/.clang-format rename to paddle/fluid/string/.clang-format diff --git a/paddle/string/CMakeLists.txt b/paddle/fluid/string/CMakeLists.txt similarity index 100% rename from paddle/string/CMakeLists.txt rename to paddle/fluid/string/CMakeLists.txt diff --git a/paddle/string/piece.cc b/paddle/fluid/string/piece.cc similarity index 99% rename from paddle/string/piece.cc rename to paddle/fluid/string/piece.cc index 330ca5f0155e92e34563ca16fffa482502428fda..560413dff1f0e41789275701fd6c61394e95e13c 100644 --- a/paddle/string/piece.cc +++ b/paddle/fluid/string/piece.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/string/piece.h" +#include "piece.h" #include diff --git a/paddle/string/piece.h b/paddle/fluid/string/piece.h similarity index 99% rename from paddle/string/piece.h rename to paddle/fluid/string/piece.h index dcef9791a70884eed04078bf9f97be9617e9d2b0..f2bb6b2c76164fbe63a9b53ec41385014f240ffd 100644 --- a/paddle/string/piece.h +++ b/paddle/fluid/string/piece.h @@ -28,7 +28,7 @@ namespace string { // its syntax is simple as it doesn't own/manage the string, it is // cheap to construct Pieces and pass them around. class Piece { -public: + public: static const size_t npos = static_cast(-1); // We provide non-explicit singleton constructors so users can @@ -55,7 +55,7 @@ public: // Return a string that contains the copy of the referenced data. std::string ToString() const { return std::string(data_, size_); } -private: + private: const char* data_; size_t size_; diff --git a/paddle/string/piece_test.cc b/paddle/fluid/string/piece_test.cc similarity index 99% rename from paddle/string/piece_test.cc rename to paddle/fluid/string/piece_test.cc index 250f26d61f8efe49861a78b83f944fa06fa5ec46..fc17d315b9df99374bb3a7b0a94e385a4abb7b5e 100644 --- a/paddle/string/piece_test.cc +++ b/paddle/fluid/string/piece_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/string/piece.h" +#include "paddle/fluid/string/piece.h" #include diff --git a/paddle/string/printf.h b/paddle/fluid/string/printf.h similarity index 97% rename from paddle/string/printf.h rename to paddle/fluid/string/printf.h index 03809d22092012c7815eb6a89b9fb8bc9eed549b..b55ae21b87ee6a3d158812e5ff872a03288abd20 100644 --- a/paddle/string/printf.h +++ b/paddle/fluid/string/printf.h @@ -71,7 +71,7 @@ #include #include -#include "paddle/string/tinyformat/tinyformat.h" // https://github.com/c42f/tinyformat +#include "tinyformat/tinyformat.h" // https://github.com/c42f/tinyformat namespace paddle { namespace string { diff --git a/paddle/string/printf_test.cc b/paddle/fluid/string/printf_test.cc similarity index 85% rename from paddle/string/printf_test.cc rename to paddle/fluid/string/printf_test.cc index 9815f29bdd82df9062dd5cacf9c3121bb65e3be9..6ca59bdefdbe2b23b49c844e893adb939c3d5a6f 100644 --- a/paddle/string/printf_test.cc +++ b/paddle/fluid/string/printf_test.cc @@ -11,7 +11,7 @@ // 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/string/printf.h" +#include "printf.h" #include @@ -24,6 +24,6 @@ TEST(StringPrintf, StringPrintf) { long hour = 14; int min = 44; EXPECT_EQ(std::string("Wednesday, July 27, 14:44"), - paddle::string::Sprintf( - "%s, %s %d, %.2d:%.2d", weekday, month, day, hour, min)); + paddle::string::Sprintf("%s, %s %d, %.2d:%.2d", weekday, month, day, + hour, min)); } diff --git a/paddle/string/tinyformat/tinyformat.h b/paddle/fluid/string/tinyformat/tinyformat.h similarity index 92% rename from paddle/string/tinyformat/tinyformat.h rename to paddle/fluid/string/tinyformat/tinyformat.h index 270198dc52c14175f7ab91395668a7828fe2f075..d1a2c47f1a9f258aefbdcce88513e05dda308fa0 100644 --- a/paddle/string/tinyformat/tinyformat.h +++ b/paddle/fluid/string/tinyformat/tinyformat.h @@ -147,7 +147,7 @@ namespace detail { // Test whether type T1 is convertible to type T2 template struct is_convertible { -private: + private: // two types of different size struct fail { char dummy[2]; @@ -160,7 +160,7 @@ private: static succeed tryConvert(const T2 &); static const T1 &makeT1(); -public: + public: // Standard trick: the (...) version of tryConvert will be chosen from // 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 @@ -170,8 +170,7 @@ public: // Format the value by casting to type fmtT. This default implementation // should never be called. -template ::value> struct formatValueAsType { static void invoke(std::ostream & /*out*/, const T & /*value*/) { assert(0); } @@ -241,11 +240,8 @@ TINYFORMAT_DEFINE_FORMAT_TRUNCATED_CSTR(char) /// operator<< to format the type T, with special cases for the %c and %p /// conversions. template -inline void formatValue(std::ostream &out, - const char * /*fmtBegin*/, - const char *fmtEnd, - int ntrunc, - const T &value) { +inline void formatValue(std::ostream &out, const char * /*fmtBegin*/, + const char *fmtEnd, int ntrunc, const T &value) { // 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 // void* respectively and format that instead of the value itself. For the @@ -267,25 +263,22 @@ inline void formatValue(std::ostream &out, } // Overloaded version for char types to support printing as an integer -#define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \ - inline void formatValue(std::ostream &out, \ - const char * /*fmtBegin*/, \ - const char *fmtEnd, \ - int /**/, \ - charType value) { \ - switch (*(fmtEnd - 1)) { \ - case 'u': \ - case 'd': \ - case 'i': \ - case 'o': \ - case 'X': \ - case 'x': \ - out << static_cast(value); \ - break; \ - default: \ - out << value; \ - break; \ - } \ +#define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \ + inline void formatValue(std::ostream &out, const char * /*fmtBegin*/, \ + const char *fmtEnd, int /**/, charType value) { \ + switch (*(fmtEnd - 1)) { \ + case 'u': \ + case 'd': \ + case 'i': \ + case 'o': \ + case 'X': \ + case 'x': \ + out << static_cast(value); \ + break; \ + default: \ + out << value; \ + break; \ + } \ } // per 3.9.1: char, signed char and unsigned char are all distinct types TINYFORMAT_DEFINE_FORMATVALUE_CHAR(char) @@ -482,7 +475,7 @@ namespace detail { // each argument to be allocated as a homogenous array inside FormatList // whereas a naive implementation based on inheritance does not. class FormatArg { -public: + public: FormatArg() {} template @@ -491,22 +484,17 @@ public: m_formatImpl(&formatImpl), m_toIntImpl(&toIntImpl) {} - void format(std::ostream &out, - const char *fmtBegin, - const char *fmtEnd, + void format(std::ostream &out, const char *fmtBegin, const char *fmtEnd, int ntrunc) const { m_formatImpl(out, fmtBegin, fmtEnd, ntrunc, m_value); } int toInt() const { return m_toIntImpl(m_value); } -private: + private: template - static void formatImpl(std::ostream &out, - const char *fmtBegin, - const char *fmtEnd, - int ntrunc, - const void *value) { + static void formatImpl(std::ostream &out, const char *fmtBegin, + const char *fmtEnd, int ntrunc, const void *value) { formatValue(out, fmtBegin, fmtEnd, ntrunc, *static_cast(value)); } @@ -516,11 +504,8 @@ private: } const void *m_value; - void (*m_formatImpl)(std::ostream &out, - const char *fmtBegin, - const char *fmtEnd, - int ntrunc, - const void *value); + void (*m_formatImpl)(std::ostream &out, const char *fmtBegin, + const char *fmtEnd, int ntrunc, const void *value); int (*m_toIntImpl)(const void *value); }; @@ -569,12 +554,10 @@ inline const char *printFormatStringLiteral(std::ostream &out, // necessary to pull out variable width and precision . The function returns a // pointer to the character after the end of the current format spec. inline const char *streamStateFromFormat(std::ostream &out, - bool &spacePadPositive, - int &ntrunc, + bool &spacePadPositive, int &ntrunc, const char *fmtStart, const detail::FormatArg *formatters, - int &argIndex, - int numFormatters) { + int &argIndex, int numFormatters) { if (*fmtStart != '%') { TINYFORMAT_ERROR( "tinyformat: Not enough conversion specifiers in format string"); @@ -750,10 +733,8 @@ inline const char *streamStateFromFormat(std::ostream &out, } //------------------------------------------------------------------------------ -inline void formatImpl(std::ostream &out, - const char *fmt, - const detail::FormatArg *formatters, - int numFormatters) { +inline void formatImpl(std::ostream &out, const char *fmt, + const detail::FormatArg *formatters, int numFormatters) { // Saved stream state std::streamsize origWidth = out.width(); std::streamsize origPrecision = out.precision(); @@ -765,13 +746,9 @@ inline void formatImpl(std::ostream &out, fmt = printFormatStringLiteral(out, fmt); bool spacePadPositive = false; int ntrunc = -1; - const char *fmtEnd = streamStateFromFormat(out, - spacePadPositive, - ntrunc, - fmt, - formatters, - argIndex, - numFormatters); + const char *fmtEnd = + streamStateFromFormat(out, spacePadPositive, ntrunc, fmt, formatters, + argIndex, numFormatters); if (argIndex >= numFormatters) { // Check args remain after reading any variable width/precision TINYFORMAT_ERROR("tinyformat: Not enough format arguments"); @@ -820,15 +797,14 @@ inline void formatImpl(std::ostream &out, /// information has been stripped from the arguments, leaving just enough of a /// common interface to perform formatting as required. class FormatList { -public: + public: FormatList(detail::FormatArg *formatters, int N) : m_formatters(formatters), m_N(N) {} - friend void vformat(std::ostream &out, - const char *fmt, + friend void vformat(std::ostream &out, const char *fmt, const FormatList &list); -private: + private: const detail::FormatArg *m_formatters; int m_N; }; @@ -841,7 +817,7 @@ namespace detail { // Format list subclass with fixed storage to avoid dynamic allocation template class FormatListN : public FormatList { -public: + public: template FormatListN(const Args &... args) : FormatList(&m_formatterStore[0], N), @@ -849,14 +825,14 @@ public: static_assert(sizeof...(args) == N, "Number of args must be N"); } -private: + private: FormatArg m_formatterStore[N]; }; // Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard template <> class FormatListN<0> : public FormatList { -public: + public: FormatListN() : FormatList(0, 0) {} }; diff --git a/paddle/string/to_string.h b/paddle/fluid/string/to_string.h similarity index 100% rename from paddle/string/to_string.h rename to paddle/fluid/string/to_string.h diff --git a/paddle/string/to_string_test.cc b/paddle/fluid/string/to_string_test.cc similarity index 96% rename from paddle/string/to_string_test.cc rename to paddle/fluid/string/to_string_test.cc index 05650ee8f14f2b050dec07803cdbfa3893eb79d7..1e890f572eb842eba49b859807083f4e5af57df8 100644 --- a/paddle/string/to_string_test.cc +++ b/paddle/fluid/string/to_string_test.cc @@ -12,12 +12,12 @@ 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/string/to_string.h" +#include "to_string.h" #include constexpr char kOutputString[] = "User Defined Output"; class UserDefinedClass { -public: + public: }; std::ostream& operator<<(std::ostream& s, const UserDefinedClass& ins) {