Fix coordinate calculation in DMat::from_fn().
The builder function `f` was receiving incorrect coordinates, often involving a uint underflow. Added a test case to verify the new behavior.
This commit is contained in:
parent
97c2e71fd6
commit
ebe1ed1f16
|
@ -3,3 +3,4 @@
|
|||
doc
|
||||
lib
|
||||
TODO
|
||||
target/
|
||||
|
|
|
@ -139,7 +139,7 @@ impl<N> DMat<N> {
|
|||
DMat {
|
||||
nrows: nrows,
|
||||
ncols: ncols,
|
||||
mij: Vec::from_fn(nrows * ncols, |i| { let m = i % ncols; f(m, m - i * ncols) })
|
||||
mij: Vec::from_fn(nrows * ncols, |i| f(i % nrows, i / nrows))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -266,3 +266,16 @@ fn test_decomp_qr_mat5() {
|
|||
fn test_decomp_qr_mat6() {
|
||||
test_decomp_qr_impl!(Mat6<f64>);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_from_fn() {
|
||||
let actual: DMat<uint> = DMat::from_fn( 3, 4,
|
||||
|i,j| 10*i + j);
|
||||
let expected: DMat<uint> = DMat::from_row_vec(3, 4,
|
||||
[0_0, 0_1, 0_2, 0_3,
|
||||
1_0, 1_1, 1_2, 1_3,
|
||||
2_0, 2_1, 2_2, 2_3 ]);
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue