Skip to content

Fix findmin/max with dims for non-1 based inputs.#45822

Open
N5N3 wants to merge 3 commits into
JuliaLang:masterfrom
N5N3:findminmax
Open

Fix findmin/max with dims for non-1 based inputs.#45822
N5N3 wants to merge 3 commits into
JuliaLang:masterfrom
N5N3:findminmax

Conversation

@N5N3

@N5N3 N5N3 commented Jun 26, 2022

Copy link
Copy Markdown
Member

This PR fixs the possible error from findmin/max by ensuring that the input's keys contains no zero. (Close #38660)
The added check might be expensive (zi in keys calls iterate based fallback), but I can't find a non-breaking way to do the same check.

This PR also add a faster fallback if the input's keys is a AbstractArray with the same axes.
My local bench shows that it makes findmin/max almost 2x faster if f is cheap.

@N5N3 N5N3 added the bugfix This change fixes an existing bug label Jun 26, 2022
@N5N3 N5N3 changed the title Check the legality of zero-index based initialization. Fix 'findmin/max' with dims for non-1 based inputs. Jun 26, 2022
@N5N3 N5N3 changed the title Fix 'findmin/max' with dims for non-1 based inputs. Fix findmin/max with dims for non-1 based inputs. Jun 26, 2022
@N5N3 N5N3 force-pushed the findminmax branch 2 times, most recently from ef914a7 to 4c6c1c6 Compare June 29, 2022 01:46

@andrewjradcliffe andrewjradcliffe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a good idea. Once approved, I'll need to update #45783 to utilize the same approach.

Comment thread base/reducedim.jl Outdated
Comment thread base/reducedim.jl
N5N3 and others added 2 commits July 12, 2022 11:08
And add an optimized fallback for `keys::AbstractArray` (almost 2x faster with cheap `f`.)
1. remove `check_reducedims` within `mapfirst!`.
    `init_array!` for other reductions also skip this check.
     it should be safe to remove it as we add no `@inbounds`
2. remove unneeded `getindex`.

Co-Authored-By: Andrew Radcliffe <96091198+andrewjradcliffe@users.noreply.github.com>
@brenhinkeller brenhinkeller added the search & find The find* family of functions label Nov 17, 2022
@vtjnash vtjnash added merge me PR is reviewed. Merge when all tests are passing and removed merge me PR is reviewed. Merge when all tests are passing labels Oct 1, 2025
@vtjnash

vtjnash commented Oct 1, 2025

Copy link
Copy Markdown
Member

@mbauman is this still superseded by #58418? That is quite a list of bugs and PRs you appear about to cleanup with that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This change fixes an existing bug search & find The find* family of functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findmin(A; dims) ignores first value if index is 0

5 participants