isCirculantMatrix method

bool isCirculantMatrix({
  1. num tolerance = 1e-10,
})

Checks if the matrix is a Circulant matrix.

A Circulant matrix is a special kind of Toeplitz matrix where the diagonals "wrap around" such that the first row is a cyclic shift of the row above it.

tolerance is the numerical tolerance used to compare the elements. Default value for tolerance is 1e-10.

Returns true if the matrix is tridiagonal, false otherwise.

Implementation

bool isCirculantMatrix({num tolerance = 1e-10}) {
  if (!isSquareMatrix()) return false;

  for (int i = 0; i < rowCount - 1; i++) {
    for (int j = 0; j < columnCount - 1; j++) {
      if ((_data[i][j] - _data[i + 1][(j + 1) % columnCount]).abs() >
          tolerance) {
        return false;
      }
    }
  }
  return true;
}