def test_concat(self): t1 = tensor.Tensor((2, 3)) t2 = tensor.Tensor((1, 3)) t1.set_value(1) t2.set_value(2) lyr = layer.Concat('concat', 0, [t1.shape, t2.shape]) t = lyr.forward(model_pb2.kTrain, [t1, t2]) tnp = tensor.to_numpy(t[0]) self.assertEquals(np.sum(tnp), 12)
def test_concat(self): t1 = tensor.Tensor((2, 3)) t2 = tensor.Tensor((1, 3)) t1.set_value(1) t2.set_value(2) lyr = layer.Concat('concat', 0, [(3, ), (3, )]) t = lyr.forward(model_pb2.kTrain, [t1, t2]) tnp = tensor.to_numpy(t) self.assertEquals(np.sum(tnp), 12) t3 = tensor.Tensor((3, 3)) t3.set_value(1.5) grads, _ = lyr.backward(model_pb2.kTrain, [t3]) gnp = tensor.to_numpy(grads[0]) self.assertEquals(np.sum(gnp), 6 * 1.5)