1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
use self::interpolate::{higher_index, lower_index, Interpolate};
use super::sort::get_many_from_sorted_mut_unchecked;
use crate::errors::QuantileError;
use crate::errors::{EmptyInput, MinMaxError, MinMaxError::UndefinedOrder};
use crate::{MaybeNan, MaybeNanExt};
use ndarray::prelude::*;
use ndarray::{Data, DataMut, RemoveAxis, Zip};
use noisy_float::types::N64;
use std::cmp;

/// Quantile methods for `ArrayBase`.
pub trait QuantileExt<A, S, D>
where
    S: Data<Elem = A>,
    D: Dimension,
{
    /// Finds the index of the minimum value of the array.
    ///
    /// Returns `Err(MinMaxError::UndefinedOrder)` if any of the pairwise
    /// orderings tested by the function are undefined. (For example, this
    /// occurs if there are any floating-point NaN values in the array.)
    ///
    /// Returns `Err(MinMaxError::EmptyInput)` if the array is empty.
    ///
    /// Even if there are multiple (equal) elements that are minima, only one
    /// index is returned. (Which one is returned is unspecified and may depend
    /// on the memory layout of the array.)
    ///
    /// # Example
    ///
    /// ```
    /// use ndarray::array;
    /// use ndarray_stats::QuantileExt;
    ///
    /// let a = array![[1., 3., 5.],
    ///                [2., 0., 6.]];
    /// assert_eq!(a.argmin(), Ok((1, 1)));
    /// ```
    fn argmin(&self) -> Result<D::Pattern, MinMaxError>
    where
        A: PartialOrd;

    /// Finds the index of the minimum value of the array skipping NaN values.
    ///
    /// Returns `Err(EmptyInput)` if the array is empty or none of the values in the array
    /// are non-NaN values.
    ///
    /// Even if there are multiple (equal) elements that are minima, only one
    /// index is returned. (Which one is returned is unspecified and may depend
    /// on the memory layout of the array.)
    ///
    /// # Example
    ///
    /// ```
    /// use ndarray::array;
    /// use ndarray_stats::QuantileExt;
    ///
    /// let a = array![[::std::f64::NAN, 3., 5.],
    ///                [2., 0., 6.]];
    /// assert_eq!(a.argmin_skipnan(), Ok((1, 1)));
    /// ```
    fn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
    where
        A: MaybeNan,
        A::NotNan: Ord;

    /// Finds the elementwise minimum of the array.
    ///
    /// Returns `Err(MinMaxError::UndefinedOrder)` if any of the pairwise
    /// orderings tested by the function are undefined. (For example, this
    /// occurs if there are any floating-point NaN values in the array.)
    ///
    /// Returns `Err(MinMaxError::EmptyInput)` if the array is empty.
    ///
    /// Even if there are multiple (equal) elements that are minima, only one
    /// is returned. (Which one is returned is unspecified and may depend on
    /// the memory layout of the array.)
    fn min(&self) -> Result<&A, MinMaxError>
    where
        A: PartialOrd;

    /// Finds the elementwise minimum of the array, skipping NaN values.
    ///
    /// Even if there are multiple (equal) elements that are minima, only one
    /// is returned. (Which one is returned is unspecified and may depend on
    /// the memory layout of the array.)
    ///
    /// **Warning** This method will return a NaN value if none of the values
    /// in the array are non-NaN values. Note that the NaN value might not be
    /// in the array.
    fn min_skipnan(&self) -> &A
    where
        A: MaybeNan,
        A::NotNan: Ord;

    /// Finds the index of the maximum value of the array.
    ///
    /// Returns `Err(MinMaxError::UndefinedOrder)` if any of the pairwise
    /// orderings tested by the function are undefined. (For example, this
    /// occurs if there are any floating-point NaN values in the array.)
    ///
    /// Returns `Err(MinMaxError::EmptyInput)` if the array is empty.
    ///
    /// Even if there are multiple (equal) elements that are maxima, only one
    /// index is returned. (Which one is returned is unspecified and may depend
    /// on the memory layout of the array.)
    ///
    /// # Example
    ///
    /// ```
    /// use ndarray::array;
    /// use ndarray_stats::QuantileExt;
    ///
    /// let a = array![[1., 3., 7.],
    ///                [2., 5., 6.]];
    /// assert_eq!(a.argmax(), Ok((0, 2)));
    /// ```
    fn argmax(&self) -> Result<D::Pattern, MinMaxError>
    where
        A: PartialOrd;

    /// Finds the index of the maximum value of the array skipping NaN values.
    ///
    /// Returns `Err(EmptyInput)` if the array is empty or none of the values in the array
    /// are non-NaN values.
    ///
    /// Even if there are multiple (equal) elements that are maxima, only one
    /// index is returned. (Which one is returned is unspecified and may depend
    /// on the memory layout of the array.)
    ///
    /// # Example
    ///
    /// ```
    /// use ndarray::array;
    /// use ndarray_stats::QuantileExt;
    ///
    /// let a = array![[::std::f64::NAN, 3., 5.],
    ///                [2., 0., 6.]];
    /// assert_eq!(a.argmax_skipnan(), Ok((1, 2)));
    /// ```
    fn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
    where
        A: MaybeNan,
        A::NotNan: Ord;

    /// Finds the elementwise maximum of the array.
    ///
    /// Returns `Err(MinMaxError::UndefinedOrder)` if any of the pairwise
    /// orderings tested by the function are undefined. (For example, this
    /// occurs if there are any floating-point NaN values in the array.)
    ///
    /// Returns `Err(EmptyInput)` if the array is empty.
    ///
    /// Even if there are multiple (equal) elements that are maxima, only one
    /// is returned. (Which one is returned is unspecified and may depend on
    /// the memory layout of the array.)
    fn max(&self) -> Result<&A, MinMaxError>
    where
        A: PartialOrd;

    /// Finds the elementwise maximum of the array, skipping NaN values.
    ///
    /// Even if there are multiple (equal) elements that are maxima, only one
    /// is returned. (Which one is returned is unspecified and may depend on
    /// the memory layout of the array.)
    ///
    /// **Warning** This method will return a NaN value if none of the values
    /// in the array are non-NaN values. Note that the NaN value might not be
    /// in the array.
    fn max_skipnan(&self) -> &A
    where
        A: MaybeNan,
        A::NotNan: Ord;

    /// Return the qth quantile of the data along the specified axis.
    ///
    /// `q` needs to be a float between 0 and 1, bounds included.
    /// The qth quantile for a 1-dimensional lane of length `N` is defined
    /// as the element that would be indexed as `(N-1)q` if the lane were to be sorted
    /// in increasing order.
    /// If `(N-1)q` is not an integer the desired quantile lies between
    /// two data points: we return the lower, nearest, higher or interpolated
    /// value depending on the `interpolate` strategy.
    ///
    /// Some examples:
    /// - `q=0.` returns the minimum along each 1-dimensional lane;
    /// - `q=0.5` returns the median along each 1-dimensional lane;
    /// - `q=1.` returns the maximum along each 1-dimensional lane.
    /// (`q=0` and `q=1` are considered improper quantiles)
    ///
    /// The array is shuffled **in place** along each 1-dimensional lane in
    /// order to produce the required quantile without allocating a copy
    /// of the original array. Each 1-dimensional lane is shuffled independently
    /// from the others.
    /// No assumptions should be made on the ordering of the array elements
    /// after this computation.
    ///
    /// Complexity ([quickselect](https://en.wikipedia.org/wiki/Quickselect)):
    /// - average case: O(`m`);
    /// - worst case: O(`m`^2);
    /// where `m` is the number of elements in the array.
    ///
    /// Returns `Err(EmptyInput)` when the specified axis has length 0.
    ///
    /// Returns `Err(InvalidQuantile(q))` if `q` is not between `0.` and `1.` (inclusive).
    ///
    /// **Panics** if `axis` is out of bounds.
    fn quantile_axis_mut<I>(
        &mut self,
        axis: Axis,
        q: N64,
        interpolate: &I,
    ) -> Result<Array<A, D::Smaller>, QuantileError>
    where
        D: RemoveAxis,
        A: Ord + Clone,
        S: DataMut,
        I: Interpolate<A>;

    /// A bulk version of [`quantile_axis_mut`], optimized to retrieve multiple
    /// quantiles at once.
    ///
    /// Returns an `Array`, where subviews along `axis` of the array correspond
    /// to the elements of `qs`.
    ///
    /// See [`quantile_axis_mut`] for additional details on quantiles and the algorithm
    /// used to retrieve them.
    ///
    /// Returns `Err(EmptyInput)` when the specified axis has length 0.
    ///
    /// Returns `Err(InvalidQuantile(q))` if any `q` in `qs` is not between `0.` and `1.` (inclusive).
    ///
    /// **Panics** if `axis` is out of bounds.
    ///
    /// [`quantile_axis_mut`]: #tymethod.quantile_axis_mut
    ///
    /// # Example
    ///
    /// ```rust
    /// use ndarray::{array, aview1, Axis};
    /// use ndarray_stats::{QuantileExt, interpolate::Nearest};
    /// use noisy_float::types::n64;
    ///
    /// let mut data = array![[3, 4, 5], [6, 7, 8]];
    /// let axis = Axis(1);
    /// let qs = &[n64(0.3), n64(0.7)];
    /// let quantiles = data.quantiles_axis_mut(axis, &aview1(qs), &Nearest).unwrap();
    /// for (&q, quantile) in qs.iter().zip(quantiles.axis_iter(axis)) {
    ///     assert_eq!(quantile, data.quantile_axis_mut(axis, q, &Nearest).unwrap());
    /// }
    /// ```
    fn quantiles_axis_mut<S2, I>(
        &mut self,
        axis: Axis,
        qs: &ArrayBase<S2, Ix1>,
        interpolate: &I,
    ) -> Result<Array<A, D>, QuantileError>
    where
        D: RemoveAxis,
        A: Ord + Clone,
        S: DataMut,
        S2: Data<Elem = N64>,
        I: Interpolate<A>;

    /// Return the `q`th quantile of the data along the specified axis, skipping NaN values.
    ///
    /// See [`quantile_axis_mut`](#tymethod.quantile_axis_mut) for details.
    fn quantile_axis_skipnan_mut<I>(
        &mut self,
        axis: Axis,
        q: N64,
        interpolate: &I,
    ) -> Result<Array<A, D::Smaller>, QuantileError>
    where
        D: RemoveAxis,
        A: MaybeNan,
        A::NotNan: Clone + Ord,
        S: DataMut,
        I: Interpolate<A::NotNan>;

    private_decl! {}
}

