Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion include/xtensor/views/xslice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ namespace xt
template <class R = std::ptrdiff_t, class T>
inline auto drop(T&& indices)
{
if constexpr (xtl::is_integral<T>::value)
if constexpr (xtl::is_integral<std::decay_t<T>>::value)
{
using slice_type = xdrop_slice<R>;
using container_type = typename slice_type::container_type;
Expand Down
23 changes: 23 additions & 0 deletions test/test_xoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,29 @@ namespace xt
EXPECT_EQ(expected1, res3);
EXPECT_EQ(expected2, res4);
}

TEST_CASE("divide_4d")
{
using T4 = xt::xtensor<float, 4, xt::layout_type::row_major>;
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
Expand Down
19 changes: 19 additions & 0 deletions test/test_xview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, 1>({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<double, 1>{1, 3}));

// Assign through the drop view
xt::view(my_array, xt::drop(1)) = 0.;
EXPECT_EQ(my_array, (xt::xtensor<double, 1>{0, 2, 0}));

// Reset, then test drop with a variable (the original compilation issue)
my_array = xt::xtensor<double, 1>({1, 2, 3});
const size_t index = 1;
auto v2 = xt::view(my_array, xt::drop(index));
EXPECT_EQ(v2, (xt::xtensor<double, 1>{1, 3}));
}
}
Loading