diff --git a/include/xtensor/views/xslice.hpp b/include/xtensor/views/xslice.hpp index 3b4d3a6fb..775123934 100644 --- a/include/xtensor/views/xslice.hpp +++ b/include/xtensor/views/xslice.hpp @@ -484,7 +484,7 @@ namespace xt template inline auto drop(T&& indices) { - if constexpr (xtl::is_integral::value) + if constexpr (xtl::is_integral>::value) { using slice_type = xdrop_slice; using container_type = typename slice_type::container_type; diff --git a/test/test_xoperation.cpp b/test/test_xoperation.cpp index fa97a0946..21a9c77bd 100644 --- a/test/test_xoperation.cpp +++ b/test/test_xoperation.cpp @@ -858,6 +858,29 @@ namespace xt EXPECT_EQ(expected1, res3); EXPECT_EQ(expected2, res4); } + + TEST_CASE("divide_4d") + { + using T4 = xt::xtensor; + using shape_type = typename T4::shape_type; + + shape_type shape = {2, 3, 2, 2}; + T4 a(shape, 4.5f); + T4 b(shape, 1.3f); + + EXPECT_EQ((a / b)(0, 0, 0, 0), a(0, 0, 0, 0) / b(0, 0, 0, 0)); + + float sb = 1.2f; + EXPECT_EQ((a / sb)(0, 0, 0, 0), a(0, 0, 0, 0) / sb); + + float sa = 4.6f; + EXPECT_EQ((sa / b)(0, 0, 0, 0), sa / b(0, 0, 0, 0)); + + // self-divide assignment: a = a / b (no zeros in b) + auto a_before = a(1, 2, 1, 1); + a = a / b; + EXPECT_EQ(a(1, 2, 1, 1), a_before / b(1, 2, 1, 1)); + } } #undef XOPERATION_TEST_TYPES diff --git a/test/test_xview.cpp b/test/test_xview.cpp index c98993bf9..18449b742 100644 --- a/test/test_xview.cpp +++ b/test/test_xview.cpp @@ -1861,4 +1861,23 @@ namespace xt XT_ASSERT_THROW(const auto col = xt::col(arr, 0), std::invalid_argument); } + + TEST(xview, drop_on_1dim_array) + { + auto my_array = xt::xtensor({1, 2, 3}); + + // drop(1) creates a view excluding index 1 + auto v1 = xt::view(my_array, xt::drop(1)); + EXPECT_EQ(v1, (xt::xtensor{1, 3})); + + // Assign through the drop view + xt::view(my_array, xt::drop(1)) = 0.; + EXPECT_EQ(my_array, (xt::xtensor{0, 2, 0})); + + // Reset, then test drop with a variable (the original compilation issue) + my_array = xt::xtensor({1, 2, 3}); + const size_t index = 1; + auto v2 = xt::view(my_array, xt::drop(index)); + EXPECT_EQ(v2, (xt::xtensor{1, 3})); + } }