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

Function BackwardSliceColumnTest

test/singa/test_slice.cc:146–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146void BackwardSliceColumnTest(std::shared_ptr<singa::Device> dev) {
147 size_t a = 2u, b = 1u, c = 3u;
148 singa::LayerConf conf;
149 conf.set_type("singa_slice");
150 auto slice_conf = conf.mutable_slice_conf();
151 slice_conf->set_axis(1);
152 slice_conf->add_slice_point(2);
153 singa::Slice layer;
154 layer.Setup({a + b}, conf);
155 layer.ToDevice(dev);
156
157 singa::Tensor t1({c, a}, dev);
158 singa::Tensor t2({c, b}, dev);
159 t1.SetValue(1.0f);
160 t2.SetValue(2.0f);
161 auto out = layer.Backward(singa::kTrain, {t1, t2});
162 auto grad = out.first[0];
163 grad.ToHost();
164 const float* outptr = grad.data<float>();
165 for (size_t i = 0; i < c; i++) {
166 for (size_t j = 0; j < a; j++)
167 EXPECT_FLOAT_EQ(outptr[i * (a + b) + j], 1.0f);
168 }
169 for (size_t i = 0; i < c; i++) {
170 for (size_t j = a; j < a + b; j++)
171 EXPECT_FLOAT_EQ(outptr[i * (a + b) + j], 2.0f);
172 }
173}
174
175TEST(Slice, BackwardSliceRowCpp) { BackwardSliceRowTest(singa::defaultDevice); }
176

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