Skip to content

Conversation

N5N3
Copy link
Member

@N5N3 N5N3 commented Jun 26, 2022

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
Copy link
Contributor

@andrewjradcliffe andrewjradcliffe left a comment

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.

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 <[email protected]>
@brenhinkeller brenhinkeller added the search & find The find* family of functions label Nov 17, 2022
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
3 participants