-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
unify reduce/reducedim empty case behaviors #55628
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
base: master
Are you sure you want to change the base?
Conversation
Once CI passes (modulo a SparseArrays test), let's run Nanosoldier. |
@nanosoldier |
The package evaluation job you requested has completed - possible new issues were detected. |
OK, that went better than I expected. There are three root failures as far as I can see:
|
OK, that's fascinating. All of those examples would be fixed by #52004, which was only blocked by precisely the same sparse array failures that this PR faces. I'm not a huge fan of #52004, but perhaps there's a middle ground by just preserving the eltype for |
Triage is ok with making all of these errors. The result for |
e92a570
to
53f3328
Compare
OK, let's see what PkgEval sees here now. @nanosoldier |
The package evaluation job you requested has completed - possible new issues were detected. Report summary❗ Packages that crashed1 packages crashed only on the current version.
3 packages crashed on the previous version too. ✖ Packages that failed31 packages failed only on the current version.
1438 packages failed on the previous version too. ✔ Packages that passed tests21 packages passed tests only on the current version.
5240 packages passed tests on the previous version too. ~ Packages that at least loaded11 packages successfully loaded only on the current version.
2835 packages successfully loaded on the previous version too. ➖ Packages that were skipped altogether918 packages were skipped on the previous version too. |
Well that new report looks awfully consistent with what we saw last fall — those three packages are still failing. Looks like we additionally snagged C3D this time, with an empty reduction error on (effectively) I think the periodic graphs example is a perfect motivation. It calls both maxden = maximum(denominator.(_invmat); dims=2)
invmat::Matrix{Int} = maximum(maxden; init=0) > 1 ? (maxden .* _invmat) : _invmat |
Given that triage gave their 👍 and the limited ecosystem impact here I'm going to swap the labels here to "minor change". But this isn't ready yet; we need to merge |
There's a proposed "minor change" to Julia v1.13 that would make `extrema([], dims=2)` (and other such reductions) an error, akin to how `extrema([])` is an error when `init` is not specified. This package was flagged as having (at least) one such usage here; it errored in [PkgEval](https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/813bcf3_vs_c3e7b1b/report.html). See JuliaLang/julia#55628 for more details. This addresses that first such usage; there may be [other places](https://github.com/search?q=repo%3AGenericMappingTools%2FGMT.jl+%2F%28%3F%3Aextrema%7Cminimum%7Cmaximum%29.*dims%2F&type=code) that similarly need to change by either supplying `init` or skipping the empty case entirely.
There's a proposed "minor change" to Julia v1.13 that would make `maximum([], dims=2)` (and other such reductions) an error, akin to how `maximum([])` is an error when `init` is not specified. This package was flagged as having (at least) one such usage here; it errored in [PkgEval](https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/813bcf3_vs_c3e7b1b/report.html). See JuliaLang/julia#55628 for more details.
There's a proposed "minor change" to Julia v1.13 that would make `maximum([], dims=2)` (and other such reductions) an error, akin to how `maximum([])` is an error when `init` is not specified. This package was flagged as having (at least) one such usage here; it errored in [PkgEval](https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/813bcf3_vs_c3e7b1b/report.html). See JuliaLang/julia#55628 for more details.
There's a proposed "minor change" to Julia v1.13 that would make `maximum([], dims=2)` (and other such reductions) an error, akin to how `maximum([])` is an error when `init` is not specified. This package was flagged as having (at least) one such usage here; it errored in [PkgEval](https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/813bcf3_vs_c3e7b1b/report.html). See JuliaLang/julia#55628 for more details.
There's a proposed "minor change" to Julia v1.13 that would make `extrema([], dims=2)` (and other such reductions) an error, akin to how `extrema([])` is an error when `init` is not specified. This package was flagged as having (at least) one such usage here; it errored in [PkgEval](https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/813bcf3_vs_c3e7b1b/report.html). See JuliaLang/julia#55628 for more details. This addresses that first such usage; there may be [other places](https://github.com/search?q=repo%3AGenericMappingTools%2FGMT.jl+%2F%28%3F%3Aextrema%7Cminimum%7Cmaximum%29.*dims%2F&type=code) that similarly need to change by either supplying `init` or skipping the empty case entirely.
Previously, Julia tried to guess at initial values for empty dimensional reductions in a slightly different way than whole-array reductions. This change unifies those behaviors, such that `mapreduce_empty` is called for empty dimensional reductions, just like it is called for empty whole-array reductions. Beyond the unification (which is valuable in its own right), this change enables some downstream simplifications to dimensional reductions and is likely to be the "most breaking" public behavior in a refactoring targeting more correctness improvements.
adfe6f8
to
0e924cf
Compare
Despite the label here, this is ready to go. It just requires coordination with SparseArrays. I think the best approach would be to merge JuliaSparse/SparseArrays.jl#615 first. It’s failing over there, but those exact same tests pass in this PR’s CI. Then once that’s merged, we can adjust the second commit here to just bump the stdlib normally. It’d be good to get a final review here in any case, and I don’t have commit rights to SparseArrays myself. |
This PR implements a very simple rule for empty dimensional reductions: they should behave exactly the same as their whole-array counterparts. If the whole-array reduction errors, the dimensional flavor should also error. If the whole-array reduction gives a value, then the dimensional version should just return the appropriately-shaped array
fill
ed with it.Previously, Julia tried to guess at initial values for empty dimensional reductions in a slightly different way than whole-array reductions. This change unifies those behaviors, such that
mapreduce_empty
is called for empty dimensional reductions, just like it is called for empty whole-array reductions.Beyond the unification (which is valuable in its own right), this change enables some downstream simplifications to dimensional reductions and is likely to be the "most breaking" public behavior in a refactoring targeting more correctness improvements (#55318).
It's a little convoluted to understand the exact motivation, utility, and net effect of this change. Here are two case studies, demonstrating the behaviors prior to this change:
This PR makes all six cases above errors. This is a useful and important change because it's precisely this guessing of eltype and initial array values that lead to the many correctness errors that #55318 fixes. It's also worth noting that the incremental widening approach in #55318 could support the empty-return case, but it would do so at the expense of type stability because the "reducing over an empty collection" error branch adds a possible
Array{Union{}}
return value.