/** * Checks that a matrix rank1 update is possible for the given matrix */ protected void checkRank1(Matrix C) { if (!isSquare()) throw new IndexOutOfBoundsException("!A.isSquare"); if (numRows != C.numRows()) throw new IndexOutOfBoundsException("A.numRows != C.numRows (" + numRows + " != " + C.numRows() + ")"); }
/** * Finds the number of non-zero entries on each row */ public static int[] rowBandwidth(Matrix A) { int[] nz = new int[A.numRows()]; for (MatrixEntry e : A) nz[e.row()]++; return nz; }
/** * Constructor for LowerTriangDenseMatrix * * @param A * Matrix to copy from. Only the lower triangular part is copied */ public LowerTriangDenseMatrix(Matrix A) { this(A, Math.min(A.numRows(), A.numColumns())); }
/** * Constructor for AbstractMatrix, same size as A. The invoking constructor * should set this matrix equal the argument matrix */ protected AbstractMatrix(Matrix A) { this(A.numRows(), A.numColumns()); }
/** * Checks that the sizes of this matrix and the given conform */ protected void checkSize(Matrix B) { if (numRows != B.numRows()) throw new IndexOutOfBoundsException("A.numRows != B.numRows (" + numRows + " != " + B.numRows() + ")"); if (numColumns != B.numColumns()) throw new IndexOutOfBoundsException( "A.numColumns != B.numColumns (" + numColumns + " != " + B.numColumns() + ")"); }
/** * Constructor for AbstractTriangDenseMatrix * * @param A * Matrix to copy from */ AbstractTriangDenseMatrix(Matrix A, UpLo uplo, Diag diag) { this(A, Math.min(A.numRows(), A.numColumns()), uplo, diag); }
/** * Constructor for UpperTriangDenseMatrix * * @param A * Matrix to copy from. Only the upper triangular part is copied * @param deep * True for deep copy, false for reference (in which case * <code>A</code> must be a dense matrix) */ public UpperTriangDenseMatrix(Matrix A, boolean deep) { this(A, Math.min(A.numRows(), A.numColumns()), deep); }
/** * Constructor for AbstractMatrix, same size as A. The invoking constructor * should set this matrix equal the argument matrix */ protected AbstractMatrix(Matrix A) { this(A.numRows(), A.numColumns()); }
/** * Calculates a Cholesky decomposition * * @param A * Matrix to decompose. Not modified * @return The current decomposition */ public static DenseCholesky factorize(Matrix A) { return new DenseCholesky(A.numRows(), true) .factor(new UpperSPDDenseMatrix(A)); }
/** * Convenience method for computing the complete eigenvalue decomposition of * the given matrix * * @param A * Matrix to factorize. Not modified * @return Newly allocated decomposition * @throws NotConvergedException */ public static EVD factorize(Matrix A) throws NotConvergedException { return new EVD(A.numRows()).factor(new DenseMatrix(A)); }
/** * Calculates a Cholesky decomposition * * @param A * Matrix to decompose. Not modified * @return The current decomposition */ public static DenseCholesky factorize(Matrix A) { return new DenseCholesky(A.numRows(), true) .factor(new UpperSPDDenseMatrix(A)); }
/** * Creates an LU decomposition of the given matrix * * @param A * Matrix to decompose. Not modified * @return The current decomposition */ public static DenseLU factorize(Matrix A) { return new DenseLU(A.numRows(), A.numColumns()).factor(new DenseMatrix( A)); }
/** * Convenience method to compute an RQ decomposition * * @param A * Matrix to decompose. Not modified * @return Newly allocated decomposition */ public static RQ factorize(Matrix A) { return new RQ(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Creates an LU decomposition of the given matrix * * @param A * Matrix to decompose. Not modified * @return The current decomposition */ public static DenseLU factorize(Matrix A) { return new DenseLU(A.numRows(), A.numColumns()).factor(new DenseMatrix( A)); }
/** * Convenience method for computing a full SVD * * @param A * Matrix to decompose, not modified * @return Newly allocated factorization * @throws NotConvergedException */ public static SVD factorize(Matrix A) throws NotConvergedException { return new SVD(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Convenience method to compute a LQ decomposition * * @param A * Matrix to decompose. Not modified * @return Newly allocated decomposition */ public static LQ factorize(Matrix A) { return new LQ(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Convenience method for computing a full SVD * * @param A * Matrix to decompose, not modified * @return Newly allocated factorization * @throws NotConvergedException */ public static SVD factorize(Matrix A) throws NotConvergedException { return new SVD(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Convenience method to compute a QR decomposition * * @param A * Matrix to decompose. Not modified * @return Newly allocated decomposition */ public static QR factorize(Matrix A) { return new QR(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Convenience method to compute a QL decomposition * * @param A * Matrix to decompose. Not modified * @return Newly allocated decomposition */ public static QL factorize(Matrix A) { return new QL(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Convenience method to compute a LQ decomposition * * @param A * Matrix to decompose. Not modified * @return Newly allocated decomposition */ public static LQ factorize(Matrix A) { return new LQ(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }