Skip to content

Commit 8691e32

Browse files
committed
Clarify which (arg)min/max index/value is returned
For performance, it's beneficial to avoid guaranteeing a particular iteration order. For example, the current implementation of `min` may return any of the minima because the iteration order of `ArrayBase.fold()` is unspecified. The current implementation of `argmin` does always return the first minimum (in logical order) since `ArrayBase.indexed_iter()` always iterates in logical order, but we may want to optimize the iteration order in the future.
1 parent e6426a6 commit 8691e32

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/quantile.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,18 @@ where
182182
S: Data<Elem = A>,
183183
D: Dimension,
184184
{
185-
/// Finds the first index of the minimum value of the array.
185+
/// Finds the index of the minimum value of the array.
186186
///
187187
/// Returns `None` if any of the pairwise orderings tested by the function
188188
/// are undefined. (For example, this occurs if there are any
189189
/// floating-point NaN values in the array.)
190190
///
191191
/// Returns `None` if the array is empty.
192192
///
193+
/// Even if there are multiple (equal) elements that are minima, only one
194+
/// index is returned. (Which one is returned is unspecified and may depend
195+
/// on the memory layout of the array.)
196+
///
193197
/// # Example
194198
///
195199
/// ```
@@ -214,12 +218,20 @@ where
214218
/// floating-point NaN values in the array.)
215219
///
216220
/// Additionally, returns `None` if the array is empty.
221+
///
222+
/// Even if there are multiple (equal) elements that are minima, only one
223+
/// is returned. (Which one is returned is unspecified and may depend on
224+
/// the memory layout of the array.)
217225
fn min(&self) -> Option<&A>
218226
where
219227
A: PartialOrd;
220228

221229
/// Finds the elementwise minimum of the array, skipping NaN values.
222230
///
231+
/// Even if there are multiple (equal) elements that are minima, only one
232+
/// is returned. (Which one is returned is unspecified and may depend on
233+
/// the memory layout of the array.)
234+
///
223235
/// **Warning** This method will return a NaN value if none of the values
224236
/// in the array are non-NaN values. Note that the NaN value might not be
225237
/// in the array.
@@ -228,14 +240,18 @@ where
228240
A: MaybeNan,
229241
A::NotNan: Ord;
230242

231-
/// Finds the first index of the maximum value of the array.
243+
/// Finds the index of the maximum value of the array.
232244
///
233245
/// Returns `None` if any of the pairwise orderings tested by the function
234246
/// are undefined. (For example, this occurs if there are any
235247
/// floating-point NaN values in the array.)
236248
///
237249
/// Returns `None` if the array is empty.
238250
///
251+
/// Even if there are multiple (equal) elements that are maxima, only one
252+
/// index is returned. (Which one is returned is unspecified and may depend
253+
/// on the memory layout of the array.)
254+
///
239255
/// # Example
240256
///
241257
/// ```
@@ -260,12 +276,20 @@ where
260276
/// floating-point NaN values in the array.)
261277
///
262278
/// Additionally, returns `None` if the array is empty.
279+
///
280+
/// Even if there are multiple (equal) elements that are maxima, only one
281+
/// is returned. (Which one is returned is unspecified and may depend on
282+
/// the memory layout of the array.)
263283
fn max(&self) -> Option<&A>
264284
where
265285
A: PartialOrd;
266286

267287
/// Finds the elementwise maximum of the array, skipping NaN values.
268288
///
289+
/// Even if there are multiple (equal) elements that are maxima, only one
290+
/// is returned. (Which one is returned is unspecified and may depend on
291+
/// the memory layout of the array.)
292+
///
269293
/// **Warning** This method will return a NaN value if none of the values
270294
/// in the array are non-NaN values. Note that the NaN value might not be
271295
/// in the array.

0 commit comments

Comments
 (0)