MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / loadProblem

Method loadProblem

ml/src/svm_wrapper.cpp:270–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270bool
271pcl::SVM::loadProblem(const char* filename, svm_problem& prob)
272{
273 FILE* fp = fopen(filename, "re");
274 svm_node* x_space_;
275 char* endptr;
276 char *idx, *val, *label;
277
278 if (fp == nullptr) {
279 PCL_ERROR(
280 "[pcl::%s] Can't open input file %s.\n", getClassName().c_str(), filename);
281 return false;
282 }
283
284 int elements = 0;
285 prob.l = 0;
286
287 line_ = Malloc(char, max_line_len_);
288
289 // readline function writes one line in var. "line_"
290 while (readline(fp) != nullptr) {
291 // "\t" cuts the tab or space.
292 // strtok splits the string into tokens
293 strtok(line_, " \t"); // label
294 ++elements;
295 // features
296
297 while (true) {
298 // split the next element
299 char* p = strtok(nullptr, " \t");
300
301 if (p == nullptr || *p == '\n') // check '\n' as ' ' may be after the last feature
302 break;
303
304 ++elements;
305 }
306 ++elements; // contains the number of elements in the string
307 ++prob.l; // number op
308 }
309
310 rewind(fp); // returns to the top pos of fp
311
312 prob.y = Malloc(double, prob.l);
313 prob.x = Malloc(struct svm_node*, prob.l);
314 x_space_ = Malloc(struct svm_node, elements);
315
316 int max_index = 0;
317 int j = 0;
318 bool isUnlabelled = false;
319
320 for (int i = 0; i < prob.l; i++) {
321 int inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel
322 // has <index> start from 0
323 // read one line in the file
324 readline(fp);
325 prob.x[i] = &x_space_[j];
326
327 if (!isUnlabelled) {

Callers

nothing calls this directly

Calls 2

readlineFunction · 0.85
getClassNameFunction · 0.50

Tested by

no test coverage detected