determinant function Null safety

double determinant(
  1. Matrix mat
)

Implementation

double determinant(Matrix mat) {
  if (!mat.isLU) {
    decomposeLU(mat);
  }
  double result = 1;
  final rs = mat.cloneRowSwaps();
  // Figure out how many row swaps r there were
  for (int c = 0; c < rs.length;) {
    final sc = rs[c];
    if (sc == c) {
      c++;
    } else {
      rs[c] = rs[sc];
      rs[sc] = sc;
      result = -result;
    }
  }
  // result is now -1^(number of row swaps)
  for (int i = 0; i < mat.columns; i++) {
    result *= mat.getF(i, i);
  }
  return result;
}