def fit_general(xy, uv, wxy=None, wuv=None):
    " Fits (non-iteratively and without sigma-clipping) a displacement,\n    rotation, scale, and skew transformations (i.e., the full ``2x2``\n    transformation matrix) between input lists of positions\n    ``xy`` and ``uv``. When weights are provided, a weighted fit is performed.\n    Parameter descriptions and return values are identical to those\n    in `iter_linear_fit`, except returned ``fit`` dictionary does not contain\n    the following keys irrelevant to this function: ``'center'``,\n    ``'fitmask'``, and ``'eff_nclip'``.\n\n    "
    if (len(xy) < 3):
        raise NotEnoughPointsError('At least three points are required to find 6-parameter linear affine transformations.')
    x = np.array(xy[:, 0], dtype=np.longdouble)
    y = np.array(xy[:, 1], dtype=np.longdouble)
    u = np.array(uv[:, 0], dtype=np.longdouble)
    v = np.array(uv[:, 1], dtype=np.longdouble)
    if ((wxy is None) and (wuv is None)):
        w = None
        sw = float(x.size)
        sx = x.sum()
        sy = y.sum()
        su = u.sum()
        sv = v.sum()
        sxu = np.dot(x, u)
        syu = np.dot(y, u)
        sxv = np.dot(x, v)
        syv = np.dot(y, v)
        suu = np.dot(u, u)
        svv = np.dot(v, v)
        suv = np.dot(u, v)
    else:
        if (wxy is None):
            w = np.array(wuv, dtype=np.longdouble)
        elif (wuv is None):
            w = np.array(wxy, dtype=np.longdouble)
        else:
            wuv = np.array(wuv, dtype=np.longdouble)
            wxy = np.array(wxy, dtype=np.longdouble)
            m = np.logical_and((wuv > 0), (wxy > 0))
            w = np.zeros_like(wuv)
            w[m] = ((wxy[m] * wuv[m]) / (wxy[m] + wuv[m]))
        if np.any((w < 0.0)):
            raise ValueError('Invalid weights: weights must be non-negative.')
        if (np.sum((w > 0)) < 3):
            raise ValueError("Not enough valid data for 'general' fit: too many weights are zero!")
        sw = np.sum(w, dtype=np.longdouble)
        sx = np.dot(w, x)
        sy = np.dot(w, y)
        su = np.dot(w, u)
        sv = np.dot(w, v)
        sxu = np.dot(w, (x * u))
        syu = np.dot(w, (y * u))
        sxv = np.dot(w, (x * v))
        syv = np.dot(w, (y * v))
        suu = np.dot(w, (u * u))
        svv = np.dot(w, (v * v))
        suv = np.dot(w, (u * v))
    m = np.array([[su, sv, sw], [suu, suv, su], [suv, svv, sv]], dtype=np.longdouble)
    a = np.array([sx, sxu, sxv], dtype=np.longdouble)
    b = np.array([sy, syu, syv], dtype=np.longdouble)
    try:
        inv_m = inv(m)
    except np.linalg.LinAlgError:
        raise SingularMatrixError('Singular matrix: suspected colinear points.')
    p = np.dot(inv_m, a)
    q = np.dot(inv_m, b)
    if (not (np.all(np.isfinite(p)) and np.all(np.isfinite(q)))):
        raise SingularMatrixError('Singular matrix: suspected colinear points.')
    fit = _build_fit(p, q, 'general')
    resids = ((xy - np.dot(uv, fit['matrix_ld'].T)) - fit['shift_ld'])
    fit['resids'] = resids.astype(np.double)
    _compute_stat(fit, residuals=resids, weights=w)
    return fit
