@@ -1663,19 +1663,26 @@ def test__resample_valid_output():
16631663 [(np .array ([[0.1 , 0.3 , 0.2 ]]), mimage .NEAREST ,
16641664 np .array ([[0.1 , 0.1 , 0.1 , 0.3 , 0.3 , 0.3 , 0.3 , 0.2 , 0.2 , 0.2 ]])),
16651665 (np .array ([[0.1 , 0.3 , 0.2 ]]), mimage .BILINEAR ,
1666- np .array ([[0.1 , 0.1 , 0.15078125 , 0.21096191 , 0.27033691 ,
1667- 0.28476562 , 0.2546875 , 0.22460938 , 0.20002441 , 0.20002441 ]])),
1666+ np .array ([[0.1 , 0.1 , 0.15 , 0.21 , 0.27 , 0.285 , 0.255 , 0.225 , 0.2 , 0.2 ]])),
1667+ (np .array ([[0.1 , 0.9 ]]), mimage .BILINEAR ,
1668+ np .array ([[0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.14 , 0.22 , 0.3 , 0.38 , 0.46 ,
1669+ 0.54 , 0.62 , 0.7 , 0.78 , 0.86 , 0.9 , 0.9 , 0.9 , 0.9 , 0.9 ]])),
1670+ (np .array ([[0.1 , 0.1 ]]), mimage .BILINEAR , np .full ((1 , 10 ), 0.1 )),
16681671 ]
16691672)
16701673def test_resample_nonaffine (data , interpolation , expected ):
1671- # Test that equivalent affine and nonaffine transforms resample the same
1674+ # Test that both affine and nonaffine transforms resample to the correct answer
1675+
1676+ # If the array is constant, the tolerance can be tight
1677+ # Otherwise, the tolerance is limited by the subpixel approach in the agg backend
1678+ atol = 0 if np .all (data == data .ravel ()[0 ]) else 2e-3
16721679
16731680 # Create a simple affine transform for scaling the input array
16741681 affine_transform = Affine2D ().scale (sx = expected .shape [1 ] / data .shape [1 ], sy = 1 )
16751682
16761683 affine_result = np .empty_like (expected )
16771684 mimage .resample (data , affine_result , affine_transform , interpolation = interpolation )
1678- assert_allclose (affine_result , expected )
1685+ assert_allclose (affine_result , expected , atol = atol )
16791686
16801687 # Create a nonaffine version of the same transform
16811688 # by compositing with a nonaffine identity transform
@@ -1684,13 +1691,13 @@ class NonAffineIdentityTransform(Transform):
16841691 output_dims = 2
16851692
16861693 def inverted (self ):
1687- return self
1694+ return self
16881695 nonaffine_transform = NonAffineIdentityTransform () + affine_transform
16891696
16901697 nonaffine_result = np .empty_like (expected )
16911698 mimage .resample (data , nonaffine_result , nonaffine_transform ,
16921699 interpolation = interpolation )
1693- assert_allclose (nonaffine_result , expected , atol = 5e-3 )
1700+ assert_allclose (nonaffine_result , expected , atol = atol )
16941701
16951702
16961703def test_axesimage_get_shape ():
0 commit comments