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

Fixing bug in argmin/argmax called with axis on rank-1 container #2753

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:


linux:

strategy:
Expand Down Expand Up @@ -86,7 +85,6 @@ jobs:
working-directory: build
run: ctest -R ^xtest$ --output-on-failure


macos:

strategy:
Expand Down
12 changes: 10 additions & 2 deletions include/xtensor/xsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,16 @@ namespace xt
{
auto begin = e.template begin<L>();
auto end = e.template end<L>();
std::size_t i = static_cast<std::size_t>(std::distance(begin, std::min_element(begin, end)));
return xtensor<size_t, 0>{i};
if (std::is_same<F, std::less<value_type>>::value)
{
tdegeus marked this conversation as resolved.
Show resolved Hide resolved
std::size_t i = static_cast<std::size_t>(std::distance(begin, std::min_element(begin, end)));
return xtensor<size_t, 0>{i};
}
else
{
std::size_t i = static_cast<std::size_t>(std::distance(begin, std::max_element(begin, end)));
return xtensor<size_t, 0>{i};
}
}

result_shape_type alt_shape;
Expand Down
8 changes: 8 additions & 0 deletions test/test_xsort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ namespace xt
EXPECT_EQ(ex, argmin(xa));
EXPECT_EQ(ex_2, argmin(xa, 0));
EXPECT_EQ(ex_3, argmin(xa, 1));

xtensor<double, 1> ya = {1, 0, 3, 2, 2};
EXPECT_EQ(1, argmin(ya)());
EXPECT_EQ(1, argmin(ya, 0)());
}

TEST(xsort, argmax)
Expand Down Expand Up @@ -263,6 +267,10 @@ namespace xt
xtensor<std::size_t, 2> ex_6 = {{0, 0, 0, 0}, {0, 0, 0, 0}};
EXPECT_EQ(ex_6, argmax(c, 1));

xtensor<double, 1> ya = {1, 0, 3, 2, 2};
EXPECT_EQ(2, argmax(ya)());
EXPECT_EQ(2, argmax(ya, 0)());

// xtensor#2568
xarray<double> d = {0, 1, 0};
xtensor<size_t, 0> d_ex_1 = {1};
Expand Down