Fits (non-iteratively and without sigma-clipping) a displacement,
rotation, scale, and skew transformations (i.e., the full ``2x2``
transformation matrix) between input lists of positions
``xy`` and ``uv``. When weights are provided, a weighted fit is performed.
Parameter descriptions and return values are identical to those
in `iter_linear_fit`, except returned ``fit`` dictionary does not contain
the following keys irrelevant to this function: ``'center'``,
``'fitmask'``, and ``'eff_nclip'``.
def fit_general(xy, uv, wxy=None, wuv=None):
    " Fits (non-iteratively and without sigma-clipping) a displacement,\n    rotation, scale, and skew transformations (i.e., the full ``2x2``\n    transformation matrix) between input lists of positions\n    ``xy`` and ``uv``. When weights are provided, a weighted fit is performed.\n    Parameter descriptions and return values are identical to those\n    in `iter_linear_fit`, except returned ``fit`` dictionary does not contain\n    the following keys irrelevant to this function: ``'center'``,\n    ``'fitmask'``, and ``'eff_nclip'``.\n\n    "
    if (len(xy) < 3):
        raise NotEnoughPointsError('At least three points are required to find 6-parameter linear affine transformations.')
    x = np.array(xy[:, 0], dtype=np.longdouble)
    y = np.array(xy[:, 1], dtype=np.longdouble)
    u = np.array(uv[:, 0], dtype=np.longdouble)
    v = np.array(uv[:, 1], dtype=np.longdouble)
    if ((wxy is None) and (wuv is None)):
        w = None
        sw = float(x.size)
        sx = x.sum()
        sy = y.sum()
        su = u.sum()
        sv = v.sum()
        sxu = np.dot(x, u)
        syu = np.dot(y, u)
        sxv = np.dot(x, v)
        syv = np.dot(y, v)
        suu = np.dot(u, u)
        svv = np.dot(v, v)
        suv = np.dot(u, v)
    else:
        if (wxy is None):
            w = np.array(wuv, dtype=np.longdouble)
        elif (wuv is None):
            w = np.array(wxy, dtype=np.longdouble)
        else:
            wuv = np.array(wuv, dtype=np.longdouble)
            wxy = np.array(wxy, dtype=np.longdouble)
            m = np.logical_and((wuv > 0), (wxy > 0))
            w = np.zeros_like(wuv)
            w[m] = ((wxy[m] * wuv[m]) / (wxy[m] + wuv[m]))
        if np.any((w < 0.0)):
            raise ValueError('Invalid weights: weights must be non-negative.')
        if (np.sum((w > 0)) < 3):
            raise ValueError("Not enough valid data for 'general' fit: too many weights are zero!")
        sw = np.sum(w, dtype=np.longdouble)
        sx = np.dot(w, x)
        sy = np.dot(w, y)
        su = np.dot(w, u)
        sv = np.dot(w, v)
        sxu = np.dot(w, (x * u))
        syu = np.dot(w, (y * u))
        sxv = np.dot(w, (x * v))
        syv = np.dot(w, (y * v))
        suu = np.dot(w, (u * u))
        svv = np.dot(w, (v * v))
        suv = np.dot(w, (u * v))
    m = np.array([[su, sv, sw], [suu, suv, su], [suv, svv, sv]], dtype=np.longdouble)
    a = np.array([sx, sxu, sxv], dtype=np.longdouble)
    b = np.array([sy, syu, syv], dtype=np.longdouble)
    try:
        inv_m = inv(m)
    except np.linalg.LinAlgError:
        raise SingularMatrixError('Singular matrix: suspected colinear points.')
    p = np.dot(inv_m, a)
    q = np.dot(inv_m, b)
    if (not (np.all(np.isfinite(p)) and np.all(np.isfinite(q)))):
        raise SingularMatrixError('Singular matrix: suspected colinear points.')
    fit = _build_fit(p, q, 'general')
    resids = ((xy - np.dot(uv, fit['matrix_ld'].T)) - fit['shift_ld'])
    fit['resids'] = resids.astype(np.double)
    _compute_stat(fit, residuals=resids, weights=w)
    return fit