We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b4a9f8e commit 9575b39Copy full SHA for 9575b39
2 files changed
include/xtensor/misc/xmanipulation.hpp
@@ -1052,17 +1052,15 @@ namespace xt
1052
{
1053
auto cpy = empty_like(e);
1054
const auto& shape = cpy.shape();
1055
- std::size_t saxis = static_cast<std::size_t>(axis);
1056
- if (axis < 0)
1057
- {
1058
- axis += std::ptrdiff_t(cpy.dimension());
1059
- }
+ const auto dim = cpy.dimension();
1060
1061
- if (saxis >= cpy.dimension() || axis < 0)
+ if (axis < -static_cast<std::ptrdiff_t>(dim) || axis >= static_cast<std::ptrdiff_t>(dim))
1062
1063
- XTENSOR_THROW(std::runtime_error, "axis is no within shape dimension.");
+ XTENSOR_THROW(std::runtime_error, "axis is not within shape dimension.");
1064
}
1065
+ std::size_t saxis = normalize_axis(dim, axis);
+
1066
const auto axis_dim = static_cast<std::ptrdiff_t>(shape[saxis]);
1067
while (shift < 0)
1068
test/test_xmanipulation.cpp
@@ -502,6 +502,18 @@ namespace xt
502
503
xarray<double> expected8 = {{{3, 1, 2}}, {{6, 4, 5}}, {{9, 7, 8}}};
504
ASSERT_EQ(expected8, xt::roll(e2, -2, /*axis*/ 2));
505
506
+ EXPECT_THROW(xt::roll(e2, 1, /*axis*/ 3), std::runtime_error);
507
+ EXPECT_THROW(xt::roll(e2, 1, /*axis*/ -4), std::runtime_error);
508
509
+ xarray<double> expected9 = {{{3, 1, 2}}, {{6, 4, 5}}, {{9, 7, 8}}};
510
+ ASSERT_EQ(expected9, xt::roll(e2, -2, /*axis*/ -1));
511
512
+ xarray<double> expected10 = {{{1, 2, 3}}, {{4, 5, 6}}, {{7, 8, 9}}};
513
+ ASSERT_EQ(expected10, xt::roll(e2, -2, /*axis*/ -2));
514
515
+ xarray<double> expected11 = {{{4, 5, 6}}, {{7, 8, 9}}, {{1, 2, 3}}};
516
+ ASSERT_EQ(expected11, xt::roll(e2, 2, /*axis*/ -3));
517
518
519
TEST(xmanipulation, repeat_all_elements_of_axis_0_of_int_array_2_times)
0 commit comments