def _unpack_data(data, prior, svdcut, uncorrelated_data, add_svdnoise):
<EOL>if not isinstance(data, tuple):<EOL><INDENT>x = False                   <EOL>y = _unpack_gvars(data)<EOL><DEDENT>elif len(data) == <NUM_LIT:3>:<EOL><INDENT>x, ym, ycov = data<EOL>ym = numpy.asarray(ym)<EOL>ycov = numpy.asarray(ycov)<EOL>y = _gvar.gvar(ym, ycov)<EOL><DEDENT>elif len(data) == <NUM_LIT:2>:<EOL><INDENT>x, y = data<EOL>y = _unpack_gvars(y)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"+str(len(data)))<EOL><DEDENT>if prior is not None:<EOL><INDENT>prior = _unpack_gvars(prior)<EOL><DEDENT>def _apply_svd(data, svdcut=svdcut):<EOL><INDENT>ans, inv_wgts = _gvar.svd(<EOL>data, wgts=-<NUM_LIT:1>, svdcut=svdcut, add_svdnoise=add_svdnoise,<EOL>)<EOL>fdata = _FDATA(<EOL>mean=_gvar.mean(ans.flat),<EOL>inv_wgts=inv_wgts,<EOL>svdcorrection=numpy.sum(ans.svdcorrection.flat),<EOL>logdet=ans.logdet,<EOL>nblocks=ans.nblocks,<EOL>svdn=ans.nmod,<EOL>)<EOL>del ans.nblocks<EOL>return ans, fdata<EOL><DEDENT>if uncorrelated_data:<EOL><INDENT>ysdev = _gvar.sdev(y.flat)<EOL>if prior is None:<EOL><INDENT>pfdata = _FDATA(<EOL>mean=[], inv_wgts=[([],[])], svdcorrection=_gvar.gvar(<NUM_LIT:0>,<NUM_LIT:0>),<EOL>logdet=<NUM_LIT:0.0>, nblocks={<NUM_LIT:1>:<NUM_LIT:0>}, svdn=<NUM_LIT:0>,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>prior, pfdata = _apply_svd(prior)<EOL><DEDENT>inv_wgts = [(numpy.arange(y.size, dtype=numpy.intp), <NUM_LIT:1.> / ysdev)]<EOL>i, wgt = pfdata.inv_wgts[<NUM_LIT:0>]<EOL>if len(i) > <NUM_LIT:0>:<EOL><INDENT>inv_wgts = [(<EOL>numpy.concatenate((inv_wgts[<NUM_LIT:0>][<NUM_LIT:0>], i + y.size)),<EOL>numpy.concatenate((inv_wgts[<NUM_LIT:0>][<NUM_LIT:1>], wgt))<EOL>)]<EOL><DEDENT>for i, wgt in pfdata.inv_wgts[<NUM_LIT:1>:]:<EOL><INDENT>inv_wgts.append((<EOL>i + y.size, wgt<EOL>))<EOL><DEDENT>pfdata.nblocks[<NUM_LIT:1>] = pfdata.nblocks.get(<NUM_LIT:1>, <NUM_LIT:0>) + y.size<EOL>fdata = _FDATA(<EOL>mean=numpy.concatenate((_gvar.mean(y.flat), pfdata.mean)),<EOL>inv_wgts=inv_wgts,<EOL>svdcorrection=pfdata.svdcorrection,<EOL>logdet=<NUM_LIT:2> * numpy.sum(numpy.log(ysdev)) + pfdata.logdet,<EOL>nblocks=pfdata.nblocks,<EOL>svdn=pfdata.svdn,<EOL>)<EOL><DEDENT>elif prior is None:<EOL><INDENT>y, fdata = _apply_svd(y)<EOL><DEDENT>else:<EOL><INDENT>yp, fdata = _apply_svd(numpy.concatenate((y.flat, prior.flat)))<EOL>y.flat = yp[:y.size]<EOL>prior.flat = yp[y.size:]<EOL><DEDENT>return x, y, prior, fdata<EOL>
Unpack data and prior into ``(x, y, prior, fdata)``.

    This routine unpacks ``data`` and ``prior`` into ``x, y, prior, fdata``
    where ``x`` is the independent data, ``y`` is the fit data,
    ``prior`` is the collection of priors for the fit, and ``fdata``
    contains the information about the data and prior needed for the
    fit function. Both ``y`` and ``prior`` are modified to account
    for SVD cuts if ``svdcut>0``.

    Allowed layouts for ``data`` are: ``x, y, ycov``, ``x, y, ysdev``,
    ``x, y``, and ``y``. In the last two case, ``y`` can be either an array
    of |GVar|\s or a dictionary whose values are |GVar|\s or arrays of
    |GVar|\s. In the last case it is assumed that the fit function is a
    function of only the parameters: ``fcn(p)`` --- no ``x``. (This is also
    assumed if ``x = False``.)

    Output data in ``fdata`` is: ``fdata.mean`` containing the mean values of
    ``y.flat`` and ``prior.flat`` (if there is a prior);
    ``fdata.svdcorrection``  containing the sum of the SVD corrections to
    ``y.flat`` and ``prior.flat``; ``fdata.logdet`` containing  the logarithm
    of the  determinant of the covariance matrix of ``y.flat`` and
    ``prior.flat``; and ``fdata.inv_wgts`` containing a representation of the
    inverse of the covariance matrix, after SVD cuts (see :func:`gvar.svd`
    for a description of the format).