Problem
DenseMatrix::new(nrows, ncols, values, column_major) -> Result<Self, Failed> fails with Failed, which carries no structured information: which dimension constraint was violated, what was received, what was expected. Every dimension bug becomes guesswork at the call site.
Real example from downstream debugging (genefold): a transpose bug in test fixtures (from_iterator axis 0 vs 1) surfaced as a bare Failed from DenseMatrix::new deep inside a build path. Diagnosing required re-deriving the expected element count by hand.
Proposal
Introduce structured variants while keeping Failed as a legacy alias:
pub enum MatrixError {
DimensionMismatch { rows: usize, cols: usize, expected_len: usize, got: usize },
EmptyInput,
NaNValue { index: (usize, usize) },
}
Minimum viable step: make Failed's Display include received vs expected sizes for the common length-mismatch case. That single change resolves most debugging pain without a breaking API change.
Note
Same reasoning applies to other constructors returning Failed (from_2d_vec, from_iterator): they know expected vs actual element counts at the failure point and currently discard them.
Problem
DenseMatrix::new(nrows, ncols, values, column_major) -> Result<Self, Failed>fails withFailed, which carries no structured information: which dimension constraint was violated, what was received, what was expected. Every dimension bug becomes guesswork at the call site.Real example from downstream debugging (genefold): a transpose bug in test fixtures (
from_iteratoraxis 0 vs 1) surfaced as a bareFailedfromDenseMatrix::newdeep inside a build path. Diagnosing required re-deriving the expected element count by hand.Proposal
Introduce structured variants while keeping
Failedas a legacy alias:Minimum viable step: make
Failed'sDisplayinclude received vs expected sizes for the common length-mismatch case. That single change resolves most debugging pain without a breaking API change.Note
Same reasoning applies to other constructors returning
Failed(from_2d_vec,from_iterator): they know expected vs actual element counts at the failure point and currently discard them.