-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Linq.Parallel Max/Min return unstable results. #14787
Comments
I don't see why you would expect stable results here. Stable results could be asked for if desired by combining with an index and making the index a secondary sort key. For most people this will add extra work to track indices (trivial to do relatively if you weren't parallel since everything will have a higher index than previous items, but you are parallel so that's no longer the case) and use them as tie-breakers if necessary.
But
Indeed, your wording "first" points at why; you can't predict which element will be first to a parallel implementation. |
@hackcraft - then I'll need to double check the tests that say otherwise (I only modified them). They might be executing sequentially or something. |
@hackcraft - okay, what's actually going on is the tests are capturing the index via a @AlfredoMS - in light of this, I'm going to close this issue (and comment the tests a bit more). |
@Clockwork-Muse that makes sense; capturing the index via a Select is exactly what I was talking about when I said "Stable results could be asked for if desired". |
When dealing with an ordered source, and the maximum or minimum has duplicates according to the comparator, the result returned isn't stable. The following test is failing (results non-deterministic):
(this actual test hasn't been uploaded yet, but the rest of the types have been).
DelegateComparable
returns a type that says "go use this other comparer instead".ModularCongruenceComparer
compares based on the mod of the input - using 1 means everything has a mod of0
.I'm expecting the "first" item to be returned (not replaced) from ordered input, for
Max
andMin
to behave the same way asOrderBy
does - this may be unfounded. I do not care about unordered input, or the various versions that deal only with primitives; only when a types provides its own comparator is this a potential issue.This may be important behavior to consider for #14753 .
@stephentoub
The text was updated successfully, but these errors were encountered: