Add Rand for nmat.
This commit is contained in:
parent
98b484c311
commit
622435f7ad
|
@ -1,4 +1,5 @@
|
|||
use core::num::{One, Zero};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use core::vec::{from_elem, swap, all, all2};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
|
@ -250,6 +251,23 @@ impl<D, T:FuzzyEq<T>> FuzzyEq<T> for NMat<D, T>
|
|||
{ all2(self.mij, other.mij, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
|
||||
}
|
||||
|
||||
impl<D: Dim, T: Rand + Zero + Copy> Rand for NMat<D, T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> NMat<D, T>
|
||||
{
|
||||
let dim = Dim::dim::<D>();
|
||||
let mut res : NMat<D, T> = Zero::zero();
|
||||
|
||||
for uint::range(0u, dim) |i|
|
||||
{
|
||||
for uint::range(0u, dim) |j|
|
||||
{ res.set(i, j, &rng.gen()); }
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Dim, T: ToStr> ToStr for NMat<D, T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
Loading…
Reference in New Issue