| 63 | } |
| 64 | |
| 65 | void ForwardConcatColumnTest(std::shared_ptr<singa::Device> dev) { |
| 66 | size_t a = 2u, b = 1u, c = 3u; |
| 67 | singa::Tensor t1({c, a}, dev); |
| 68 | singa::Tensor t2({c, b}, dev); |
| 69 | singa::LayerConf conf; |
| 70 | conf.set_type("singa_concat"); |
| 71 | conf.mutable_concat_conf()->set_axis(1); |
| 72 | singa::Concat layer; |
| 73 | layer.Setup({{a}, {b}}, conf); |
| 74 | layer.ToDevice(dev); |
| 75 | |
| 76 | t1.SetValue(1.0f); |
| 77 | t2.SetValue(2.0f); |
| 78 | auto out = layer.Forward(singa::kTrain, {t1, t2}); |
| 79 | EXPECT_EQ(out.size(), 1u); |
| 80 | out[0].ToHost(); |
| 81 | const float* outptr = out[0].data<float>(); |
| 82 | for (size_t i = 0; i < c; i++) { |
| 83 | for (size_t j = 0; j < a; j++) |
| 84 | EXPECT_FLOAT_EQ(outptr[i * (a + b) + j], 1.0f); |
| 85 | } |
| 86 | for (size_t i = 0; i < c; i++) { |
| 87 | for (size_t j = a; j < a + b; j++) |
| 88 | EXPECT_FLOAT_EQ(outptr[i * (a + b) + j], 2.0f); |
| 89 | } |
| 90 | } |
| 91 | TEST(Concat, ForwardConcatRowCpp) { |
| 92 | ForwardConcatRowTest(singa::defaultDevice); |
| 93 | } |