

@attr.gpu
@condition.retry(3)
def test_forward_gpu(self):
    x = chainer.Variable(self.x)
    t = chainer.Variable(self.t)
    y = self.link(x, t)
    self.assertEqual(y.data.dtype, numpy.float32)
    self.assertEqual(y.data.shape, ())
    negative_sampling.NegativeSamplingFunction.samples = cuda.to_gpu(y.creator.samples)
    self.link.to_gpu()
    y_g = self.link(chainer.Variable(cuda.to_gpu(self.x)), chainer.Variable(cuda.to_gpu(self.t)))
    del negative_sampling.NegativeSamplingFunction.samples
    self.assertEqual(y_g.data.dtype, numpy.float32)
    self.assertEqual(y_g.data.shape, ())
    gradient_check.assert_allclose(y.data, y_g.data, atol=0.0001)

dataset/ETHPy150Open pfnet/chainer/tests/chainer_tests/links_tests/loss_tests/test_negative_sampling.py TestNegativeSampling.test_forward_gpu/original