@@ -12,24 +12,24 @@ def _component_kernel(height, width):
1212 scale_x = 2.0 / float (width )
1313
1414 def arrangement (theta_row , out_component , scale_y_tensor , scale_x_tensor ):
15- theta_arr = theta_row [:, None , None , :].expand ((- 1 , height , width , - 1 )).flatten (end_dim = 3 )
15+ theta_arr = theta_row [:, None , None , :, : ].expand ((- 1 , height , width , - 1 , - 1 )).flatten (end_dim = 4 )
1616 out_arr = out_component .flatten ()
1717 return theta_arr .tile ((1 , 3 )), out_arr .tile ((1 ,)), scale_y_tensor , scale_x_tensor
1818
1919 def application (theta , out , scale_y_tensor , scale_x_tensor ):
2020 x = ((out .offsets (2 ) + 0.5 ) * scale_x_tensor ) - 1.0
2121 y = ((out .offsets (1 ) + 0.5 ) * scale_y_tensor ) - 1.0
22- t0 = ntl .sum (theta * (theta .offsets (1 ) == 0 ), axis = 1 )
23- t1 = ntl .sum (theta * (theta .offsets (1 ) == 1 ), axis = 1 )
24- t2 = ntl .sum (theta * (theta .offsets (1 ) == 2 ), axis = 1 )
22+ t0 = ntl .sum (theta * (theta .offsets (2 ) == 0 ), axis = 1 )
23+ t1 = ntl .sum (theta * (theta .offsets (2 ) == 1 ), axis = 1 )
24+ t2 = ntl .sum (theta * (theta .offsets (2 ) == 2 ), axis = 1 )
2525 out = t0 * x + t1 * y + t2
2626
2727 return ninetoothed .make (
2828 arrangement ,
2929 application ,
3030 (
31- Tensor (2 ),
3231 Tensor (3 ),
32+ Tensor (4 ),
3333 Tensor (0 , constexpr = True , value = scale_y , name = "scale_y" ),
3434 Tensor (0 , constexpr = True , value = scale_x , name = "scale_x" ),
3535 ),
@@ -46,6 +46,5 @@ def run(theta, size, align_corners=False):
4646 kernel = _component_kernel (height , width )
4747 scale_y = 2.0 / float (height )
4848 scale_x = 2.0 / float (width )
49- kernel (theta [:, 0 , :], out [..., 0 ], scale_y , scale_x )
50- kernel (theta [:, 1 , :], out [..., 1 ], scale_y , scale_x )
49+ kernel (theta , out , scale_y , scale_x )
5150 return out
0 commit comments