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

Function TEST

test/singa/test_csv.cc:31–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29using singa::Shape;
30using singa::Tensor;
31TEST(CSV, EncoderDecode) {
32 singa::CSVEncoder encoder;
33 singa::CSVDecoder decoder;
34
35 singa::DecoderConf decoder_conf;
36 decoder_conf.set_has_label(true);
37 decoder.Setup(decoder_conf);
38 EXPECT_EQ(true, decoder.has_label());
39
40 float in_data[] = {1.23f, 4.5f, 5.1f, 3.33f, 0.44f};
41 std::string in_str = "2, 1.23, 4.5, 5.1, 3.33, 0.44";
42 int in_label = 2;
43 size_t size = 5;
44
45 std::vector<Tensor> input;
46 Tensor data(Shape{size}, singa::kFloat32), label(Shape{1}, singa::kInt);
47 data.CopyDataFromHostPtr<float>(in_data, size);
48 label.CopyDataFromHostPtr<int>(&in_label, 1);
49 input.push_back(data);
50 input.push_back(label);
51
52 std::string value = encoder.Encode(input);
53 in_str.erase(std::remove(in_str.begin(), in_str.end(), ' '), in_str.end());
54 EXPECT_EQ(in_str, value);
55
56 std::vector<Tensor> output = decoder.Decode(value);
57 const auto* out_data = output.at(0).data<float>();
58 const auto* out_label = output.at(1).data<int>();
59 for (size_t i = 0; i < size; i++) EXPECT_EQ(in_data[i], out_data[i]);
60 EXPECT_EQ(in_label, out_label[0]);
61}

Callers

nothing calls this directly

Calls 6

has_labelMethod · 0.80
SetupMethod · 0.45
EncodeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected