Safe element accessors (bounds-checked by assert in debug)
double getAt(int i, int j) { assert(i >= 0 && i < rows && j >= 0 && j < cols, 'Index out of bounds'); return data[i * cols + j]; }