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

Function ForwardSliceColumnTest

test/singa/test_slice.cc:71–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void ForwardSliceColumnTest(std::shared_ptr<singa::Device> dev) {
72 size_t a = 2u, b = 1u, c = 3u;
73 singa::LayerConf conf;
74 conf.set_type("singa_slice");
75 auto slice_conf = conf.mutable_slice_conf();
76 slice_conf->set_axis(1);
77 slice_conf->add_slice_point(a);
78 singa::Slice layer;
79 layer.Setup({a + b}, conf);
80 layer.ToDevice(dev);
81
82 singa::Tensor t({c, a + b}, dev);
83 singa::Uniform(-1.f, 1.f, &t);
84 auto out = layer.Forward(singa::kTrain, {t});
85 EXPECT_EQ(out.size(), 2u);
86
87 t.ToHost();
88 const float* tptr = t.data<float>();
89
90 out[0].ToHost();
91 const float* outa = out[0].data<float>();
92 for (size_t i = 0; i < c; i++)
93 for (size_t j = 0; j < a; j++)
94 EXPECT_FLOAT_EQ(outa[i * a + j], tptr[i * (a + b) + j]);
95 out[1].ToHost();
96 const float* outb = out[1].data<float>();
97 for (size_t i = 0; i < c; i++)
98 for (size_t j = 0; j < b; j++)
99 EXPECT_FLOAT_EQ(outb[i * b + j], tptr[i * (a + b) + a + j]);
100}
101
102TEST(Slice, ForwardSliceRowCpp) { ForwardSliceRowTest(singa::defaultDevice); }
103

Callers 1

TESTFunction · 0.85

Calls 6

ToHostMethod · 0.80
UniformFunction · 0.50
SetupMethod · 0.45
ToDeviceMethod · 0.45
ForwardMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected