Hi, I’m currently converting my numpy vectorized code running a fft2 to pytorch, but somehow the result is different. Am I doing it wrong?
numpy version:
def apply_filter_vector(_filter, arr):
    tc= arr.copy()
    temp = apply_filter(tc, _filter[:, :, None])
    return temp 

def apply_filter(arr, _filter, axes=(0,1)):
    return ifft2(
        np.multiply(ifftshift(1 - _filter), fft2(arr, axes=axes)),
        axes=axes,
    ).real

pytorch version :
def apply_filter_vector_pytorch(_filter, arr, cuda=False):
    tc= arr.copy()
    
    if cuda == True:
        temp = apply_filter_pytorch(tc, _filter[:, :, None], cuda=True)        
    else:
        temp = apply_filter_pytorch(tc, _filter[:, :, None], cuda=False) 
    return temp

def apply_filter_pytorch(arr, _filter, axes=(0,1), cuda=False):
    _filter = torch.from_numpy(_filter)
    arr = torch.from_numpy(arr)
    if cuda == True:
        _filter=_filter.cuda()
        arr=arr.cuda()
    result = torch.fft.ifft2(torch.multiply(torch.fft.ifftshift(1.0-_filter),torch.fft.fft2(arr, dim =axes)))
    if cuda == True:
        result= result.cpu()
    result= result.numpy().real
    return result

the data is a 3D array (2D square images with z axis variation in time).