Skip to content

Commit

Permalink
Merge pull request #44 from cjneely10/development
Browse files Browse the repository at this point in the history
Better error handling
  • Loading branch information
cjneely10 authored Jun 23, 2022
2 parents cd44276 + 820a759 commit 53bf910
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 84 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]

### Python bindings
- [PyO3](https://github.com/PyO3/pyo3)-derived bindings for use within Python

## [0.2.0] - 2022-07-24
### Added
- Better stderr messages on file-parsing errors
- Line/col numbers and kind of error
- Disallow `nan` values in input per Affinity Propagation algorithm requirements

### Changed
- Small edits to pass-by-value instead of by-reference

### Fixed
- `nan` values were accepted as valid input.
- No valid similarity calculation is present for `nan` values

## [0.1.1] - 2022-02-15
First release of `affinityprop`
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "affinityprop"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
authors = ["Chris Neely <[email protected]>"]
license = "GPL-3.0"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Rust](https://github.com/cjneely10/affinityprop/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/cjneely10/affinityprop/actions/workflows/rust.yml)
[![affinityprop crate](https://img.shields.io/crates/v/affinityprop?color=blue&style=flat)](https://crates.io/crates/affinityprop)
[![affinityprop docs](https://img.shields.io/docsrs/affinityprop)](https://docs.rs/affinityprop/0.1.1/affinityprop/)
[![affinityprop docs](https://img.shields.io/docsrs/affinityprop)](https://docs.rs/affinityprop/0.2.0/affinityprop/)
[![GitHub](https://img.shields.io/github/license/cjneely10/affinityprop)](https://www.gnu.org/licenses/gpl-3.0.html)
[![affinityprop: rustc 1.58](https://img.shields.io/badge/affinityprop-rustc__1.58-blue)](https://doc.rust-lang.org/rustc/what-is-rustc.html)
![coverage](https://img.shields.io/badge/coverage-95%25-success)
Expand Down Expand Up @@ -48,7 +48,7 @@ with `rustc >=1.58`
## In Rust code
```toml
[dependencies]
affinityprop = "0.1.1"
affinityprop = "0.2.0"
ndarray = "0.15.4"
```

Expand Down Expand Up @@ -146,7 +146,7 @@ IDs will automatically be assigned by zero-based index.

### Help Menu
```text
affinityprop 0.1.1
affinityprop 0.2.0
Chris N. <[email protected]>
Vectorized and Parallelized Affinity Propagation
Expand Down
13 changes: 5 additions & 8 deletions src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
Zip::from(self.tmp.axis_iter_mut(Axis(0)))
.and(self.similarity.axis_iter(Axis(0)))
.and(&max1)
.par_for_each(|mut t, s, m| t.iter_mut().zip(s.iter()).for_each(|(t, s)| *t = *s - *m));
.par_for_each(|mut t, s, &m| t.iter_mut().zip(s.iter()).for_each(|(t, s)| *t = *s - m));

// tmp[ind, I] = S[ind, I] - Y2
Zip::from(self.tmp.axis_iter_mut(Axis(0)))
Expand All @@ -203,7 +203,7 @@ where
// np.maximum(R, 0, tmp)
Zip::from(&mut self.tmp)
.and(&self.responsibility)
.par_for_each(|t, r| *t = *r);
.par_for_each(|t, &r| *t = r);
self.tmp.par_map_inplace(|v| {
if *v < self.zero {
*v = self.zero;
Expand Down Expand Up @@ -248,9 +248,9 @@ where
fn max_argmax(data: ArrayView<F, Dim<[usize; 1]>>) -> (usize, F) {
let mut max_pos = 0;
let mut max: F = data[0];
data.iter().enumerate().for_each(|(idx, val)| {
if *val > max {
max = *val;
data.iter().enumerate().for_each(|(idx, &val)| {
if val > max {
max = val;
max_pos = idx;
}
});
Expand Down Expand Up @@ -313,9 +313,6 @@ mod test {
assert!(
actual.len() == exemplars.len()
&& actual.iter().all(|(idx, values)| {
if !exemplars.contains_key(idx) {
return false;
}
let v: HashSet<usize> =
HashSet::from_iter(values.iter().map(|v| v.clone()));
let a: HashSet<usize> = HashSet::from_iter(
Expand Down
23 changes: 7 additions & 16 deletions src/bin/affinityprop/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod ops;
#[cfg(not(tarpaulin_include))]
fn main() {
let matches = clap_app!(affinityprop =>
(version: "0.1.1")
(version: "0.2.0")
(author: "Chris N. <[email protected]>")
(about: "Vectorized and Parallelized Affinity Propagation")
(@arg INPUT: -i --input +takes_value +required "Path to input file")
Expand Down Expand Up @@ -166,20 +166,11 @@ fn predict<F>(
Some(pref) => Preference::Value(pref),
None => Preference::Median,
};
let a: (bool, HashMap<usize, Vec<usize>>);
match similarity {
1 => {
a = ap.predict(&x, NegCosine::default(), preference);
}
2 => {
a = ap.predict(&x, LogEuclidean::default(), preference);
}
3 => {
a = ap.predict_precalculated(x, preference);
}
_ => {
a = ap.predict(&x, NegEuclidean::default(), preference);
}
}
let a: (bool, HashMap<usize, Vec<usize>>) = match similarity {
1 => ap.predict(&x, NegCosine::default(), preference),
2 => ap.predict(&x, LogEuclidean::default(), preference),
3 => ap.predict_precalculated(x, preference),
_ => ap.predict(&x, NegEuclidean::default(), preference),
};
display_results(a.0, &a.1, y);
}
Loading

0 comments on commit 53bf910

Please sign in to comment.