def imresize(img, scale, antialiasing=True, interpolation=None):
    (in_C, in_H, in_W) = img.size()
    (out_C, out_H, out_W) = (in_C, math.ceil((in_H * scale)), math.ceil((in_W * scale)))
    (kernel, kernel_width) = {'cubic': (cubic, 4.0), 'lanczos2': (lanczos2, 4.0), 'lanczos3': (lanczos3, 6.0), 'box': (box, 1.0), 'linear': (linear, 2.0), None: (cubic, 4.0)}.get(interpolation)
    (weights_H, indices_H, sym_len_Hs, sym_len_He) = calculate_weights_indices(in_H, out_H, scale, kernel, kernel_width, antialiasing)
    (weights_W, indices_W, sym_len_Ws, sym_len_We) = calculate_weights_indices(in_W, out_W, scale, kernel, kernel_width, antialiasing)
    img_aug = torch.FloatTensor(in_C, ((in_H + sym_len_Hs) + sym_len_He), in_W)
    img_aug.narrow(1, sym_len_Hs, in_H).copy_(img)
    sym_patch = img[:, :sym_len_Hs, :]
    inv_idx = torch.arange((sym_patch.size(1) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(1, inv_idx)
    img_aug.narrow(1, 0, sym_len_Hs).copy_(sym_patch_inv)
    sym_patch = img[:, (- sym_len_He):, :]
    inv_idx = torch.arange((sym_patch.size(1) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(1, inv_idx)
    img_aug.narrow(1, (sym_len_Hs + in_H), sym_len_He).copy_(sym_patch_inv)
    out_1 = torch.FloatTensor(in_C, out_H, in_W)
    kernel_width = weights_H.size(1)
    for i in range(out_H):
        idx = int(indices_H[i][0])
        out_1[0, i, :] = img_aug[0, idx:(idx + kernel_width), :].transpose(0, 1).mv(weights_H[i])
        out_1[1, i, :] = img_aug[1, idx:(idx + kernel_width), :].transpose(0, 1).mv(weights_H[i])
        out_1[2, i, :] = img_aug[2, idx:(idx + kernel_width), :].transpose(0, 1).mv(weights_H[i])
    out_1_aug = torch.FloatTensor(in_C, out_H, ((in_W + sym_len_Ws) + sym_len_We))
    out_1_aug.narrow(2, sym_len_Ws, in_W).copy_(out_1)
    sym_patch = out_1[:, :, :sym_len_Ws]
    inv_idx = torch.arange((sym_patch.size(2) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(2, inv_idx)
    out_1_aug.narrow(2, 0, sym_len_Ws).copy_(sym_patch_inv)
    sym_patch = out_1[:, :, (- sym_len_We):]
    inv_idx = torch.arange((sym_patch.size(2) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(2, inv_idx)
    out_1_aug.narrow(2, (sym_len_Ws + in_W), sym_len_We).copy_(sym_patch_inv)
    out_2 = torch.FloatTensor(in_C, out_H, out_W)
    kernel_width = weights_W.size(1)
    for i in range(out_W):
        idx = int(indices_W[i][0])
        out_2[0, :, i] = out_1_aug[0, :, idx:(idx + kernel_width)].mv(weights_W[i])
        out_2[1, :, i] = out_1_aug[1, :, idx:(idx + kernel_width)].mv(weights_W[i])
        out_2[2, :, i] = out_1_aug[2, :, idx:(idx + kernel_width)].mv(weights_W[i])
    return out_2
def imresize(img, scale, antialiasing=True, interpolation=None):
    (in_C, in_H, in_W) = img.size()
    (out_C, out_H, out_W) = (in_C, math.ceil((in_H * scale)), math.ceil((in_W * scale)))
    (kernel, kernel_width) = {'cubic': (cubic, 4.0), 'lanczos2': (lanczos2, 4.0), 'lanczos3': (lanczos3, 6.0), 'box': (box, 1.0), 'linear': (linear, 2.0), None: (cubic, 4.0)}.get(interpolation)
    (weights_H, indices_H, sym_len_Hs, sym_len_He) = calculate_weights_indices(in_H, out_H, scale, kernel, kernel_width, antialiasing)
    (weights_W, indices_W, sym_len_Ws, sym_len_We) = calculate_weights_indices(in_W, out_W, scale, kernel, kernel_width, antialiasing)
    img_aug = torch.FloatTensor(in_C, ((in_H + sym_len_Hs) + sym_len_He), in_W)
    img_aug.narrow(1, sym_len_Hs, in_H).copy_(img)
    sym_patch = img[:, :sym_len_Hs, :]
    inv_idx = torch.arange((sym_patch.size(1) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(1, inv_idx)
    img_aug.narrow(1, 0, sym_len_Hs).copy_(sym_patch_inv)
    sym_patch = img[:, (- sym_len_He):, :]
    inv_idx = torch.arange((sym_patch.size(1) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(1, inv_idx)
    img_aug.narrow(1, (sym_len_Hs + in_H), sym_len_He).copy_(sym_patch_inv)
    out_1 = torch.FloatTensor(in_C, out_H, in_W)
    kernel_width = weights_H.size(1)
    for i in range(out_H):
        idx = int(indices_H[i][0])
        out_1[0, i, :] = img_aug[0, idx:(idx + kernel_width), :].transpose(0, 1).mv(weights_H[i])
        out_1[1, i, :] = img_aug[1, idx:(idx + kernel_width), :].transpose(0, 1).mv(weights_H[i])
        out_1[2, i, :] = img_aug[2, idx:(idx + kernel_width), :].transpose(0, 1).mv(weights_H[i])
    out_1_aug = torch.FloatTensor(in_C, out_H, ((in_W + sym_len_Ws) + sym_len_We))
    out_1_aug.narrow(2, sym_len_Ws, in_W).copy_(out_1)
    sym_patch = out_1[:, :, :sym_len_Ws]
    inv_idx = torch.arange((sym_patch.size(2) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(2, inv_idx)
    out_1_aug.narrow(2, 0, sym_len_Ws).copy_(sym_patch_inv)
    sym_patch = out_1[:, :, (- sym_len_We):]
    inv_idx = torch.arange((sym_patch.size(2) - 1), (- 1), (- 1)).long()
    sym_patch_inv = sym_patch.index_select(2, inv_idx)
    out_1_aug.narrow(2, (sym_len_Ws + in_W), sym_len_We).copy_(sym_patch_inv)
    out_2 = torch.FloatTensor(in_C, out_H, out_W)
    kernel_width = weights_W.size(1)
    for i in range(out_W):
        idx = int(indices_W[i][0])
        out_2[0, :, i] = out_1_aug[0, :, idx:(idx + kernel_width)].mv(weights_W[i])
        out_2[1, :, i] = out_1_aug[1, :, idx:(idx + kernel_width)].mv(weights_W[i])
        out_2[2, :, i] = out_1_aug[2, :, idx:(idx + kernel_width)].mv(weights_W[i])
    return out_2