From 57b89b38df7da1b4ad977731f12ab094fc1dc83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 8 Sep 2013 17:19:50 +0200 Subject: [PATCH] Add `nrow()`, `ncols()` methods for `DMat`, and Container impl. for `DVec`. --- src/dmat.rs | 10 ++++++++++ src/dvec.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/dmat.rs b/src/dmat.rs index 41142f17..16e700fb 100644 --- a/src/dmat.rs +++ b/src/dmat.rs @@ -63,6 +63,16 @@ impl DMat { mij: vec::from_fn(nrows * ncols, |i| { let m = i % ncols; f(m, m - i * ncols) }) } } + + /// The number of row on the matrix. + pub fn nrows(&self) -> uint { + self.nrows + } + + /// The number of columns on the matrix. + pub fn ncols(&self) -> uint { + self.ncols + } } // FIXME: add a function to modify the dimension (to avoid useless allocations)? diff --git a/src/dvec.rs b/src/dvec.rs index 5caee856..7931543d 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -59,19 +59,29 @@ impl DVec { } } +impl Container for DVec { + #[inline] + fn len(&self) -> uint { + self.at.len() + } +} + impl Iterable for DVec { + #[inline] fn iter<'l>(&'l self) -> VecIterator<'l, N> { self.at.iter() } } impl IterableMut for DVec { + #[inline] fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { self.at.mut_iter() } } impl FromIterator for DVec { + #[inline] fn from_iterator>(mut param: &mut I) -> DVec { let mut res = DVec { at: ~[] };