MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / create_req

Function create_req

tools/cpp_examples/demo-client/src/ctr_prediction.cpp:93–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93int create_req(Request* req,
94 const std::vector<std::string>& data_list,
95 int start_index,
96 int batch_size) {
97 for (int i = 0; i < batch_size; ++i) {
98 CTRReqInstance* ins = req->add_instances();
99 if (!ins) {
100 LOG(ERROR) << "Failed create req instance";
101 return -1;
102 }
103
104 // add data
105 // avoid out of boundary
106 int cur_index = start_index + i;
107 if (cur_index >= data_list.size()) {
108 cur_index = cur_index % data_list.size();
109 }
110
111 std::vector<std::string> feature_list = split(data_list[cur_index], "\t");
112 for (int fi = 0; fi < dense_num; fi++) {
113 if (feature_list[fi] == "") {
114 ins->add_dense_ids(0.0);
115 } else {
116 float dense_id = std::stof(feature_list[fi]);
117 dense_id = (dense_id - cont_min[fi]) / cont_diff[fi];
118 ins->add_dense_ids(dense_id);
119 }
120 }
121 for (int fi = dense_num; fi < (dense_num + sparse_num); fi++) {
122 int64_t sparse_id =
123 hash(std::to_string(fi) + feature_list[fi]) % hash_dim;
124 if (sparse_id < 0) {
125 // diff between c++ and python
126 sparse_id += hash_dim;
127 }
128 ins->add_sparse_ids(sparse_id);
129 }
130 }
131 return 0;
132}
133
134void print_res(const Request& req,
135 const Response& res,

Callers 1

thread_workerFunction · 0.70

Calls 3

hashFunction · 0.85
splitFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected