unpacked, unpacked_len = rnn_utils.pad_packed_sequence(packed_out)
# Check forward
- self.assertEqual(packed_hidden, seq_hidden)
- self.assertEqual(unpacked, seq_out)
- self.assertEqual(unpacked_len, lengths)
+ prec = dtype2prec[dtype]
+ self.assertEqual(packed_hidden, seq_hidden, prec)
+ self.assertEqual(unpacked, seq_out, prec)
+ self.assertEqual(unpacked_len, lengths, prec)
# Check backward
seq_out.sum().backward()
self.assertEqual(torch.ones(1, 1, 4), out_t.data)
input = torch.randn(1, 1, 2, requires_grad=True)
- gradcheck(lambda x: F.upsample(x, 4, mode='nearest'), [input])
+ gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
def test_upsamplingLinear1d(self):
for align_corners in [True, False]:
self.assertEqual(torch.ones(1, 1, out_size), out_t.data)
input = torch.randn(1, 1, 2, requires_grad=True)
- gradcheck(lambda x: F.upsample(x, out_size, **kwargs), (input,))
+ gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), (input,))
def test_upsamplingLinear1d_spatial_invariance(self):
m = nn.Upsample(scale_factor=3, mode='linear', align_corners=False)
input = torch.randn(1, 1, 2, 2, requires_grad=True)
self.assertEqual(
- F.upsample(input, 4, mode='nearest'),
- F.upsample(input, scale_factor=2, mode='nearest'))
- gradcheck(lambda x: F.upsample(x, 4, mode='nearest'), [input])
- gradgradcheck(lambda x: F.upsample(x, 4, mode='nearest'), [input])
+ F.interpolate(input, 4, mode='nearest'),
+ F.interpolate(input, scale_factor=2, mode='nearest'))
+ gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
+ gradgradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
def test_upsamplingBilinear2d(self):
for align_corners in [True, False]:
self.assertEqual(torch.ones(1, 1, out_size, out_size), out_t.data)
input = torch.randn(1, 1, 2, 2, requires_grad=True)
- gradcheck(lambda x: F.upsample(x, out_size, **kwargs), [input])
+ gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
def test_upsamplingBicubic2d(self):
# test output against known input
self.assertEqual(torch.ones(1, 1, 4, 4, 4), out_t.data)
input = torch.randn(1, 1, 2, 2, 2, requires_grad=True)
- gradcheck(lambda x: F.upsample(x, 4, mode='nearest'), [input])
+ gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
def test_upsamplingTrilinear3d(self):
for align_corners in [True, False]:
input = torch.randn(1, 1, 2, 2, 2, requires_grad=True)
self.assertEqual(
- F.upsample(input, (out_size, out_size, out_size), **kwargs),
- F.upsample(input, scale_factor=scale_factor, **kwargs))
- gradcheck(lambda x: F.upsample(x, out_size, **kwargs), [input])
- gradgradcheck(lambda x: F.upsample(x, out_size, **kwargs), [input])
+ F.interpolate(input, (out_size, out_size, out_size), **kwargs),
+ F.interpolate(input, scale_factor=scale_factor, **kwargs))
+ gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
+ gradgradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
def test_upsamplingTrilinear3d_spatial_invariance(self):
m = nn.Upsample(scale_factor=3, mode='trilinear', align_corners=False)