@@ -3995,6 +3995,70 @@ def test_functional_image_correctness(self, dimensions, kernel_size, sigma, dtyp
39953995 torch .testing .assert_close (actual , expected , rtol = 0 , atol = 1 )
39963996
39973997
3998+ @pytest .mark .skipif (not CVCUDA_AVAILABLE , reason = "test requires CVCUDA" )
3999+ @needs_cuda
4000+ class TestGaussianBlurCVCUDA :
4001+ def test_kernel_image_errors (self ):
4002+ image = make_image_cvcuda (batch_dims = (1 ,))
4003+
4004+ with pytest .raises (ValueError , match = "kernel_size is a sequence its length should be 2" ):
4005+ F .gaussian_blur_cvcuda (image , kernel_size = [1 , 2 , 3 ])
4006+
4007+ for kernel_size in [2 , - 1 ]:
4008+ with pytest .raises (ValueError , match = "kernel_size should have odd and positive integers" ):
4009+ F .gaussian_blur_cvcuda (image , kernel_size = kernel_size )
4010+
4011+ with pytest .raises (ValueError , match = "sigma is a sequence, its length should be 2" ):
4012+ F .gaussian_blur_cvcuda (image , kernel_size = 1 , sigma = [1 , 2 , 3 ])
4013+
4014+ with pytest .raises (TypeError , match = "sigma should be either float or sequence of floats" ):
4015+ F .gaussian_blur_cvcuda (image , kernel_size = 1 , sigma = object ())
4016+
4017+ with pytest .raises (ValueError , match = "sigma should have positive values" ):
4018+ F .gaussian_blur_cvcuda (image , kernel_size = 1 , sigma = - 1 )
4019+
4020+ def test_functional (self ):
4021+ check_functional (F .gaussian_blur , make_image_cvcuda (batch_dims = (1 ,)), kernel_size = (3 , 3 ))
4022+
4023+ @pytest .mark .parametrize ("device" , cpu_and_cuda ())
4024+ @pytest .mark .parametrize ("sigma" , [5 , 2.0 , (0.5 , 2 ), [1.3 , 2.7 ]])
4025+ def test_transform (self , device , sigma ):
4026+ check_transform (
4027+ transforms .GaussianBlur (kernel_size = 3 , sigma = sigma ), make_image_cvcuda (batch_dims = (1 ,), device = device )
4028+ )
4029+
4030+ @pytest .mark .parametrize (
4031+ ("dimensions" , "kernel_size" , "sigma" ),
4032+ [
4033+ ((10 , 12 ), (3 , 3 ), 0.8 ),
4034+ ((10 , 12 ), (3 , 3 ), 0.5 ),
4035+ ((10 , 12 ), (3 , 5 ), 0.8 ),
4036+ ((10 , 12 ), (3 , 5 ), 0.5 ),
4037+ ((26 , 28 ), (23 , 23 ), 1.7 ),
4038+ ],
4039+ )
4040+ @pytest .mark .parametrize ("color_space" , ["RGB" , "GRAY" ])
4041+ @pytest .mark .parametrize ("batch_dims" , [(1 ,), (2 ,), (4 ,)])
4042+ @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .float32 ])
4043+ def test_functional_image_correctness (self , dimensions , kernel_size , sigma , color_space , batch_dims , dtype ):
4044+ height , width = dimensions
4045+
4046+ image_tensor = make_image (
4047+ size = (height , width ), color_space = color_space , batch_dims = batch_dims , dtype = dtype , device = "cuda"
4048+ )
4049+ image_cvcuda = F .to_cvcuda_tensor (image_tensor )
4050+
4051+ expected = F .gaussian_blur_image (image_tensor , kernel_size = kernel_size , sigma = sigma )
4052+ actual = F .gaussian_blur_cvcuda (image_cvcuda , kernel_size = kernel_size , sigma = sigma )
4053+ actual_torch = F .cvcuda_to_tensor (actual )
4054+
4055+ if dtype .is_floating_point :
4056+ torch .testing .assert_close (actual_torch , expected , rtol = 0 , atol = 0.3 )
4057+ else :
4058+ # uint8/16 gaussians can differ by up to max-value, most likely an overflow issue
4059+ torch .testing .assert_close (actual_torch , expected , rtol = 0 , atol = get_max_value (dtype ))
4060+
4061+
39984062class TestGaussianNoise :
39994063 @pytest .mark .parametrize (
40004064 "make_input" ,
0 commit comments