pub fn flat_index(indices: &[usize], shape: &[usize]) -> Result<usize, String>
Compute the flat index from multi-dimensional indices (row-major).