def METHOD_NAME(n, q, i, j):
    # location in data1
    y1 = i * stride1 + max_displacement
    x1 = j * stride1 + max_displacement
    # location in data2
    y2 = y1 + (te.indexdiv(q, displacement_size) - displacement_radius) * stride2
    x2 = x1 + (te.indexmod(q, displacement_size) - displacement_radius) * stride2
    return te.sum(
        corr_func(padded_data1[n, rc, y1 + ry, x1 + rx], padded_data2[n, rc, y2 + ry, x2 + rx]),
        axis=[rc, ry, rx],
    )