예제 #1
0
    def test_exception(self, device, dtype):
        input = torch.ones(1, 1, 3, 4, device=device, dtype=dtype)
        kernel = torch.ones(3, 3, device=device, dtype=dtype)

        with pytest.raises(TypeError):
            assert gradient([0.], kernel)

        with pytest.raises(TypeError):
            assert gradient(input, [0.])

        with pytest.raises(ValueError):
            test = torch.ones(2, 3, 4, device=device, dtype=dtype)
            assert gradient(test, kernel)

        with pytest.raises(ValueError):
            test = torch.ones(2, 3, 4, device=device, dtype=dtype)
            assert gradient(input, test)
예제 #2
0
    def test_exception(self, dev_str, dtype_str, call):
        input_ = ivy.ones((1, 1, 3, 4), dev_str=dev_str, dtype_str=dtype_str)
        kernel = ivy.ones((3, 3), dev_str=dev_str, dtype_str=dtype_str)

        with pytest.raises(ValueError):
            test = ivy.ones((2, 3, 4), dev_str=dev_str, dtype_str=dtype_str)
            assert gradient(test, kernel)

        with pytest.raises(ValueError):
            test = ivy.ones((2, 3, 4), dev_str=dev_str, dtype_str=dtype_str)
            assert gradient(input_, test)

        if call is not helpers.torch_call:
            return

        with pytest.raises(TypeError):
            assert gradient([0.], kernel)

        with pytest.raises(TypeError):
            assert gradient(input_, [0.])
예제 #3
0
 def test_value(self, device, dtype):
     input = torch.tensor(
         [[0.5, 1., 0.3], [0.7, 0.3, 0.8], [0.4, 0.9, 0.2]],
         device=device,
         dtype=dtype)[None, None, :, :]
     kernel = torch.tensor([[0., 1., 0.], [1., 1., 1.], [0., 1., 0.]],
                           device=device,
                           dtype=dtype)
     expected = torch.tensor(
         [[0.5, 0.7, 0.7], [0.4, 0.7, 0.6], [0.5, 0.7, 0.7]],
         device=device,
         dtype=dtype)[None, None, :, :]
     assert_allclose(gradient(input, kernel), expected)
예제 #4
0
 def test_value(self, device, dtype):
     tensor = torch.tensor(
         [[0.5, 1.0, 0.3], [0.7, 0.3, 0.8], [0.4, 0.9, 0.2]],
         device=device,
         dtype=dtype)[None, None, :, :]
     kernel = torch.tensor(
         [[-1.0, 0.0, -1.0], [0.0, 0.0, 0.0], [-1.0, 0.0, -1.0]],
         device=device,
         dtype=dtype)
     expected = torch.tensor(
         [[0.5, 0.7, 0.7], [0.4, 0.7, 0.6], [0.5, 0.7, 0.7]],
         device=device,
         dtype=dtype)[None, None, :, :]
     assert_allclose(gradient(tensor, kernel), expected)
예제 #5
0
 def test_cardinality(self, dev_str, dtype_str, call, shape, kernel):
     img = ivy.ones(shape, dtype_str=dtype_str, dev_str=dev_str)
     krnl = ivy.ones(kernel, dtype_str=dtype_str, dev_str=dev_str)
     assert gradient(img, krnl).shape == shape
예제 #6
0
 def test_cardinality(self, device, dtype, shape, kernel):
     img = torch.ones(shape, device=device, dtype=dtype)
     krnl = torch.ones(kernel, device=device, dtype=dtype)
     assert gradient(img, krnl).shape == shape