Add `nrow()`, `ncols()` methods for `DMat`, and Container impl. for `DVec`.

This commit is contained in:
Sébastien Crozet 2013-09-08 17:19:50 +02:00
parent 3ab06faef6
commit 57b89b38df
2 changed files with 20 additions and 0 deletions

View File

@ -63,6 +63,16 @@ impl<N> DMat<N> {
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)?

View File

@ -59,19 +59,29 @@ impl<N: Clone> DVec<N> {
}
}
impl<N> Container for DVec<N> {
#[inline]
fn len(&self) -> uint {
self.at.len()
}
}
impl<N> Iterable<N> for DVec<N> {
#[inline]
fn iter<'l>(&'l self) -> VecIterator<'l, N> {
self.at.iter()
}
}
impl<N> IterableMut<N> for DVec<N> {
#[inline]
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
self.at.mut_iter()
}
}
impl<N> FromIterator<N> for DVec<N> {
#[inline]
fn from_iterator<I: Iterator<N>>(mut param: &mut I) -> DVec<N> {
let mut res = DVec { at: ~[] };