diff --git a/src/arrayformat.rs b/src/arrayformat.rs index dce405e8b..345c942eb 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -105,9 +105,13 @@ impl<'a, A: fmt::Debug, S, D: Dimension> fmt::Debug for ArrayBase { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Add extra information for Debug - try!(format_array(self, f, <_>::fmt)); - try!(write!(f, " shape={:?}, strides={:?}, layout={:?}", - self.shape(), self.strides(), layout=self.view().layout())); + format_array(self, f, <_>::fmt)?; + write!(f, " shape={:?}, strides={:?}, layout={:?}", + self.shape(), self.strides(), layout=self.view().layout())?; + match D::NDIM { + Some(ndim) => write!(f, ", const ndim={}", ndim)?, + None => write!(f, ", dynamic ndim={}", self.ndim())?, + } Ok(()) } } diff --git a/tests/format.rs b/tests/format.rs index a245413cf..4dbc939cc 100644 --- a/tests/format.rs +++ b/tests/format.rs @@ -1,7 +1,7 @@ - extern crate ndarray; -use ndarray::{arr0, rcarr1, aview1}; +use ndarray::prelude::*; +use ndarray::rcarr1; #[test] fn formatting() @@ -35,3 +35,20 @@ fn formatting() let s = format!("{:02x}", aview1::(&[1, 0xff, 0xfe])); assert_eq!(s, "[01, ff, fe]"); } + +#[test] +fn debug_format() { + let a = Array2::::zeros((3, 4)); + assert_eq!( + format!("{:?}", a), + "[[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] shape=[3, 4], strides=[4, 1], layout=C (0x1), const ndim=2" + ); + assert_eq!( + format!("{:?}", a.into_dyn()), + "[[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] shape=[3, 4], strides=[4, 1], layout=C (0x1), dynamic ndim=2" + ); +}