Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

remove math lib and update test

pulkit-khandelwal900eb6abd88f
diff --git a/test/test_image.py b/test/test_image.py
index ea0b4d856..205609ec4 100644
--- a/test/test_image.py
+++ b/test/test_image.py
@@ -82,3 +82,14 @@ class TestLaplacian:
input = torch.rand(batch_shape).to(torch.device(device_type))
laplace = image.Laplacian(kernel_size)
assert laplace(input).shape == batch_shape
+
+ def test_gradcheck(self):
+ # test parameters
+ batch_shape = (2, 3, 11, 7)
+ kernel_size = (3, 9)
+
+ # evaluate function gradient
+ input = torch.rand(batch_shape)
+ input = utils.tensor_to_gradcheck_var(input)
+ assert gradcheck(image.laplacian, (input, kernel_size,),
+ raise_exception=True)
diff --git a/torchgeometry/image/laplacian.py b/torchgeometry/image/laplacian.py
index 27d701826..7692ee5f9 100644
--- a/torchgeometry/image/laplacian.py
+++ b/torchgeometry/image/laplacian.py
@@ -1,6 +1,5 @@
from typing import Tuple
-import math
import torch
import torch.nn as nn
from torch.nn.functional import conv2d
@@ -79,7 +78,7 @@ def get_laplacian_kernel2d(kernel_size: int) -> torch.Tensor:
kernel = torch.ones((kernel_size, kernel_size))
mid = kernel_size // 2
- kernel[mid, mid] = 1 - math.pow(kernel_size, 2)
+ kernel[mid, mid] = 1 - kernel_size ** 2
kernel_2d: torch.Tensor = kernel
return kernel_2d