| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b4a9f8e commit 4149fb7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1052,17 +1052,15 @@ namespace xt | |||
| 1052 | 1052 | { | |
| 1053 | 1053 | auto cpy = empty_like(e); | |
| 1054 | 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 | - } | ||
| 1055 | + const auto dim = cpy.dimension(); | ||
| 1060 | 1056 | ||
| 1061 | - if (saxis >= cpy.dimension() || axis < 0) | ||
| 1057 | + if (axis < -static_cast<std::ptrdiff_t>(dim) || axis >= static_cast<std::ptrdiff_t>(dim)) | ||
| 1062 | 1058 | { | |
| 1063 | - XTENSOR_THROW(std::runtime_error, "axis is no within shape dimension."); | ||
| 1059 | + XTENSOR_THROW(std::runtime_error, "axis is not within shape dimension."); | ||
| 1064 | 1060 | } | |
| 1065 | 1061 | ||
| 1062 | + std::size_t saxis = normalize_axis(dim, axis); | ||
| 1063 | + | ||
| 1066 | 1064 | const auto axis_dim = static_cast<std::ptrdiff_t>(shape[saxis]); | |
| 1067 | 1065 | while (shift < 0) | |
| 1068 | 1066 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -502,6 +502,18 @@ namespace xt | |||
| 502 | 502 | ||
| 503 | 503 | xarray<double> expected8 = {{{3, 1, 2}}, {{6, 4, 5}}, {{9, 7, 8}}}; | |
| 504 | 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)); | ||
| 505 | 517 | } | |
| 506 | 518 | ||
| 507 | 519 | TEST(xmanipulation, repeat_all_elements_of_axis_0_of_int_array_2_times) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments