Skip to content

Avoid calling extrema(...; dims) with empty arrays #1711

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

Merged
merged 1 commit into from
May 1, 2025

Conversation

mbauman
Copy link
Contributor

@mbauman mbauman commented Apr 29, 2025

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. See JuliaLang/julia#55628 for more details.

This addresses that first such usage; there may be other places 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 `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.
Copy link
Member

@joa-quim joa-quim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know about this. But I have a doubt on how to handle this. For example in this case, the fix would better be 4 lines above, after the declaration of

dest::Matrix{Float64} = zeros(Float64, DS.n_rows, DS.n_columns + plusZzero)

to add

isempty(dest) && continue       # Skip empty segments

But, and here is my doubt, would this type of solution avoid that nanosoldier would still flag the current case?

@mbauman
Copy link
Contributor Author

mbauman commented Apr 30, 2025

Yeah, that sounds like a great solution that would further simply things here; I'm not familiar with this codebase so I made the most minimal and straightforward change I could easily see.

I do suspect that it'll also happen in those other places I linked; PkgEval errored while precompiling the package so we only tripped over the very first failure.

@joa-quim
Copy link
Member

Hmm, wait, I'm a bit confused. You say that extrema([], dims=2) will become an error but all (but one) cases pointed out are doing extrema([], dims=1) and that is already an error. e.g.

extrema(Vector{Float64}(undef, 0), dims=1)
ERROR: ArgumentError: reducing over an empty collection is not allowed

Copy link
Member

@joa-quim joa-quim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, the fix needs to be here after all (skipping above would break some code)

@joa-quim joa-quim merged commit 1f3ac2a into GenericMappingTools:master May 1, 2025
1 check passed
@joa-quim
Copy link
Member

joa-quim commented May 1, 2025

Try to address all of these cases with #1713

@mbauman mbauman deleted the patch-1 branch May 1, 2025 14:17
@mbauman
Copy link
Contributor Author

mbauman commented May 1, 2025

Thanks for taking this across the line — I know changes like these are annoying, and I appreciate the understanding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants