Compute nontrivial parameters for evaluating a bivariate distribution
    as a 2D Gaussian. Inputs:

    * sx: standard deviation (not variance) of x var
    * sy: standard deviation (not variance) of y var
    * cxy: covariance (not correlation coefficient) of x and y

    Returns: (a, b, c), where z = k exp (ax² + bxy + cy²)

    The proper value for k can be obtained from bivnorm().

def bivabc (sx, sy, cxy):
    """Compute nontrivial parameters for evaluating a bivariate distribution
    as a 2D Gaussian. Inputs:

    * sx: standard deviation (not variance) of x var
    * sy: standard deviation (not variance) of y var
    * cxy: covariance (not correlation coefficient) of x and y

    Returns: (a, b, c), where z = k exp (ax² + bxy + cy²)

    The proper value for k can be obtained from bivnorm().

    """
    _bivcheck (sx, sy, cxy)

    sx2, sy2, cxy2 = sx**2, sy**2, cxy**2
    t = 1. / (sx2 * sy2 - cxy2)
    if t <= 0:
        raise ValueError ('covariance just barely out of bounds '
                          '(sx=%.10e, sy=%.10e, cxy=%.10e, cxy/sxsy=%.16f)' %
                          (sx, sy, cxy, cxy / (sx * sy)))

    a = -0.5 * sy2 * t
    c = -0.5 * sx2 * t
    b = cxy * t
    return _abccheck (a, b, c)