Add an unsafe `at_fast` method for unchecked read access to DVec and DMat.
This commit is contained in:
parent
3b814b462f
commit
72395f3546
21
src/dmat.rs
21
src/dmat.rs
|
@ -149,7 +149,14 @@ impl<N: Clone> DMat<N> {
|
||||||
pub fn at(&self, row: uint, col: uint) -> N {
|
pub fn at(&self, row: uint, col: uint) -> N {
|
||||||
assert!(row < self.nrows);
|
assert!(row < self.nrows);
|
||||||
assert!(col < self.ncols);
|
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<N: Clone + Mul<N, N> + Add<N, N> + Zero> Mul<DMat<N>, DMat<N>> for DMat<N>
|
||||||
let mut acc: N = Zero::zero();
|
let mut acc: N = Zero::zero();
|
||||||
|
|
||||||
for k in range(0u, self.ncols) {
|
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);
|
res.set(i, j, acc);
|
||||||
|
@ -186,7 +195,9 @@ RMul<DVec<N>> for DMat<N> {
|
||||||
let mut acc: N = Zero::zero();
|
let mut acc: N = Zero::zero();
|
||||||
|
|
||||||
for j in range(0u, self.ncols) {
|
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;
|
res.at[i] = acc;
|
||||||
|
@ -207,7 +218,9 @@ LMul<DVec<N>> for DMat<N> {
|
||||||
let mut acc: N = Zero::zero();
|
let mut acc: N = Zero::zero();
|
||||||
|
|
||||||
for j in range(0u, self.nrows) {
|
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;
|
res.at[i] = acc;
|
||||||
|
|
|
@ -35,6 +35,13 @@ impl<N: Zero + Clone> DVec<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<N: Clone> DVec<N> {
|
||||||
|
/// Indexing without bounds checking.
|
||||||
|
pub unsafe fn at_fast(&self, i: uint) -> N {
|
||||||
|
vec::raw::get(self.at, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<N: One + Clone> DVec<N> {
|
impl<N: One + Clone> DVec<N> {
|
||||||
/// Builds a vector filled with ones.
|
/// Builds a vector filled with ones.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue