Skip to content

Commit 10bdfa9

Browse files
committed
Rename percentile -> quantile
1 parent 87f9882 commit 10bdfa9

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ndarray-stats = "0.1"
2020
* **0.1.0** (not yet released)
2121

2222
* Initial release.
23-
* Includes percentile functionality provided by @LukeMathWalker. (See
23+
* Includes quantile functionality provided by @LukeMathWalker. (See
2424
[`ndarray` issue #461](https://github.com/bluss/ndarray/pull/461).)
2525

2626
## Contributing

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ extern crate rand;
99
extern crate quickcheck;
1010

1111
pub use maybe_nan::{MaybeNan, MaybeNanExt};
12-
pub use percentile::{interpolate, PercentileExt};
12+
pub use quantile::{interpolate, QuantileExt};
1313
pub use sort::Sort1dExt;
1414

1515
mod maybe_nan;
16-
mod percentile;
16+
mod quantile;
1717
mod sort;

src/percentile.rs renamed to src/quantile.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ pub mod interpolate {
1010
use num_traits::{FromPrimitive, ToPrimitive};
1111
use std::ops::{Add, Div};
1212

13-
/// Used to provide an interpolation strategy to [`percentile_axis_mut`].
13+
/// Used to provide an interpolation strategy to [`quantile_axis_mut`].
1414
///
15-
/// [`percentile_axis_mut`]: ../trait.PercentileExt.html#tymethod.percentile_axis_mut
15+
/// [`quantile_axis_mut`]: ../trait.QuantileExt.html#tymethod.quantile_axis_mut
1616
pub trait Interpolate<T> {
1717
#[doc(hidden)]
18-
fn float_percentile_index(q: f64, len: usize) -> f64 {
18+
fn float_quantile_index(q: f64, len: usize) -> f64 {
1919
((len - 1) as f64) * q
2020
}
2121
#[doc(hidden)]
2222
fn lower_index(q: f64, len: usize) -> usize {
23-
Self::float_percentile_index(q, len).floor() as usize
23+
Self::float_quantile_index(q, len).floor() as usize
2424
}
2525
#[doc(hidden)]
2626
fn higher_index(q: f64, len: usize) -> usize {
27-
Self::float_percentile_index(q, len).ceil() as usize
27+
Self::float_quantile_index(q, len).ceil() as usize
2828
}
2929
#[doc(hidden)]
30-
fn float_percentile_index_fraction(q: f64, len: usize) -> f64 {
31-
Self::float_percentile_index(q, len).fract()
30+
fn float_quantile_index_fraction(q: f64, len: usize) -> f64 {
31+
Self::float_quantile_index(q, len).fract()
3232
}
3333
#[doc(hidden)]
3434
fn needs_lower(q: f64, len: usize) -> bool;
@@ -94,7 +94,7 @@ pub mod interpolate {
9494

9595
impl<T> Interpolate<T> for Nearest {
9696
fn needs_lower(q: f64, len: usize) -> bool {
97-
<Self as Interpolate<T>>::float_percentile_index_fraction(q, len) < 0.5
97+
<Self as Interpolate<T>>::float_quantile_index_fraction(q, len) < 0.5
9898
}
9999
fn needs_higher(q: f64, len: usize) -> bool {
100100
!<Self as Interpolate<T>>::needs_lower(q, len)
@@ -156,7 +156,7 @@ pub mod interpolate {
156156
where
157157
D: Dimension,
158158
{
159-
let fraction = <Self as Interpolate<T>>::float_percentile_index_fraction(q, len);
159+
let fraction = <Self as Interpolate<T>>::float_quantile_index_fraction(q, len);
160160
let mut a = lower.unwrap();
161161
let b = higher.unwrap();
162162
azip!(mut a, ref b in {
@@ -169,8 +169,8 @@ pub mod interpolate {
169169
}
170170
}
171171

172-
/// Percentile methods.
173-
pub trait PercentileExt<A, S, D>
172+
/// Quantile methods.
173+
pub trait QuantileExt<A, S, D>
174174
where
175175
S: Data<Elem = A>,
176176
D: Dimension,
@@ -231,24 +231,24 @@ where
231231
A: MaybeNan,
232232
A::NotNan: Ord;
233233

234-
/// Return the qth percentile of the data along the specified axis.
234+
/// Return the qth quantile of the data along the specified axis.
235235
///
236236
/// `q` needs to be a float between 0 and 1, bounds included.
237-
/// The qth percentile for a 1-dimensional lane of length `N` is defined
237+
/// The qth quantile for a 1-dimensional lane of length `N` is defined
238238
/// as the element that would be indexed as `(N-1)q` if the lane were to be sorted
239239
/// in increasing order.
240-
/// If `(N-1)q` is not an integer the desired percentile lies between
240+
/// If `(N-1)q` is not an integer the desired quantile lies between
241241
/// two data points: we return the lower, nearest, higher or interpolated
242242
/// value depending on the type `Interpolate` bound `I`.
243243
///
244244
/// Some examples:
245245
/// - `q=0.` returns the minimum along each 1-dimensional lane;
246246
/// - `q=0.5` returns the median along each 1-dimensional lane;
247247
/// - `q=1.` returns the maximum along each 1-dimensional lane.
248-
/// (`q=0` and `q=1` are considered improper percentiles)
248+
/// (`q=0` and `q=1` are considered improper quantiles)
249249
///
250250
/// The array is shuffled **in place** along each 1-dimensional lane in
251-
/// order to produce the required percentile without allocating a copy
251+
/// order to produce the required quantile without allocating a copy
252252
/// of the original array. Each 1-dimensional lane is shuffled independently
253253
/// from the others.
254254
/// No assumptions should be made on the ordering of the array elements
@@ -261,17 +261,17 @@ where
261261
///
262262
/// **Panics** if `axis` is out of bounds or if `q` is not between
263263
/// `0.` and `1.` (inclusive).
264-
fn percentile_axis_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
264+
fn quantile_axis_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
265265
where
266266
D: RemoveAxis,
267267
A: Ord + Clone,
268268
S: DataMut,
269269
I: Interpolate<A>;
270270

271-
/// Return the `q`th percentile of the data along the specified axis, skipping NaN values.
271+
/// Return the `q`th quantile of the data along the specified axis, skipping NaN values.
272272
///
273-
/// See [`percentile_axis_mut`](##tymethod.percentile_axis_mut) for details.
274-
fn percentile_axis_skipnan_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
273+
/// See [`quantile_axis_mut`](##tymethod.quantile_axis_mut) for details.
274+
fn quantile_axis_skipnan_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
275275
where
276276
D: RemoveAxis,
277277
A: MaybeNan,
@@ -280,7 +280,7 @@ where
280280
I: Interpolate<A::NotNan>;
281281
}
282282

283-
impl<A, S, D> PercentileExt<A, S, D> for ArrayBase<S, D>
283+
impl<A, S, D> QuantileExt<A, S, D> for ArrayBase<S, D>
284284
where
285285
S: Data<Elem = A>,
286286
D: Dimension,
@@ -357,7 +357,7 @@ where
357357
}))
358358
}
359359

360-
fn percentile_axis_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
360+
fn quantile_axis_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
361361
where
362362
D: RemoveAxis,
363363
A: Ord + Clone,
@@ -387,7 +387,7 @@ where
387387
I::interpolate(lower, higher, q, axis_len)
388388
}
389389

390-
fn percentile_axis_skipnan_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
390+
fn quantile_axis_skipnan_mut<I>(&mut self, axis: Axis, q: f64) -> Array<A, D::Smaller>
391391
where
392392
D: RemoveAxis,
393393
A: MaybeNan,
@@ -402,7 +402,7 @@ where
402402
} else {
403403
Some(
404404
not_nan
405-
.percentile_axis_mut::<I>(Axis(0), q)
405+
.quantile_axis_mut::<I>(Axis(0), q)
406406
.into_raw_vec()
407407
.remove(0),
408408
)

tests/percentile.rs renamed to tests/quantile.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate ndarray_stats;
55
use ndarray::prelude::*;
66
use ndarray_stats::{
77
interpolate::{Higher, Linear, Lower, Midpoint, Nearest},
8-
PercentileExt,
8+
QuantileExt,
99
};
1010

1111
#[test]
@@ -69,74 +69,74 @@ fn test_max_skipnan_all_nan() {
6969
}
7070

7171
#[test]
72-
fn test_percentile_axis_mut_with_odd_axis_length() {
72+
fn test_quantile_axis_mut_with_odd_axis_length() {
7373
let mut a = arr2(&[[1, 3, 2, 10], [2, 4, 3, 11], [3, 5, 6, 12]]);
74-
let p = a.percentile_axis_mut::<Lower>(Axis(0), 0.5);
74+
let p = a.quantile_axis_mut::<Lower>(Axis(0), 0.5);
7575
assert!(p == a.subview(Axis(0), 1));
7676
}
7777

7878
#[test]
79-
fn test_percentile_axis_mut_with_even_axis_length() {
79+
fn test_quantile_axis_mut_with_even_axis_length() {
8080
let mut b = arr2(&[[1, 3, 2, 10], [2, 4, 3, 11], [3, 5, 6, 12], [4, 6, 7, 13]]);
81-
let q = b.percentile_axis_mut::<Lower>(Axis(0), 0.5);
81+
let q = b.quantile_axis_mut::<Lower>(Axis(0), 0.5);
8282
assert!(q == b.subview(Axis(0), 1));
8383
}
8484

8585
#[test]
86-
fn test_percentile_axis_mut_to_get_minimum() {
86+
fn test_quantile_axis_mut_to_get_minimum() {
8787
let mut b = arr2(&[[1, 3, 22, 10]]);
88-
let q = b.percentile_axis_mut::<Lower>(Axis(1), 0.);
88+
let q = b.quantile_axis_mut::<Lower>(Axis(1), 0.);
8989
assert!(q == arr1(&[1]));
9090
}
9191

9292
#[test]
93-
fn test_percentile_axis_mut_to_get_maximum() {
93+
fn test_quantile_axis_mut_to_get_maximum() {
9494
let mut b = arr1(&[1, 3, 22, 10]);
95-
let q = b.percentile_axis_mut::<Lower>(Axis(0), 1.);
95+
let q = b.quantile_axis_mut::<Lower>(Axis(0), 1.);
9696
assert!(q == arr0(22));
9797
}
9898

9999
#[test]
100-
fn test_percentile_axis_skipnan_mut_higher_opt_i32() {
100+
fn test_quantile_axis_skipnan_mut_higher_opt_i32() {
101101
let mut a = arr2(&[[Some(4), Some(2), None, Some(1), Some(5)], [None; 5]]);
102-
let q = a.percentile_axis_skipnan_mut::<Higher>(Axis(1), 0.6);
102+
let q = a.quantile_axis_skipnan_mut::<Higher>(Axis(1), 0.6);
103103
assert_eq!(q.shape(), &[2]);
104104
assert_eq!(q[0], Some(4));
105105
assert!(q[1].is_none());
106106
}
107107

108108
#[test]
109-
fn test_percentile_axis_skipnan_mut_nearest_opt_i32() {
109+
fn test_quantile_axis_skipnan_mut_nearest_opt_i32() {
110110
let mut a = arr2(&[[Some(4), Some(2), None, Some(1), Some(5)], [None; 5]]);
111-
let q = a.percentile_axis_skipnan_mut::<Nearest>(Axis(1), 0.6);
111+
let q = a.quantile_axis_skipnan_mut::<Nearest>(Axis(1), 0.6);
112112
assert_eq!(q.shape(), &[2]);
113113
assert_eq!(q[0], Some(4));
114114
assert!(q[1].is_none());
115115
}
116116

117117
#[test]
118-
fn test_percentile_axis_skipnan_mut_midpoint_opt_i32() {
118+
fn test_quantile_axis_skipnan_mut_midpoint_opt_i32() {
119119
let mut a = arr2(&[[Some(4), Some(2), None, Some(1), Some(5)], [None; 5]]);
120-
let q = a.percentile_axis_skipnan_mut::<Midpoint>(Axis(1), 0.6);
120+
let q = a.quantile_axis_skipnan_mut::<Midpoint>(Axis(1), 0.6);
121121
assert_eq!(q.shape(), &[2]);
122122
assert_eq!(q[0], Some(3));
123123
assert!(q[1].is_none());
124124
}
125125

126126
// TODO: See https://github.com/SergiusIW/noisy_float-rs/pull/19
127127
// #[test]
128-
// fn test_percentile_axis_skipnan_mut_linear_f64() {
128+
// fn test_quantile_axis_skipnan_mut_linear_f64() {
129129
// let mut a = arr2(&[[1., 2., ::std::f64::NAN, 3.], [::std::f64::NAN; 4]]);
130-
// let q = a.percentile_axis_skipnan_mut::<Linear>(Axis(1), 0.75);
130+
// let q = a.quantile_axis_skipnan_mut::<Linear>(Axis(1), 0.75);
131131
// assert_eq!(q.shape(), &[2]);
132132
// assert!((q[0] - 2.5).abs() < 1e-12);
133133
// assert!(q[1].is_nan());
134134
// }
135135

136136
#[test]
137-
fn test_percentile_axis_skipnan_mut_linear_opt_i32() {
137+
fn test_quantile_axis_skipnan_mut_linear_opt_i32() {
138138
let mut a = arr2(&[[Some(2), Some(4), None, Some(1)], [None; 4]]);
139-
let q = a.percentile_axis_skipnan_mut::<Linear>(Axis(1), 0.75);
139+
let q = a.quantile_axis_skipnan_mut::<Linear>(Axis(1), 0.75);
140140
assert_eq!(q.shape(), &[2]);
141141
assert_eq!(q[0], Some(3));
142142
assert!(q[1].is_none());

0 commit comments

Comments
 (0)