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

Function BackwardSliceRowTest

test/singa/test_slice.cc:118–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116#endif // USE_CUDA
117
118void BackwardSliceRowTest(std::shared_ptr<singa::Device> dev) {
119 size_t a = 2u, b = 1u, c = 3u;
120 singa::LayerConf conf;
121 conf.set_type("singa_slice");
122 auto slice_conf = conf.mutable_slice_conf();
123 slice_conf->set_axis(0);
124 slice_conf->add_slice_point(2);
125 singa::Slice layer;
126 layer.Setup({c}, conf);
127 layer.ToDevice(dev);
128
129 singa::Tensor t1({a, c}, dev);
130 singa::Tensor t2({b, c}, dev);
131 t1.SetValue(1.0f);
132 t2.SetValue(2.0f);
133 auto out = layer.Backward(singa::kTrain, {t1, t2});
134 auto grad = out.first[0];
135
136 grad.ToHost();
137 const float* outptr = grad.data<float>();
138 for (size_t i = 0; i < a; i++) {
139 for (size_t j = 0; j < c; j++) EXPECT_FLOAT_EQ(outptr[i * c + j], 1.0f);
140 }
141 for (size_t i = a; i < a + b; i++) {
142 for (size_t j = 0; j < c; j++) EXPECT_FLOAT_EQ(outptr[i * c + j], 2.0f);
143 }
144}
145
146void BackwardSliceColumnTest(std::shared_ptr<singa::Device> dev) {
147 size_t a = 2u, b = 1u, c = 3u;

Callers 1

TESTFunction · 0.85

Calls 5

ToHostMethod · 0.80
SetupMethod · 0.45
ToDeviceMethod · 0.45
SetValueMethod · 0.45
BackwardMethod · 0.45

Tested by

no test coverage detected