diff --git a/src/dmat.rs b/src/dmat.rs index e595d195..ae1edfd7 100644 --- a/src/dmat.rs +++ b/src/dmat.rs @@ -149,7 +149,14 @@ impl DMat { pub fn at(&self, row: uint, col: uint) -> N { assert!(row < self.nrows); assert!(col < self.ncols); - self.mij[self.offset(row, col)].clone() + unsafe { vec::raw::get(self.mij, self.offset(row, col)) } + } + + // FIXME: put that on a `raw` module. + /// Just like `at` without bounds checking. + #[inline] + pub unsafe fn at_fast(&self, row: uint, col: uint) -> N { + vec::raw::get(self.mij, self.offset(row, col)) } } @@ -164,7 +171,9 @@ impl + Add + Zero> Mul, DMat> for DMat let mut acc: N = Zero::zero(); for k in range(0u, self.ncols) { - acc = acc + self.at(i, k) * other.at(k, j); + unsafe { + acc = acc + self.at_fast(i, k) * other.at_fast(k, j); + } } res.set(i, j, acc); @@ -186,7 +195,9 @@ RMul> for DMat { let mut acc: N = Zero::zero(); for j in range(0u, self.ncols) { - acc = acc + other.at[j] * self.at(i, j); + unsafe { + acc = acc + other.at_fast(j) * self.at_fast(i, j); + } } res.at[i] = acc; @@ -207,7 +218,9 @@ LMul> for DMat { let mut acc: N = Zero::zero(); for j in range(0u, self.nrows) { - acc = acc + other.at[j] * self.at(j, i); + unsafe { + acc = acc + other.at_fast(j) * self.at_fast(j, i); + } } res.at[i] = acc; diff --git a/src/dvec.rs b/src/dvec.rs index 87d3f817..2c5fde60 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -35,6 +35,13 @@ impl DVec { } } +impl DVec { + /// Indexing without bounds checking. + pub unsafe fn at_fast(&self, i: uint) -> N { + vec::raw::get(self.at, i) + } +} + impl DVec { /// Builds a vector filled with ones. ///