Add rand for nvec.
This commit is contained in:
parent
622435f7ad
commit
39707b42dc
|
@ -1,4 +1,5 @@
|
||||||
use core::vec::{map_zip, from_elem, map, all, all2};
|
use core::vec::{map_zip, from_elem, map, all, all2};
|
||||||
|
use core::rand::{Rand, Rng, RngUtil};
|
||||||
use core::num::{Zero, Algebraic};
|
use core::num::{Zero, Algebraic};
|
||||||
use std::cmp::FuzzyEq;
|
use std::cmp::FuzzyEq;
|
||||||
use traits::dim::Dim;
|
use traits::dim::Dim;
|
||||||
|
@ -93,6 +94,20 @@ impl<D, T:FuzzyEq<T>> FuzzyEq<T> for NVec<D, T>
|
||||||
{ all2(self.at, other.at, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
|
{ all2(self.at, other.at, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: Dim, T: Rand + Zero + Copy> Rand for NVec<D, T>
|
||||||
|
{
|
||||||
|
fn rand<R: Rng>(rng: &R) -> NVec<D, T>
|
||||||
|
{
|
||||||
|
let dim = Dim::dim::<D>();
|
||||||
|
let mut res : NVec<D, T> = Zero::zero();
|
||||||
|
|
||||||
|
for uint::range(0u, dim) |i|
|
||||||
|
{ res.at[i] = rng.gen() }
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<D: Dim, T:ToStr> ToStr for NVec<D, T>
|
impl<D: Dim, T:ToStr> ToStr for NVec<D, T>
|
||||||
{
|
{
|
||||||
fn to_str(&self) -> ~str
|
fn to_str(&self) -> ~str
|
||||||
|
|
Loading…
Reference in New Issue