def METHOD_NAME():
    # numba implementation included for the purposes of comparison.
    try:
        import numba
    except ImportError:
        return None
    def _sqdiff_numba(template, frame):
        if template.shape[2] == 3:
            return _sqdiff_numba_nomask(template, frame)
        else:
            return _sqdiff_numba_masked(template, frame)
    @numba.jit(nopython=True, nogil=True)
    def _sqdiff_numba_nomask(template, frame):
        cum = 0
        s = template.shape
        for i in range(s[0]):
            for j in range(s[1]):
                for k in range(s[2]):
                    cum += (template[i, j, k] - frame[i, j, k]) ** 2
        return cum, frame.size
    @numba.jit(nopython=True, nogil=True)
    def _sqdiff_numba_masked(template, frame):
        # mask is either 0 or 255
        cum = 0
        maskcount = 0
        s = template.shape
        for i in range(s[0]):
            for j in range(s[1]):
                if template[i, j, 3] == 255:
                    for k in range(s[2]):
                        cum += (template[i, j, k] - frame[i, j, k]) ** 2
                    maskcount += 1
        return cum, maskcount * 3
    return _sqdiff_numba