| 315 | } |
| 316 | |
| 317 | fn to_matrix(data: &[Vec<f64>]) -> StructuralBreakResult<DMatrix<f64>> { |
| 318 | let rows = data.len(); |
| 319 | if rows == 0 { |
| 320 | return Err(StructuralBreakError::InputTooShort); |
| 321 | } |
| 322 | let cols = data[0].len(); |
| 323 | if cols == 0 { |
| 324 | return Err(StructuralBreakError::InputTooShort); |
| 325 | } |
| 326 | if data.iter().any(|row| row.len() != cols) { |
| 327 | return Err(StructuralBreakError::InputTooShort); |
| 328 | } |
| 329 | let flat = data.iter().flat_map(|row| row.iter().cloned()).collect::<Vec<_>>(); |
| 330 | Ok(DMatrix::from_row_slice(rows, cols, &flat)) |
| 331 | } |
| 332 | |
| 333 | fn matrix_to_vec(matrix: DMatrix<f64>) -> Vec<Vec<f64>> { |
| 334 | let mut rows = Vec::with_capacity(matrix.nrows()); |