impl<A, S, D> QuantileExt<A, S, D> for ArrayBase<S, D>
where
    S: Data<Elem = A>,
    D: Dimension,
{
    fn argmin(&self) -> Result<D::Pattern, MinMaxError>
    where
        A: PartialOrd,
    {
        let mut current_min = self.first().ok_or(EmptyInput)?;
        let mut current_pattern_min = D::zeros(self.ndim()).into_pattern();

        for (pattern, elem) in self.indexed_iter() {
            if elem.partial_cmp(current_min).ok_or(UndefinedOrder)? == cmp::Ordering::Less {
                current_pattern_min = pattern;
                current_min = elem
            }
        }

        Ok(current_pattern_min)
    }

    fn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
    where
        A: MaybeNan,
        A::NotNan: Ord,
    {
        let mut pattern_min = D::zeros(self.ndim()).into_pattern();
        let min = self.indexed_fold_skipnan(None, |current_min, (pattern, elem)| {
            Some(match current_min {
                Some(m) if (m <= elem) => m,
                _ => {
                    pattern_min = pattern;
                    elem
                }
            })
        });
        if min.is_some() {
            Ok(pattern_min)
        } else {
            Err(EmptyInput)
        }
    }

    fn min(&self) -> Result<&A, MinMaxError>
    where
        A: PartialOrd,
    {
        let first = self.first().ok_or(EmptyInput)?;
        self.fold(Ok(first), |acc, elem| {
            let acc = acc?;
            match elem.partial_cmp(acc).ok_or(UndefinedOrder)? {
                cmp::Ordering::Less => Ok(elem),
                _ => Ok(acc),
            }
        })
    }

    fn min_skipnan(&self) -> &A
    where
        A: MaybeNan,
        A::NotNan: Ord,
    {
        let first = self.first().and_then(|v| v.try_as_not_nan());
        A::from_not_nan_ref_opt(self.fold_skipnan(first, |acc, elem| {
            Some(match acc {
                Some(acc) => acc.min(elem),
                None => elem,
            })
        }))
    }

    fn argmax(&self) -> Result<D::Pattern, MinMaxError>
    where
        A: PartialOrd,
    {
        let mut current_max = self.first().ok_or(EmptyInput)?;
        let mut current_pattern_max = D::zeros(self.ndim()).into_pattern();

        for (pattern, elem) in self.indexed_iter() {
            if elem.partial_cmp(current_max).ok_or(UndefinedOrder)? == cmp::Ordering::Greater {
                current_pattern_max = pattern;
                current_max = elem
            }
        }

        Ok(current_pattern_max)
    }

    fn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
    where
        A: MaybeNan,
        A::NotNan: Ord,
    {
        let mut pattern_max = D::zeros(self.ndim()).into_pattern();
        let max = self.indexed_fold_skipnan(None, |current_max, (pattern, elem)| {
            Some(match current_max {
                Some(m) if m >= elem => m,
                _ => {
                    pattern_max = pattern;
                    elem
                }
            })
        });
        if max.is_some() {
            Ok(pattern_max)
        } else {
            Err(EmptyInput)
        }
    }

    fn max(&self) -> Result<&A, MinMaxError>
    where
        A: PartialOrd,
    {
        let first = self.first().ok_or(EmptyInput)?;
        self.fold(Ok(first), |acc, elem| {
            let acc = acc?;
            match elem.partial_cmp(acc).ok_or(UndefinedOrder)? {
                cmp::Ordering::Greater => Ok(elem),
                _ => Ok(acc),
            }
        })
    }

    fn max_skipnan(&self) -> &A
    where
        A: MaybeNan,
        A::NotNan: Ord,
    {
        let first = self.first().and_then(|v| v.try_as_not_nan());
        A::from_not_nan_ref_opt(self.fold_skipnan(first, |acc, elem| {
            Some(match acc {
                Some(acc) => acc.max(elem),
                None => elem,
            })
        }))
    }

    fn quantiles_axis_mut<S2, I>(
        &mut self,
        axis: Axis,
        qs: &ArrayBase<S2, Ix1>,
        interpolate: &I,
    ) -> Result<Array<A, D>, QuantileError>
    where
        D: RemoveAxis,
        A: Ord + Clone,
        S: DataMut,
        S2: Data<Elem = N64>,
        I: Interpolate<A>,
    {
        // Minimize number of type parameters to avoid monomorphization bloat.
        fn quantiles_axis_mut<A, D, I>(
            mut data: ArrayViewMut<'_, A, D>,
            axis: Axis,
            qs: ArrayView1<'_, N64>,
            _interpolate: &I,
        ) -> Result<Array<A, D>, QuantileError>
        where
            D: RemoveAxis,
            A: Ord + Clone,
            I: Interpolate<A>,
        {
            for &q in qs {
                if !((q >= 0.) && (q <= 1.)) {
                    return Err(QuantileError::InvalidQuantile(q));
                }
            }

            let axis_len = data.len_of(axis);
            if axis_len == 0 {
                return Err(QuantileError::EmptyInput);
            }

            let mut results_shape = data.raw_dim();
            results_shape[axis.index()] = qs.len();
            if results_shape.size() == 0 {
                return Ok(Array::from_shape_vec(results_shape, Vec::new()).unwrap());
            }

            let mut searched_indexes = Vec::with_capacity(2 * qs.len());
            for &q in &qs {
                if I::needs_lower(q, axis_len) {
                    searched_indexes.push(lower_index(q, axis_len));
                }
                if I::needs_higher(q, axis_len) {
                    searched_indexes.push(higher_index(q, axis_len));
                }
            }
            searched_indexes.sort();
            searched_indexes.dedup();

            let mut results = Array::from_elem(results_shape, data.first().unwrap().clone());
            Zip::from(results.lanes_mut(axis))
                .and(data.lanes_mut(axis))
                .for_each(|mut results, mut data| {
                    let index_map =
                        get_many_from_sorted_mut_unchecked(&mut data, &searched_indexes);
                    for (result, &q) in results.iter_mut().zip(qs) {
                        let lower = if I::needs_lower(q, axis_len) {
                            Some(index_map[&lower_index(q, axis_len)].clone())
                        } else {
                            None
                        };
                        let higher = if I::needs_higher(q, axis_len) {
                            Some(index_map[&higher_index(q, axis_len)].clone())
                        } else {
                            None
                        };
                        *result = I::interpolate(lower, higher, q, axis_len);
                    }
                });
            Ok(results)
        }

        quantiles_axis_mut(self.view_mut(), axis, qs.view(), interpolate)
    }

    fn quantile_axis_mut<I>(
        &mut self,
        axis: Axis,
        q: N64,
        interpolate: &I,
    ) -> Result<Array<A, D::Smaller>, QuantileError>
    where
        D: RemoveAxis,
        A: Ord + Clone,
        S: DataMut,
        I: Interpolate<A>,
    {
        self.quantiles_axis_mut(axis, &aview1(&[q]), interpolate)
            .map(|a| a.index_axis_move(axis, 0))
    }

    fn quantile_axis_skipnan_mut<I>(
        &mut self,
        axis: Axis,
        q: N64,
        interpolate: &I,
    ) -> Result<Array<A, D::Smaller>, QuantileError>
    where
        D: RemoveAxis,
        A: MaybeNan,
        A::NotNan: Clone + Ord,
        S: DataMut,
        I: Interpolate<A::NotNan>,
    {
        if !((q >= 0.) && (q <= 1.)) {
            return Err(QuantileError::InvalidQuantile(q));
        }

        if self.len_of(axis) == 0 {
            return Err(QuantileError::EmptyInput);
        }

        let quantile = self.map_axis_mut(axis, |lane| {
            let mut not_nan = A::remove_nan_mut(lane);
            A::from_not_nan_opt(if not_nan.is_empty() {
                None
            } else {
                Some(
                    not_nan
                        .quantile_axis_mut::<I>(Axis(0), q, interpolate)
                        .unwrap()
                        .into_scalar(),
                )
            })
        });
        Ok(quantile)
    }

    private_impl! {}
}

/// Quantile methods for 1-D arrays.
pub trait Quantile1dExt<A, S>
where
    S: Data<Elem = A>,
{
    /// Return the qth quantile of the data.
    ///
    /// `q` needs to be a float between 0 and 1, bounds included.
    /// The qth quantile for a 1-dimensional array of length `N` is defined
    /// as the element that would be indexed as `(N-1)q` if the array were to be sorted
    /// in increasing order.
    /// If `(N-1)q` is not an integer the desired quantile lies between
    /// two data points: we return the lower, nearest, higher or interpolated
    /// value depending on the `interpolate` strategy.
    ///
    /// Some examples:
    /// - `q=0.` returns the minimum;
    /// - `q=0.5` returns the median;
    /// - `q=1.` returns the maximum.
    /// (`q=0` and `q=1` are considered improper quantiles)
    ///
    /// The array is shuffled **in place** in order to produce the required quantile
    /// without allocating a copy.
    /// No assumptions should be made on the ordering of the array elements
    /// after this computation.
    ///
    /// Complexity ([quickselect](https://en.wikipedia.org/wiki/Quickselect)):
    /// - average case: O(`m`);
    /// - worst case: O(`m`^2);
    /// where `m` is the number of elements in the array.
    ///
    /// Returns `Err(EmptyInput)` if the array is empty.
    ///
    /// Returns `Err(InvalidQuantile(q))` if `q` is not between `0.` and `1.` (inclusive).
    fn quantile_mut<I>(&mut self, q: N64, interpolate: &I) -> Result<A, QuantileError>
    where
        A: Ord + Clone,
        S: DataMut,
        I: Interpolate<A>;

    /// A bulk version of [`quantile_mut`], optimized to retrieve multiple
    /// quantiles at once.
    ///
    /// Returns an `Array`, where the elements of the array correspond to the
    /// elements of `qs`.
    ///
    /// Returns `Err(EmptyInput)` if the array is empty.
    ///
    /// Returns `Err(InvalidQuantile(q))` if any `q` in
    /// `qs` is not between `0.` and `1.` (inclusive).
    ///
    /// See [`quantile_mut`] for additional details on quantiles and the algorithm
    /// used to retrieve them.
    ///
    /// [`quantile_mut`]: #tymethod.quantile_mut
    fn quantiles_mut<S2, I>(
        &mut self,
        qs: &ArrayBase<S2, Ix1>,
        interpolate: &I,
    ) -> Result<Array1<A>, QuantileError>
    where
        A: Ord + Clone,
        S: DataMut,
        S2: Data<Elem = N64>,
        I: Interpolate<A>;

    private_decl! {}
}

impl<A, S> Quantile1dExt<A, S> for ArrayBase<S, Ix1>
where
    S: Data<Elem = A>,
{
    fn quantile_mut<I>(&mut self, q: N64, interpolate: &I) -> Result<A, QuantileError>
    where
        A: Ord + Clone,
        S: DataMut,
        I: Interpolate<A>,
    {
        Ok(self
            .quantile_axis_mut(Axis(0), q, interpolate)?
            .into_scalar())
    }

    fn quantiles_mut<S2, I>(
        &mut self,
        qs: &ArrayBase<S2, Ix1>,
        interpolate: &I,
    ) -> Result<Array1<A>, QuantileError>
    where
        A: Ord + Clone,
        S: DataMut,
        S2: Data<Elem = N64>,
        I: Interpolate<A>,
    {
        self.quantiles_axis_mut(Axis(0), qs, interpolate)
    }

    private_impl! {}
}

pub mod interpolate;