We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
argmin
argmax
axis
1 parent 69eaac5 commit 7008d95Copy full SHA for 7008d95
3 files changed
.github/workflows/ci.yml
@@ -8,7 +8,6 @@ on:
8
9
jobs:
10
11
-
12
linux:
13
14
strategy:
@@ -86,7 +85,6 @@ jobs:
86
85
working-directory: build
87
run: ctest -R ^xtest$ --output-on-failure
88
89
90
macos:
91
92
include/xtensor/xsort.hpp
@@ -1173,8 +1173,17 @@ namespace xt
1173
{
1174
auto begin = e.template begin<L>();
1175
auto end = e.template end<L>();
1176
- std::size_t i = static_cast<std::size_t>(std::distance(begin, std::min_element(begin, end)));
1177
- return xtensor<size_t, 0>{i};
+ // todo C++17 : constexpr
+ if (std::is_same<F, std::less<value_type>>::value)
1178
+ {
1179
+ std::size_t i = static_cast<std::size_t>(std::distance(begin, std::min_element(begin, end)));
1180
+ return xtensor<size_t, 0>{i};
1181
+ }
1182
+ else
1183
1184
+ std::size_t i = static_cast<std::size_t>(std::distance(begin, std::max_element(begin, end)));
1185
1186
1187
}
1188
1189
result_shape_type alt_shape;
test/test_xsort.cpp
@@ -235,6 +235,10 @@ namespace xt
235
EXPECT_EQ(ex, argmin(xa));
236
EXPECT_EQ(ex_2, argmin(xa, 0));
237
EXPECT_EQ(ex_3, argmin(xa, 1));
238
+
239
+ xtensor<double, 1> ya = {1, 0, 3, 2, 2};
240
+ EXPECT_EQ(1, argmin(ya)());
241
+ EXPECT_EQ(1, argmin(ya, 0)());
242
243
244
TEST(xsort, argmax)
@@ -263,6 +267,10 @@ namespace xt
263
267
xtensor<std::size_t, 2> ex_6 = {{0, 0, 0, 0}, {0, 0, 0, 0}};
264
268
EXPECT_EQ(ex_6, argmax(c, 1));
265
269
270
271
+ EXPECT_EQ(2, argmax(ya)());
272
+ EXPECT_EQ(2, argmax(ya, 0)());
273
266
274
// xtensor#2568
275
xarray<double> d = {0, 1, 0};
276
xtensor<size_t, 0> d_ex_1 = {1};
0 commit comments