/** Solves for <code>B</code>, overwriting it on return */
  public DenseMatrix solve(DenseMatrix B) throws MatrixNotSPDException {
    if (notspd) throw new MatrixNotSPDException();
    if (B.numRows() != n) throw new IllegalArgumentException("B.numRows() != n");

    intW info = new intW(0);
    if (upper)
      LAPACK
          .getInstance()
          .dpptrs(
              UpLo.Upper.netlib(),
              Cu.numRows(),
              B.numColumns(),
              Cu.getData(),
              B.getData(),
              Matrices.ld(Cu.numRows()),
              info);
    else
      LAPACK
          .getInstance()
          .dpptrs(
              UpLo.Lower.netlib(),
              Cl.numRows(),
              B.numColumns(),
              Cl.getData(),
              B.getData(),
              Matrices.ld(Cl.numRows()),
              info);

    if (info.val < 0) throw new IllegalArgumentException();

    return B;
  }
  private PackCholesky decompose(AbstractPackMatrix A) {
    if (n != A.numRows()) throw new IllegalArgumentException("n != A.numRows()");

    notspd = false;

    intW info = new intW(0);
    if (upper) LAPACK.getInstance().dpptrf(UpLo.Upper.netlib(), A.numRows(), A.getData(), info);
    else LAPACK.getInstance().dpptrf(UpLo.Lower.netlib(), A.numRows(), A.getData(), info);

    if (info.val > 0) notspd = true;
    else if (info.val < 0) throw new IllegalArgumentException();

    if (upper) Cu.set(A);
    else Cl.set(A);

    return this;
  }
  /**
   * Computes the reciprocal condition number
   *
   * @param A The matrix this is a decomposition of
   * @return The reciprocal condition number. Values close to unity indicate a well-conditioned
   *     system, while numbers close to zero do not.
   */
  public double rcond(Matrix A) {
    if (A.numRows() != n) throw new IllegalArgumentException("A.numRows() != n");
    if (!A.isSquare()) throw new IllegalArgumentException("!A.isSquare()");

    double anorm = A.norm(Norm.One);

    double[] work = new double[3 * n];
    int[] iwork = new int[n];

    intW info = new intW(0);
    doubleW rcond = new doubleW(0);
    if (upper)
      LAPACK
          .getInstance()
          .dppcon(UpLo.Upper.netlib(), n, Cu.getData(), anorm, rcond, work, iwork, info);
    else
      LAPACK
          .getInstance()
          .dppcon(UpLo.Lower.netlib(), n, Cl.getData(), anorm, rcond, work, iwork, info);

    if (info.val < 0) throw new IllegalArgumentException();

    return rcond.val;
  }