Make matrix Debug output semicolon-delimited rows

This commit is contained in:
Owen Brooks 2022-06-15 13:42:14 +10:00
parent dd801567f2
commit 831142d618
1 changed files with 41 additions and 3 deletions

View File

@ -195,9 +195,47 @@ pub struct Matrix<T, R, C, S> {
_phantoms: PhantomData<(T, R, C)>, _phantoms: PhantomData<(T, R, C)>,
} }
impl<T, R: Dim, C: Dim, S: fmt::Debug> fmt::Debug for Matrix<T, R, C, S> { impl<T: fmt::Debug, R: Dim, C: Dim, S: RawStorage<T, R, C> + fmt::Debug> fmt::Debug
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { for Matrix<T, R, C, S>
self.data.fmt(formatter) {
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, "}}")
} }
} }