Add WeightMatrix::from_fn()

This commit is contained in:
Michael Neumann 2015-10-30 12:51:05 +01:00
parent 188dc61817
commit 7abc850887

View File

@ -49,6 +49,11 @@ impl<T: WeightNum> WeightMatrix<T> {
WeightMatrix { c: SquareMatrix::from_row_vec(n, data) }
}
pub fn from_fn<F: Fn((usize, usize)) -> T>(n: usize, f: F) -> WeightMatrix<T> {
assert!(n > 0);
WeightMatrix { c: SquareMatrix::from_fn(n, f) }
}
#[inline(always)]
fn n(&self) -> usize {
self.c.n()