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

Remove smawk_ prefix from optimized functions #75

Merged
merged 1 commit into from
Sep 17, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You can now efficiently find row and column minima. Here is an example where we
find the column minima:

```rust
use smawk::smawk_column_minima;
use smawk::Matrix;

let matrix = vec![
vec![3, 2, 4, 5, 6],
Expand All @@ -40,7 +40,7 @@ let matrix = vec![
vec![4, 3, 2, 1, 1],
];
let minima = vec![1, 1, 4, 4, 4];
assert_eq!(smawk_column_minima(&matrix), minima);
assert_eq!(smawk::column_minima(&matrix), minima);
```

The `minima` vector gives the index of the minimum value per column, so
Expand Down
4 changes: 2 additions & 2 deletions benches/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ repeat!(
(row_smawk_200, column_smawk_200, 200),
(row_smawk_400, column_smawk_400, 400)
],
smawk::smawk_row_minima,
smawk::smawk_column_minima
smawk::row_minima,
smawk::column_minima
);
50 changes: 25 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
//! # Examples
//!
//! Computing the column minima of an *m* ✕ *n* Monge matrix can be
//! done efficiently with `smawk_column_minima`:
//! done efficiently with `smawk::column_minima`:
//!
//! ```
//! use smawk::{Matrix, smawk_column_minima};
//! use smawk::Matrix;
//!
//! let matrix = vec![
//! vec![3, 2, 4, 5, 6],
Expand All @@ -22,7 +22,7 @@
//! vec![4, 3, 2, 1, 1],
//! ];
//! let minima = vec![1, 1, 4, 4, 4];
//! assert_eq!(smawk_column_minima(&matrix), minima);
//! assert_eq!(smawk::column_minima(&matrix), minima);
//! ```
//!
//! The `minima` vector gives the index of the minimum value per
Expand Down Expand Up @@ -168,11 +168,11 @@ impl<T: Copy> Matrix<T> for ndarray::Array2<T> {
/// # Examples
///
/// ```
/// use smawk::{Matrix, smawk_row_minima};
/// use smawk::Matrix;
/// let matrix = vec![vec![4, 2, 4, 3],
/// vec![5, 3, 5, 3],
/// vec![5, 3, 3, 1]];
/// assert_eq!(smawk_row_minima(&matrix),
/// assert_eq!(smawk::row_minima(&matrix),
/// vec![1, 1, 3]);
/// ```
///
Expand All @@ -182,7 +182,7 @@ impl<T: Copy> Matrix<T> for ndarray::Array2<T> {
///
/// [pads]: https://github.com/jfinkels/PADS/blob/master/pads/smawk.py
/// [SMAWK algorithm]: https://en.wikipedia.org/wiki/SMAWK_algorithm
pub fn smawk_row_minima<T: PartialOrd + Copy, M: Matrix<T>>(matrix: &M) -> Vec<usize> {
pub fn row_minima<T: PartialOrd + Copy, M: Matrix<T>>(matrix: &M) -> Vec<usize> {
// Benchmarking shows that SMAWK performs roughly the same on row-
// and column-major matrices.
let mut minima = vec![0; matrix.nrows()];
Expand Down Expand Up @@ -210,11 +210,11 @@ pub fn smawk_row_minima<T: PartialOrd + Copy, M: Matrix<T>>(matrix: &M) -> Vec<u
/// # Examples
///
/// ```
/// use smawk::{Matrix, smawk_column_minima};
/// use smawk::Matrix;
/// let matrix = vec![vec![4, 2, 4, 3],
/// vec![5, 3, 5, 3],
/// vec![5, 3, 3, 1]];
/// assert_eq!(smawk_column_minima(&matrix),
/// assert_eq!(smawk::column_minima(&matrix),
/// vec![0, 0, 2, 2]);
/// ```
///
Expand All @@ -224,7 +224,7 @@ pub fn smawk_row_minima<T: PartialOrd + Copy, M: Matrix<T>>(matrix: &M) -> Vec<u
///
/// [SMAWK algorithm]: https://en.wikipedia.org/wiki/SMAWK_algorithm
/// [pads]: https://github.com/jfinkels/PADS/blob/master/pads/smawk.py
pub fn smawk_column_minima<T: PartialOrd + Copy, M: Matrix<T>>(matrix: &M) -> Vec<usize> {
pub fn column_minima<T: PartialOrd + Copy, M: Matrix<T>>(matrix: &M) -> Vec<usize> {
let mut minima = vec![0; matrix.ncols()];
smawk_inner(
&|i, j| matrix.index(i, j),
Expand Down Expand Up @@ -415,8 +415,8 @@ mod tests {
#[test]
fn smawk_1x1() {
let matrix = vec![vec![2]];
assert_eq!(smawk_row_minima(&matrix), vec![0]);
assert_eq!(smawk_column_minima(&matrix), vec![0]);
assert_eq!(row_minima(&matrix), vec![0]);
assert_eq!(column_minima(&matrix), vec![0]);
}

#[test]
Expand All @@ -425,15 +425,15 @@ mod tests {
vec![3], //
vec![2],
];
assert_eq!(smawk_row_minima(&matrix), vec![0, 0]);
assert_eq!(smawk_column_minima(&matrix), vec![1]);
assert_eq!(row_minima(&matrix), vec![0, 0]);
assert_eq!(column_minima(&matrix), vec![1]);
}

#[test]
fn smawk_1x2() {
let matrix = vec![vec![2, 1]];
assert_eq!(smawk_row_minima(&matrix), vec![1]);
assert_eq!(smawk_column_minima(&matrix), vec![0, 0]);
assert_eq!(row_minima(&matrix), vec![1]);
assert_eq!(column_minima(&matrix), vec![0, 0]);
}

#[test]
Expand All @@ -442,8 +442,8 @@ mod tests {
vec![3, 2], //
vec![2, 1],
];
assert_eq!(smawk_row_minima(&matrix), vec![1, 1]);
assert_eq!(smawk_column_minima(&matrix), vec![1, 1]);
assert_eq!(row_minima(&matrix), vec![1, 1]);
assert_eq!(column_minima(&matrix), vec![1, 1]);
}

#[test]
Expand All @@ -453,8 +453,8 @@ mod tests {
vec![3, 4, 4],
vec![2, 3, 3],
];
assert_eq!(smawk_row_minima(&matrix), vec![0, 0, 0]);
assert_eq!(smawk_column_minima(&matrix), vec![2, 2, 2]);
assert_eq!(row_minima(&matrix), vec![0, 0, 0]);
assert_eq!(column_minima(&matrix), vec![2, 2, 2]);
}

#[test]
Expand All @@ -465,8 +465,8 @@ mod tests {
vec![2, 3, 3, 3],
vec![2, 2, 2, 2],
];
assert_eq!(smawk_row_minima(&matrix), vec![0, 0, 0, 0]);
assert_eq!(smawk_column_minima(&matrix), vec![1, 3, 3, 3]);
assert_eq!(row_minima(&matrix), vec![0, 0, 0, 0]);
assert_eq!(column_minima(&matrix), vec![1, 3, 3, 3]);
}

#[test]
Expand All @@ -478,8 +478,8 @@ mod tests {
vec![3, 2, 4, 3, 4],
vec![4, 3, 2, 1, 1],
];
assert_eq!(smawk_row_minima(&matrix), vec![1, 1, 1, 1, 3]);
assert_eq!(smawk_column_minima(&matrix), vec![1, 1, 4, 4, 4]);
assert_eq!(row_minima(&matrix), vec![1, 1, 1, 1, 3]);
assert_eq!(column_minima(&matrix), vec![1, 1, 4, 4, 4]);
}

#[test]
Expand Down Expand Up @@ -541,8 +541,8 @@ mod tests {
vec![3.0, 2.0], //
vec![2.0, 1.0],
];
assert_eq!(smawk_row_minima(&matrix), vec![1, 1]);
assert_eq!(smawk_column_minima(&matrix), vec![1, 1]);
assert_eq!(row_minima(&matrix), vec![1, 1]);
assert_eq!(column_minima(&matrix), vec![1, 1]);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions tests/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use ndarray::{s, Array2};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use smawk::online_column_minima;
use smawk::{brute_force, recursive};
use smawk::{online_column_minima, smawk_column_minima, smawk_row_minima};

mod random_monge;
use random_monge::random_monge_matrix;
Expand All @@ -24,7 +24,7 @@ fn column_minima_agree() {
// Compute and test row minima.
let brute_force = brute_force::row_minima(&matrix);
let recursive = recursive::row_minima(&matrix);
let smawk = smawk_row_minima(&matrix);
let smawk = smawk::row_minima(&matrix);
assert_eq!(
brute_force, recursive,
"recursive and brute force differs on:\n{:?}",
Expand All @@ -39,7 +39,7 @@ fn column_minima_agree() {
// Do the same for the column minima.
let brute_force = brute_force::column_minima(&matrix);
let recursive = recursive::column_minima(&matrix);
let smawk = smawk_column_minima(&matrix);
let smawk = smawk::column_minima(&matrix);
assert_eq!(
brute_force, recursive,
"recursive and brute force differs on:\n{:?}",
Expand Down
Loading