(input, scale_factor, in_sz, out_sz, weights, dim, pad_sz,
pad_mode, fw)
| 249 | |
| 250 | |
| 251 | def apply_convs(input, scale_factor, in_sz, out_sz, weights, dim, pad_sz, |
| 252 | pad_mode, fw): |
| 253 | # for this operations we assume the resized dim is the last one. |
| 254 | # so we transpose and will transpose back after multiplying |
| 255 | input = fw_swapaxes(input, dim, -1, fw) |
| 256 | |
| 257 | # the stride for all convs is the denominator of the scale factor |
| 258 | stride, num_convs = scale_factor.denominator, scale_factor.numerator |
| 259 | |
| 260 | # prepare an empty tensor for the output |
| 261 | tmp_out_shape = list(input.shape) |
| 262 | tmp_out_shape[-1] = out_sz |
| 263 | tmp_output = fw_empty(tuple(tmp_out_shape), fw, input.device) |
| 264 | |
| 265 | # iterate over the conv operations. we have as many as the numerator |
| 266 | # of the scale-factor. for each we need boundaries and a filter. |
| 267 | for conv_ind, (pad_sz, filt) in enumerate(zip(pad_sz, weights)): |
| 268 | # apply padding (we pad last dim, padding can be negative) |
| 269 | pad_dim = input.ndim - 1 |
| 270 | tmp_input = fw_pad(input, fw, pad_sz, pad_mode, dim=pad_dim) |
| 271 | |
| 272 | # apply convolution over last dim. store in the output tensor with |
| 273 | # positional strides so that when the loop is comlete conv results are |
| 274 | # interwind |
| 275 | tmp_output[..., conv_ind::num_convs] = fw_conv(tmp_input, filt, stride) |
| 276 | |
| 277 | return fw_swapaxes(tmp_output, -1, dim, fw) |
| 278 | |
| 279 | |
| 280 | def set_scale_and_out_sz(in_shape, out_shape, scale_factors, by_convs, |
no test coverage detected