@@ -175,21 +175,14 @@ where
175175    S :  Data < Elem  = A > , 
176176    D :  Dimension , 
177177{ 
178-     /// Finds the elementwise minimum of the array. 
179- /// 
180- /// **Panics** if the array is empty. 
181- fn  min ( & self )  -> & A 
182-     where 
183-         A :  Ord ; 
184- 
185178    /// Finds the elementwise minimum of the array. 
186179/// 
187180/// Returns `None` if any of the pairwise orderings tested by the function 
188181/// are undefined. (For example, this occurs if there are any 
189182/// floating-point NaN values in the array.) 
190183/// 
191184/// Additionally, returns `None` if the array is empty. 
192- fn  min_partialord ( & self )  -> Option < & A > 
185+ fn  min ( & self )  -> Option < & A > 
193186    where 
194187        A :  PartialOrd ; 
195188
@@ -203,21 +196,14 @@ where
203196        A :  MaybeNan , 
204197        A :: NotNan :  Ord ; 
205198
206-     /// Finds the elementwise maximum of the array. 
207- /// 
208- /// **Panics** if the array is empty. 
209- fn  max ( & self )  -> & A 
210-     where 
211-         A :  Ord ; 
212- 
213199    /// Finds the elementwise maximum of the array. 
214200/// 
215201/// Returns `None` if any of the pairwise orderings tested by the function 
216202/// are undefined. (For example, this occurs if there are any 
217203/// floating-point NaN values in the array.) 
218204/// 
219205/// Additionally, returns `None` if the array is empty. 
220- fn  max_partialord ( & self )  -> Option < & A > 
206+ fn  max ( & self )  -> Option < & A > 
221207    where 
222208        A :  PartialOrd ; 
223209
@@ -259,8 +245,8 @@ where
259245/// - worst case: O(`m`^2); 
260246/// where `m` is the number of elements in the array. 
261247/// 
262- /// **Panics** if `axis` is out of bounds or  if `q` is not between  
263- /// `0.` and `1.` (inclusive). 
248+ /// **Panics** if `axis` is out of bounds,  if the axis has length 0, or if  
249+ /// `q` is not between ` 0.` and `1.` (inclusive). 
264250fn  quantile_axis_mut < I > ( & mut  self ,  axis :  Axis ,  q :  f64 )  -> Array < A ,  D :: Smaller > 
265251    where 
266252        D :  RemoveAxis , 
@@ -285,22 +271,11 @@ where
285271    S :  Data < Elem  = A > , 
286272    D :  Dimension , 
287273{ 
288-     fn  min ( & self )  -> & A 
289-     where 
290-         A :  Ord , 
291-     { 
292-         let  first = self 
293-             . iter ( ) 
294-             . next ( ) 
295-             . expect ( "Attempted to find min of empty array." ) ; 
296-         self . fold ( first,  |acc,  elem| if  elem < acc {  elem }  else  {  acc } ) 
297-     } 
298- 
299-     fn  min_partialord ( & self )  -> Option < & A > 
274+     fn  min ( & self )  -> Option < & A > 
300275    where 
301276        A :  PartialOrd , 
302277    { 
303-         let  first = self . iter ( ) . next ( ) ?; 
278+         let  first = self . first ( ) ?; 
304279        self . fold ( Some ( first) ,  |acc,  elem| match  elem. partial_cmp ( acc?) ? { 
305280            cmp:: Ordering :: Less  => Some ( elem) , 
306281            _ => acc, 
@@ -312,7 +287,7 @@ where
312287        A :  MaybeNan , 
313288        A :: NotNan :  Ord , 
314289    { 
315-         let  first = self . iter ( ) . next ( ) . and_then ( |v| v. try_as_not_nan ( ) ) ; 
290+         let  first = self . first ( ) . and_then ( |v| v. try_as_not_nan ( ) ) ; 
316291        A :: from_not_nan_ref_opt ( self . fold_skipnan ( first,  |acc,  elem| { 
317292            Some ( match  acc { 
318293                Some ( acc)  => acc. min ( elem) , 
@@ -321,22 +296,11 @@ where
321296        } ) ) 
322297    } 
323298
324-     fn  max ( & self )  -> & A 
325-     where 
326-         A :  Ord , 
327-     { 
328-         let  first = self 
329-             . iter ( ) 
330-             . next ( ) 
331-             . expect ( "Attempted to find max of empty array." ) ; 
332-         self . fold ( first,  |acc,  elem| if  elem > acc {  elem }  else  {  acc } ) 
333-     } 
334- 
335-     fn  max_partialord ( & self )  -> Option < & A > 
299+     fn  max ( & self )  -> Option < & A > 
336300    where 
337301        A :  PartialOrd , 
338302    { 
339-         let  first = self . iter ( ) . next ( ) ?; 
303+         let  first = self . first ( ) ?; 
340304        self . fold ( Some ( first) ,  |acc,  elem| match  elem. partial_cmp ( acc?) ? { 
341305            cmp:: Ordering :: Greater  => Some ( elem) , 
342306            _ => acc, 
@@ -348,7 +312,7 @@ where
348312        A :  MaybeNan , 
349313        A :: NotNan :  Ord , 
350314    { 
351-         let  first = self . iter ( ) . next ( ) . and_then ( |v| v. try_as_not_nan ( ) ) ; 
315+         let  first = self . first ( ) . and_then ( |v| v. try_as_not_nan ( ) ) ; 
352316        A :: from_not_nan_ref_opt ( self . fold_skipnan ( first,  |acc,  elem| { 
353317            Some ( match  acc { 
354318                Some ( acc)  => acc. max ( elem) , 
@@ -442,8 +406,10 @@ pub trait Quantile1dExt<A, S>
442406/// - worst case: O(`m`^2); 
443407/// where `m` is the number of elements in the array. 
444408/// 
409+ /// Returns `None` if the array is empty. 
410+ /// 
445411/// **Panics** if `q` is not between `0.` and `1.` (inclusive). 
446- fn  quantile_mut < I > ( & mut  self ,  q :  f64 )  -> A 
412+ fn  quantile_mut < I > ( & mut  self ,  q :  f64 )  -> Option < A > 
447413    where 
448414        A :  Ord  + Clone , 
449415        S :  DataMut , 
@@ -454,13 +420,17 @@ impl<A, S> Quantile1dExt<A, S> for ArrayBase<S, Ix1>
454420    where 
455421        S :  Data < Elem  = A > , 
456422{ 
457-     fn  quantile_mut < I > ( & mut  self ,  q :  f64 )  -> A 
423+     fn  quantile_mut < I > ( & mut  self ,  q :  f64 )  -> Option < A > 
458424    where 
459425        A :  Ord  + Clone , 
460426        S :  DataMut , 
461427        I :  Interpolate < A > , 
462428    { 
463-         self . quantile_axis_mut :: < I > ( Axis ( 0 ) ,  q) . into_scalar ( ) 
429+         if  self . is_empty ( )  { 
430+             None 
431+         }  else  { 
432+             Some ( self . quantile_axis_mut :: < I > ( Axis ( 0 ) ,  q) . into_scalar ( ) ) 
433+         } 
464434    } 
465435} 
466436
0 commit comments