Skip to content

Commit

Permalink
Merge pull request #2622 from AntoinePrv/const-index-view
Browse files Browse the repository at this point in the history
Change xindex_view reference type to handle const data
  • Loading branch information
JohanMabille authored Dec 23, 2022
2 parents 9f7196a + 02525c5 commit 5f45138
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/xtensor/xindex_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace xt
using expression_tag = typename extension_base::expression_tag;

using value_type = typename xexpression_type::value_type;
using reference = typename xexpression_type::reference;
using reference = inner_reference_t<CT>;
using const_reference = typename xexpression_type::const_reference;
using pointer = typename xexpression_type::pointer;
using const_pointer = typename xexpression_type::const_pointer;
Expand Down
9 changes: 9 additions & 0 deletions test/test_xindex_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ namespace xt
EXPECT_EQ(3, e(2, 2));
}

TEST(xindex_view, indices_const)
{
xarray<double> const e = xt::random::rand<double>({3, 3});
auto v = index_view(e, {{1ul, 1ul}, {1ul, 2ul}, {2ul, 2ul}});
EXPECT_EQ(e(1, 1), v(0));
auto const vc = index_view(e, {{1ul, 1ul}, {1ul, 2ul}, {2ul, 2ul}});
EXPECT_EQ(vc(0), v(0));
}

TEST(xindex_view, boolean)
{
xarray<double> e = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
Expand Down

0 comments on commit 5f45138

Please sign in to comment.