Add a new_random
method to build a DMat
or DVec
filled with random numbers.
This commit is contained in:
parent
1cf3506e06
commit
05470bba90
10
src/dmat.rs
10
src/dmat.rs
@ -1,3 +1,5 @@
|
||||
use std::rand::Rand;
|
||||
use std::rand;
|
||||
use std::num::{One, Zero};
|
||||
use std::vec;
|
||||
use std::cmp::ApproxEq;
|
||||
@ -33,6 +35,14 @@ impl<N: Zero + Clone> DMat<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Rand> DMat<N> {
|
||||
/// Builds a matrix filled with random values.
|
||||
#[inline]
|
||||
pub fn new_random(nrows: uint, ncols: uint) -> DMat<N> {
|
||||
DMat::from_fn(nrows, ncols, |_, _| rand::random())
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: One + Clone> DMat<N> {
|
||||
/// Builds a matrix filled with a given constant.
|
||||
#[inline]
|
||||
|
12
src/dvec.rs
12
src/dvec.rs
@ -1,4 +1,6 @@
|
||||
use std::num::{Zero, One, Algebraic};
|
||||
use std::rand::Rand;
|
||||
use std::rand;
|
||||
use std::vec;
|
||||
use std::vec::{VecIterator, VecMutIterator};
|
||||
use std::cmp::ApproxEq;
|
||||
@ -44,6 +46,14 @@ impl<N: One + Clone> DVec<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Rand> DVec<N> {
|
||||
/// Builds a vector filled with random values.
|
||||
#[inline]
|
||||
pub fn new_random(dim: uint) -> DVec<N> {
|
||||
DVec::from_fn(dim, |_| rand::random())
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Clone> DVec<N> {
|
||||
/// Builds a vector filled with a constant.
|
||||
#[inline]
|
||||
@ -52,7 +62,7 @@ impl<N: Clone> DVec<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Clone> DVec<N> {
|
||||
impl<N> DVec<N> {
|
||||
/// Builds a vector filled with the result of a function.
|
||||
#[inline(always)]
|
||||
pub fn from_fn(dim: uint, f: &fn(uint) -> N) -> DVec<N> {
|
||||
|
Loading…
Reference in New Issue
Block a user