Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all compilation warnings #42

Merged
merged 2 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,16 @@ impl MongePrim {
match *self {
MongePrim::ConstantRows => {
for mut row in matrix.genrows_mut() {
row.fill(rng.gen());
if rng.gen::<bool>() {
row.fill(T::one())
}
}
}
MongePrim::ConstantCols => {
for mut col in matrix.gencolumns_mut() {
col.fill(rng.gen());
if rng.gen::<bool>() {
col.fill(T::one())
}
}
}
MongePrim::UpperRightOnes => {
Expand All @@ -508,13 +512,15 @@ pub fn random_monge_matrix<R: Rng, T: PrimInt>(m: usize, n: usize, rng: &mut R)
where
Standard: Distribution<T>,
{
let monge_primitives = [
MongePrim::ConstantRows,
MongePrim::ConstantCols,
MongePrim::LowerLeftOnes,
MongePrim::UpperRightOnes,
];
let mut matrix = Array2::from_elem((m, n), T::zero());
for _ in 0..(m + n) {
let monge = if rng.gen::<bool>() {
MongePrim::LowerLeftOnes
} else {
MongePrim::UpperRightOnes
};
let monge = monge_primitives[rng.gen_range(0, monge_primitives.len())];
matrix = matrix + monge.to_matrix(m, n, rng);
}
matrix
Expand All @@ -523,7 +529,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use ndarray::arr2;
use ndarray::{arr2, Array};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;

Expand All @@ -543,33 +549,22 @@ mod tests {
fn monge_constant_rows() {
let mut rng = ChaCha20Rng::seed_from_u64(0);
let matrix: Array2<u8> = MongePrim::ConstantRows.to_matrix(5, 4, &mut rng);
assert_eq!(
matrix,
arr2(&[
[178, 178, 178, 178],
[214, 214, 214, 214],
[168, 168, 168, 168],
[126, 126, 126, 126],
[192, 192, 192, 192],
])
);
assert!(is_monge(&matrix));
for row in matrix.genrows() {
let elem = row[0];
assert_eq!(row, Array::from_elem(matrix.ncols(), elem));
}
}

#[test]
fn monge_constant_cols() {
let mut rng = ChaCha20Rng::seed_from_u64(0);
let matrix: Array2<u8> = MongePrim::ConstantCols.to_matrix(5, 4, &mut rng);
assert!(is_monge(&matrix));
assert_eq!(
matrix,
arr2(&[
[178, 214, 168, 126],
[178, 214, 168, 126],
[178, 214, 168, 126],
[178, 214, 168, 126],
[178, 214, 168, 126]
])
);
for column in matrix.gencolumns() {
let elem = column[0];
assert_eq!(column, Array::from_elem(matrix.nrows(), elem));
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn online_linear_complexity() {
let mut data = vec![];

for &size in &[1, 2, 3, 4, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100] {
let mut matrix: Array2<i32> = random_monge_matrix(size, size, &mut rng);
let matrix: Array2<i32> = random_monge_matrix(size, size, &mut rng);
let count = std::cell::RefCell::new(0);
online_column_minima(0, size, |_, i, j| {
*count.borrow_mut() += 1;
Expand Down