LUDecomposition implements AutoCloseable { public Matrix getP() { if ((cachedP == null) && !singular) { final int m = pivot.size(); cachedP = like(matrix); cachedP.assign(0.0); for (int i = 0; i < m; ++i) cachedP.setX(i, (int)pivot.get(i), 1.0); } return cachedP; } LUDecomposition(Matrix matrix);  LUDecomposition(Matrix matrix, double singularityThreshold); @Override void close(); Matrix getL(); Matrix getU(); Matrix getP(); Vector getPivot(); double determinant(); Vector solve(Vector b); Matrix solve(Matrix b);  }
@Test public void getP() throws Exception { Matrix luDecompositionP = new LUDecomposition(testMatrix).getP(); assertEquals("Unexpected row size.", testP.rowSize(), luDecompositionP.rowSize()); assertEquals("Unexpected column size.", testP.columnSize(), luDecompositionP.columnSize()); for (int i = 0; i < testP.rowSize(); i++) for (int j = 0; j < testP.columnSize(); j++) assertEquals("Unexpected value at (" + i + "," + j + ").", testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d); luDecompositionP.destroy(); }