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

Fix and refactor partition #2652

Merged
merged 10 commits into from
Mar 8, 2023
Merged

Conversation

AntoinePrv
Copy link
Contributor

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented.

Description

Fix #2651 and refactor (some) of xsort.hpp.
There was a lot of duplications between different functions in this file.
This is far from what I would like to do, but still a good improvement for now!

@AntoinePrv
Copy link
Contributor Author

AntoinePrv commented Feb 15, 2023

Cmake error in CI seems unrelated.

  Could not find a package configuration file provided by "xtl" (requested
  version 0.7.5) with any of the following names:

    xtlConfig.cmake
    xtl-config.cmake

include/xtensor/xsort.hpp Outdated Show resolved Hide resolved
include/xtensor/xsort.hpp Outdated Show resolved Hide resolved
include/xtensor/xsort.hpp Outdated Show resolved Hide resolved
include/xtensor/xsort.hpp Outdated Show resolved Hide resolved
@@ -497,60 +557,20 @@ namespace xt
}

template <class E, class C, class = std::enable_if_t<!xtl::is_integral<C>::value, int>>
inline auto partition(const xexpression<E>& e, const C& kth_container, std::ptrdiff_t axis = -1)
inline auto partition(const xexpression<E>& e, C kth_container, std::ptrdiff_t axis = -1)
Copy link
Member

Choose a reason for hiding this comment

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

This signature is not consistent with the previous overload, where C is passed by const ref. Passing it by value (to avoid the hidden copy) in the previous overload should be the way to go.

Note: the same should be applied to argpartition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JohanMabille Actually a copy of the kth container needs to be made in order to sort it so perhaps better to go with a universal reference.

Copy link
Member

Choose a reason for hiding this comment

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

My point is, if you need a copy of kth_container in the implementation of partition, let's pass this argument by value so that the copy is not hidden to the user.

@JohanMabille JohanMabille merged commit a57a6fa into xtensor-stack:master Mar 8, 2023
@AntoinePrv AntoinePrv deleted the fix-partition branch March 8, 2023 16:24
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.

wrong result with xt::quantile
2 participants