/** 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;
  }
예제 #2
0
  @Override
  public RQ factor(DenseMatrix A) {

    if (Q.numRows() != A.numRows())
      throw new IllegalArgumentException("Q.numRows() != A.numRows()");
    else if (Q.numColumns() != A.numColumns())
      throw new IllegalArgumentException("Q.numColumns() != A.numColumns()");
    else if (R == null) throw new IllegalArgumentException("R == null");

    /*
     * Calculate factorisation, and extract the triangular factor
     */
    intW info = new intW(0);
    LAPACK.getInstance().dgerqf(m, n, A.getData(), Matrices.ld(m), tau, work, work.length, info);

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

    R.zero();
    for (MatrixEntry e : A)
      if (e.column() >= (n - m) + e.row()) R.set(e.row(), e.column() - (n - m), e.get());

    /*
     * Generate the orthogonal matrix
     */
    info.val = 0;
    LAPACK
        .getInstance()
        .dorgrq(m, n, k, A.getData(), Matrices.ld(m), tau, workGen, workGen.length, info);

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

    Q.set(A);

    return this;
  }