From 1e30c41e7be026a7702ecd4db1ee031de7d5d0b6 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Fri, 20 Apr 2018 11:54:38 +0800 Subject: [PATCH] add split string --- .../operators/async_listen_and_serv_op.cc | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/async_listen_and_serv_op.cc b/paddle/fluid/operators/async_listen_and_serv_op.cc index bdb20240f6..14d9121eff 100644 --- a/paddle/fluid/operators/async_listen_and_serv_op.cc +++ b/paddle/fluid/operators/async_listen_and_serv_op.cc @@ -24,6 +24,24 @@ limitations under the License. */ namespace paddle { namespace operators { +static void split(const std::string &str, char sep, + std::vector *pieces) { + pieces->clear(); + if (str.empty()) { + return; + } + size_t pos = 0; + size_t next = str.find(sep, pos); + while (next != std::string::npos) { + pieces->push_back(str.substr(pos, next - pos)); + pos = next + 1; + next = str.find(sep, pos); + } + if (!str.substr(pos).empty()) { + pieces->push_back(str.substr(pos)); + } +} + void RunServer(std::shared_ptr service) { service->RunAsyncUpdate(); VLOG(4) << "RunServer thread end"; @@ -74,7 +92,7 @@ void AsyncListenAndServOp::RunImpl(const framework::Scope &scope, auto grad_map_str = Attr>("grad_map"); for (auto &grad_and_id : grad_map_str) { std::vector pieces; - paddle::str::split(grad_and_id, ' ', &pieces); + split(grad_and_id, ' ', &pieces); PADDLE_ENFORCE_EQ(pieces.size(), 2); PADDLE_ENFORCE_EQ(grad_to_id.count(pieces[0]), 0); int block_id = std::stoi(pieces[1]); -- GitLab