Skip to content

Commit 8e4cee3

Browse files
committed
Fix drop function to handle decayed types and add unit test for 1D array drop
1 parent 1d158a9 commit 8e4cee3

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

include/xtensor/views/xslice.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ namespace xt
484484
template <class R = std::ptrdiff_t, class T>
485485
inline auto drop(T&& indices)
486486
{
487-
if constexpr (xtl::is_integral<T>::value)
487+
if constexpr (xtl::is_integral<std::decay_t<T>>::value)
488488
{
489489
using slice_type = xdrop_slice<R>;
490490
using container_type = typename slice_type::container_type;

test/test_xview.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,4 +1861,16 @@ namespace xt
18611861

18621862
XT_ASSERT_THROW(const auto col = xt::col(arr, 0), std::invalid_argument);
18631863
}
1864+
1865+
TEST(xview, drop_on_1dim_array)
1866+
{
1867+
const auto my_array = xt::xtensor<double, 1>({1, 2, 3});
1868+
1869+
xt::view(my_array, xt::drop(1));
1870+
EXPECT_EQ(my_array, (xt::xtensor<double, 1>{1, 3}));
1871+
1872+
const size_t index = 1;
1873+
xt::view(my_array, xt::drop(index));
1874+
EXPECT_EQ(my_array, (xt::xtensor<double, 1>{1}));
1875+
}
18641876
}

0 commit comments

Comments
 (0)