1515#include " paddle/fluid/distributed/table/common_sparse_table.h"
1616#include < sstream>
1717
18- #include " boost/lexical_cast.hpp"
1918#include " glog/logging.h"
2019#include " paddle/fluid/platform/enforce.h"
2120
@@ -50,8 +49,11 @@ void CommonSparseTable::ProcessALine(const std::vector<std::string>& columns,
5049 float v = 0.0 ;
5150
5251 try {
53- v = lexical_cast<float >(va);
54- } catch (boost::bad_lexical_cast& e) {
52+ v = std::stof (va);
53+ } catch (std::invalid_argument& e) {
54+ VLOG (0 ) << " id: " << id << " get unexpected value: " << va
55+ << " and be reset to: 0.0" ;
56+ } catch (std::out_of_range& e) {
5557 VLOG (0 ) << " id: " << id << " get unexpected value: " << va
5658 << " and be reset to: 0.0" ;
5759 }
@@ -131,7 +133,7 @@ int64_t CommonSparseTable::LoadFromText(
131133
132134 while (std::getline (file, line)) {
133135 auto values = paddle::string::split_string<std::string>(line, " \t " );
134- auto id = lexical_cast< uint64_t > (values[0 ]);
136+ auto id = std::stoull (values[0 ]);
135137
136138 if (id % pserver_num != pserver_id) {
137139 VLOG (3 ) << " will not load " << values[0 ] << " from " << valuepath
@@ -150,10 +152,9 @@ int64_t CommonSparseTable::LoadFromText(
150152 VALUE* value_instant = block->GetValue (id);
151153
152154 if (values.size () == 5 ) {
153- value_instant->count_ = lexical_cast<int >(values[1 ]);
154- value_instant->unseen_days_ = lexical_cast<int >(values[2 ]);
155- value_instant->is_entry_ =
156- static_cast <bool >(lexical_cast<int >(values[3 ]));
155+ value_instant->count_ = std::stoi (values[1 ]);
156+ value_instant->unseen_days_ = std::stoi (values[2 ]);
157+ value_instant->is_entry_ = static_cast <bool >(std::stoi (values[3 ]));
157158 }
158159
159160 std::vector<float *> block_values = block->Get (id, meta.names , meta.dims );
0 commit comments