throw new IllegalArgumentException("Wrong matrix size: " + "not square");
}
int n = m.rowCount();
PermutationMatrix p = PermutationMatrix.createIdentity(n);
for (int j = 0; j < n; j++) {
Vector jcolumn = m.getColumn(j).toVector();
for (int i = 0; i < n; i++) {
int kmax = Math.min(i, j);
double s = 0.0;
for (int k = 0; k < kmax; k++) {
s += m.get(i, k) * jcolumn.unsafeGet(k);
}
jcolumn.set(i, jcolumn.unsafeGet(i) - s);
m.set(i, j, jcolumn.unsafeGet(i));
}
int biggest = j;
for (int i = j + 1; i < n; i++) {
if (Math.abs(jcolumn.unsafeGet(i)) > Math.abs(jcolumn.unsafeGet(biggest)))
biggest = i;
}
if (biggest != j) {
m.swapRows(biggest, j);
p.swapRows(biggest, j);
}
if ((j < n) && (m.get(j, j) != 0.0)) {
for (int i = j + 1; i < n; i++) {
m.set(i, j, m.get(i, j) / m.get(j, j));