def conv2(im, kernel, mode='same', dst=None):
    source = im
    if mode == 'full':
        additional_rows = kernel.shape[0] - 1
        additional_cols = kernel.shape[1] - 1
        source = cv2.copyMakeBorder(im,
                           (additional_rows + 1) / 2, additional_rows / 2,
                           (additional_cols + 1) / 2, additional_cols / 2,
                           cv2.BORDER_CONSTANT, value = 0)
    anchor = (kernel.shape[1] - kernel.shape[1]/2 - 1,
              kernel.shape[0] - kernel.shape[0]/2 - 1)
    if not dst:
        dst = np.zeros(im.shape)
    fk = np.fliplr(np.flipud(kernel)).copy()
    dst = cv2.filter2D(source, -1, fk, anchor=anchor, delta=0,
                 borderType=cv2.BORDER_CONSTANT)
    if mode == 'valid':
        dst = dst[(kernel.shape[1]-1)/2 : dst.shape[1] - kernel.shape[1]/2,
                  (kernel.shape[0]-1)/2 : dst.shape[0] - kernel.shape[0]/2]
    return dst
dataset/ETHPy150Open dfdx/masque/masque/utils.py/conv2/original