diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 8f8786c1..9afd8a14 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -195,9 +195,47 @@ pub struct Matrix { _phantoms: PhantomData<(T, R, C)>, } -impl fmt::Debug for Matrix { - fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - self.data.fmt(formatter) +impl + fmt::Debug> fmt::Debug + for Matrix +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + write!(f, "Matrix {{ ")?; + if f.alternate() { + write!(f, "\n ")?; + } + write!(f, "data: [")?; + let nrows = self.nrows(); + let ncols = self.ncols(); + for i in 0..nrows { + for j in 0..ncols { + if j != 0 { + write!(f, ", ")?; + } + // Safety: the indices are within range + unsafe { + (*self.data.get_unchecked(i, j)).fmt(f)?; + } + } + if i != nrows - 1 { + write!(f, "; ")?; + } + if f.alternate() && i != nrows - 1 { + write!(f, "\n ")?; + } + } + write!(f, "], ")?; + if f.alternate() { + write!(f, "\n ")?; + } + write!(f, "nrows: {:?}, ", nrows)?; + if f.alternate() { + write!(f, "\n ")?; + } + write!(f, "ncols: {:?} ", ncols)?; + if f.alternate() { + writeln!(f, "")?; + } + write!(f, "}}") } }