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

Histogram error handling #25

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bfb0db7
Use Option as return type where things might fail
LukeMathWalker Jan 29, 2019
4057a72
Test suite aligned with docs
LukeMathWalker Jan 29, 2019
fa1eb34
Equispaced does not panic anymore
Jan 30, 2019
669a33f
Fixed some tests
Jan 30, 2019
0e5eb6b
Fixed FD tests
Jan 30, 2019
04cf0a7
Fixed wrong condition in IF
Jan 30, 2019
4f429bc
Fixed wrong test
Jan 30, 2019
4e74c48
Added new test for EquiSpaced and fixed old one
Jan 30, 2019
56b7e45
Fixed doc tests
Jan 30, 2019
12906fd
Fix docs.
LukeMathWalker Feb 2, 2019
9d1862f
Fix docs.
LukeMathWalker Feb 2, 2019
64789d6
Fix docs.
LukeMathWalker Feb 2, 2019
fe150d1
Fmt
LukeMathWalker Mar 26, 2019
facd4c4
Merge master
LukeMathWalker Mar 26, 2019
b28c35a
Create StrategyError
LukeMathWalker Mar 26, 2019
c06f382
Fmt
LukeMathWalker Mar 26, 2019
4a24f5a
Return Result. Fix Equispaced, Sqrt and Rice
LukeMathWalker Mar 26, 2019
f708a17
Fix Rice
LukeMathWalker Mar 26, 2019
58788db
Fixed Sturges
LukeMathWalker Mar 26, 2019
3014f77
Fix strategies
LukeMathWalker Mar 26, 2019
17e5efc
Fix match
LukeMathWalker Mar 26, 2019
63abed5
Tests compile
LukeMathWalker Mar 26, 2019
4a4b489
Fix assertion
LukeMathWalker Mar 26, 2019
f692887
Fmt
LukeMathWalker Mar 26, 2019
a8ad4b1
Add more error types
jturner314 Mar 31, 2019
29f56f3
Rename StrategyError to BinsBuildError
jturner314 Apr 1, 2019
bca2dc9
Make GridBuilder::from_array return Result
jturner314 Apr 1, 2019
f41b317
Make BinsBuildError enum non-exhaustive
jturner314 Apr 1, 2019
308e0e7
Merge pull request #4 from jturner314/histogram-error-handling
LukeMathWalker Apr 1, 2019
c280c6b
Use lazy OR operator.
LukeMathWalker Apr 1, 2019
6481509
Merge remote-tracking branch 'origin/histogram-error-handling' into h…
LukeMathWalker Apr 1, 2019
701842d
Use lazy OR operator.
LukeMathWalker Apr 1, 2019
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
11 changes: 7 additions & 4 deletions src/histogram/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use ndarray::{ArrayBase, Data, Ix1, Ix2, Axis};
///
/// // The optimal grid layout is inferred from the data,
/// // specifying a strategy (Auto in this case)
/// let grid = GridBuilder::<Auto<usize>>::from_array(&observations).build();
/// let grid = GridBuilder::<Auto<usize>>::from_array(&observations).unwrap().build();
/// let expected_grid = Grid::from(vec![Bins::new(Edges::from(vec![1, 20, 39, 58, 77, 96, 115]))]);
/// assert_eq!(grid, expected_grid);
///
Expand Down Expand Up @@ -160,17 +160,20 @@ where
/// it returns a `GridBuilder` instance that has learned the required parameter
/// to build a [`Grid`] according to the specified [`strategy`].
///
/// It returns `None` if it is not possible to build a [`Grid`] given
/// the observed data according to the chosen [`strategy`].
///
/// [`Grid`]: struct.Grid.html
/// [`strategy`]: strategies/index.html
pub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Self
pub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Option<Self>
where
S: Data<Elem=A>,
{
let bin_builders = array
let bin_builders: Option<Vec<B>> = array
.axis_iter(Axis(1))
.map(|data| B::from_array(&data))
.collect();
Self { bin_builders }
bin_builders.map(|b| Self { bin_builders: b})
}

/// Returns a [`Grid`] instance, built accordingly to the specified [`strategy`]
Expand Down
2 changes: 1 addition & 1 deletion src/histogram/histograms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub trait HistogramExt<A, S>
/// [n64(-1.), n64(-0.5)],
/// [n64(0.5), n64(-1.)]
/// ];
/// let grid = GridBuilder::<Sqrt<N64>>::from_array(&observations).build();
/// let grid = GridBuilder::<Sqrt<N64>>::from_array(&observations).unwrap().build();
/// let expected_grid = Grid::from(
/// vec![
/// Bins::new(Edges::from(vec![n64(-1.), n64(0.), n64(1.), n64(2.)])),
Expand Down
Loading