ndarray_stats/lib.rs
1//! The [`ndarray-stats`] crate exposes statistical routines for `ArrayBase`,
2//! the *n*-dimensional array data structure provided by [`ndarray`].
3//!
4//! Currently available routines include:
5//! - [order statistics] (minimum, maximum, median, quantiles, etc.);
6//! - [summary statistics] (mean, skewness, kurtosis, central moments, etc.)
7//! - [partitioning];
8//! - [correlation analysis] (covariance, pearson correlation);
9//! - [measures from information theory] (entropy, KL divergence, etc.);
10//! - [measures of deviation] (count equal, L1, L2 distances, mean squared err etc.)
11//! - [histogram computation].
12//!
13//! Please feel free to contribute new functionality! A roadmap can be found [here].
14//!
15//! Our work is inspired by other existing statistical packages such as
16//! [`NumPy`] (Python) and [`StatsBase.jl`] (Julia) - any contribution bringing us closer to
17//! feature parity is more than welcome!
18//!
19//! [`ndarray-stats`]: https://github.com/rust-ndarray/ndarray-stats/
20//! [`ndarray`]: https://github.com/rust-ndarray/ndarray
21//! [order statistics]: trait.QuantileExt.html
22//! [partitioning]: trait.Sort1dExt.html
23//! [summary statistics]: trait.SummaryStatisticsExt.html
24//! [correlation analysis]: trait.CorrelationExt.html
25//! [measures of deviation]: trait.DeviationExt.html
26//! [measures from information theory]: trait.EntropyExt.html
27//! [histogram computation]: histogram/index.html
28//! [here]: https://github.com/rust-ndarray/ndarray-stats/issues/1
29//! [`NumPy`]: https://docs.scipy.org/doc/numpy-1.14.1/reference/routines.statistics.html
30//! [`StatsBase.jl`]: https://juliastats.github.io/StatsBase.jl/latest/
31
32pub use crate::correlation::CorrelationExt;
33pub use crate::deviation::DeviationExt;
34pub use crate::entropy::EntropyExt;
35pub use crate::histogram::HistogramExt;
36pub use crate::maybe_nan::{MaybeNan, MaybeNanExt};
37pub use crate::quantile::{interpolate, Quantile1dExt, QuantileExt};
38pub use crate::sort::Sort1dExt;
39pub use crate::summary_statistics::SummaryStatisticsExt;
40
41#[cfg(test)]
42#[macro_use]
43extern crate approx;
44
45#[macro_use]
46mod multi_input_error_macros {
47 macro_rules! return_err_if_empty {
48 ($arr:expr) => {
49 if $arr.len() == 0 {
50 return Err(MultiInputError::EmptyInput);
51 }
52 };
53 }
54 macro_rules! return_err_unless_same_shape {
55 ($arr_a:expr, $arr_b:expr) => {
56 use crate::errors::{MultiInputError, ShapeMismatch};
57 if $arr_a.shape() != $arr_b.shape() {
58 return Err(MultiInputError::ShapeMismatch(ShapeMismatch {
59 first_shape: $arr_a.shape().to_vec(),
60 second_shape: $arr_b.shape().to_vec(),
61 })
62 .into());
63 }
64 };
65 }
66}
67
68#[macro_use]
69mod private {
70 /// This is a public type in a private module, so it can be included in
71 /// public APIs, but other crates can't access it.
72 pub struct PrivateMarker;
73
74 /// Defines an associated function for a trait that is impossible for other
75 /// crates to implement. This makes it possible to add new associated
76 /// types/functions/consts/etc. to the trait without breaking changes.
77 macro_rules! private_decl {
78 () => {
79 /// This method makes this trait impossible to implement outside of
80 /// `ndarray-stats` so that we can freely add new methods, etc., to
81 /// this trait without breaking changes.
82 ///
83 /// We don't anticipate any other crates needing to implement this
84 /// trait, but if you do have such a use-case, please let us know.
85 ///
86 /// **Warning** This method is not considered part of the public
87 /// API, and client code should not rely on it being present. It
88 /// may be removed in a non-breaking release.
89 fn __private__(&self, _: crate::private::PrivateMarker);
90 };
91 }
92
93 /// Implements the associated function defined by `private_decl!`.
94 macro_rules! private_impl {
95 () => {
96 fn __private__(&self, _: crate::private::PrivateMarker) {}
97 };
98 }
99}
100
101mod correlation;
102mod deviation;
103mod entropy;
104pub mod errors;
105pub mod histogram;
106mod maybe_nan;
107mod quantile;
108mod sort;
109mod summary_statistics;