MCPcopy Create free account
hub / github.com/apache/singa / Decode

Method Decode

src/io/csv_decoder.cc:27–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace singa {
26
27std::vector<Tensor> CSVDecoder::Decode(std::string value) {
28 std::vector<Tensor> output;
29 std::stringstream ss;
30 ss.str(value);
31 int l = 0;
32 if (has_label_ == true)
33 ss >> l;
34 std::string str;
35 float d[kMaxCSVBufSize];
36 int size = 0;
37 while (std::getline(ss, str, ',')) {
38 float temp;
39 if (std::stringstream(str) >> temp) {
40 CHECK_LE(size, kMaxCSVBufSize - 1);
41 d[size++] = temp;
42 }
43 }
44
45 Tensor data(Shape {static_cast<size_t>(size)}, kFloat32);
46 data.CopyDataFromHostPtr(d, size);
47 output.push_back(data);
48 if (has_label_ == true) {
49 Tensor label(Shape {1}, kInt);
50 label.CopyDataFromHostPtr(&l, 1);
51 output.push_back(label);
52 }
53 return output;
54}
55} // namespace singa

Callers 4

TESTFunction · 0.45
TESTFunction · 0.45
ReadMeanMethod · 0.45
DecodeTransformMethod · 0.45

Calls 1

CopyDataFromHostPtrMethod · 0.45

Tested by 2

TESTFunction · 0.36
TESTFunction · 0.36