// Sum the principal diagonal of a rectangular row-major matrix after validating its flattened length. pub fn matrix_diag_sum(data: vector, rows: i64, cols: i64) -> f64 { if rows<0 || cols<0 || rows*cols != len(data) { return 0.0; } let mut sum = 0.0; let mut i = 0; while i