Skip to content
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

Replace the call to sort by select in stdlib_stats_median #584

Merged
merged 7 commits into from
Dec 10, 2021

Conversation

jvdp1
Copy link
Member

@jvdp1 jvdp1 commented Dec 1, 2021

Based on the performance tests reported in stdlib_selection.md, I replaced all calls to sort by select in stdlib_stats_median.fypp.

src/stdlib_stats_median.fypp Outdated Show resolved Hide resolved
@jvdp1 jvdp1 requested a review from gareth-nx December 1, 2021 20:54
Copy link
Contributor

@gareth-nx gareth-nx left a comment

Choose a reason for hiding this comment

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

Thanks very much!

src/stdlib_stats_median.fypp Outdated Show resolved Hide resolved
src/stdlib_stats_median.fypp Outdated Show resolved Hide resolved
src/tests/stats/test_median.fypp Show resolved Hide resolved
@gareth-nx
Copy link
Contributor

I just realised that it will also be necessary to update the specs.

At the moment the specs indicated that after a call to median, the input array is sorted. Whereas now it will only be partially sorted.

@jvdp1
Copy link
Member Author

jvdp1 commented Dec 2, 2021

I just realised that it will also be necessary to update the specs.

At the moment the specs indicated that after a call to median, the input array is sorted. Whereas now it will only be partially sorted.

Indeed, I forgot it. It is now done. Note that the input array is an intent(in) and it is therefore not modified. A copy of the array is always done.

@leonfoks
Copy link

leonfoks commented Dec 2, 2021

The side effect of having a modified input array is actually beneficial to the speed of KdTrees once those are implemented or any other recursive partitioning that uses the median.
Can an optional argument be added like “in-place” (like a lot of numpy methods) so a user can specifically request in place memory manipulation?

@gareth-nx
Copy link
Contributor

The side effect of having a modified input array is actually beneficial to the speed of KdTrees once those are implemented or any other recursive partitioning that uses the median. Can an optional argument be added like “in-place” (like a lot of numpy methods) so a user can specifically request in place memory manipulation?

@leonfoks In this case, one could just use select or arg_select directly -- and the in-place partial sort will happen.

However that is not exactly the same as computing the median (if there are an even number of elements). Does the KdTree application need this variant of the median, or does the result of select or arg_select alone suffice?

@leonfoks
Copy link

leonfoks commented Dec 2, 2021

Good point @gareth-nx ! I forgot that median was wrapping the select methods... Ignore my last comment!

@jvdp1 jvdp1 added the reviewers needed This patch requires extra eyes label Dec 3, 2021
Copy link
Contributor

@gareth-nx gareth-nx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

Copy link
Member

@milancurcic milancurcic left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@milancurcic milancurcic merged commit d58f77d into fortran-lang:master Dec 10, 2021
@jvdp1 jvdp1 deleted the median_select branch December 22, 2021 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewers needed This patch requires extra eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants