Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix xmasked_view with xfunction #2501

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
9 changes: 6 additions & 3 deletions include/xtensor/xmasked_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ namespace xt
using bool_load_type = xtl::xmasked_value<typename data_type::bool_load_type, mask_type>;

using shape_type = typename data_type::shape_type;
using strides_type = typename data_type::strides_type;

static constexpr layout_type static_layout = data_type::static_layout;
static constexpr bool contiguous_layout = false;

using inner_shape_type = typename data_type::inner_shape_type;
using inner_strides_type = typename data_type::inner_strides_type;
using inner_backstrides_type = typename data_type::inner_backstrides_type;
using inner_strides_type = xtl::mpl::eval_if_t<has_strides<data_type>,
detail::expr_inner_strides_type<data_type>,
get_strides_type<shape_type>>;
using inner_backstrides_type = xtl::mpl::eval_if_t<has_strides<data_type>,
detail::expr_inner_backstrides_type<data_type>,
get_strides_type<shape_type>>;

using expression_tag = xtensor_expression_tag;

Expand Down
26 changes: 21 additions & 5 deletions test/test_xmasked_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,33 @@ namespace xt

TEST(xmasked_view, view)
{
xt::xarray<size_t> data = {{0,1}, {2,3}, {4,5}};
xt::xarray<size_t> data_new = xt::zeros<size_t>(data.shape());
xt::xarray<bool> col_mask = {false, true};
xarray<size_t> data = {{0,1}, {2,3}, {4,5}};
xarray<size_t> data_new = zeros<size_t>(data.shape());
xarray<bool> col_mask = {false, true};

auto row_masked = xt::masked_view(xt::view(data, 0, xt::all()), col_mask);
auto new_row_masked = xt::masked_view(xt::view(data_new, 0, xt::all()), col_mask);
auto row_masked = masked_view(view(data, 0, all()), col_mask);
auto new_row_masked = masked_view(view(data_new, 0, all()), col_mask);

row_masked += 10;
new_row_masked = row_masked;

EXPECT_EQ(data_new(0, 0), size_t(0));
EXPECT_EQ(data_new(0, 1), size_t(11));
}

TEST(xmasked_view, xfunction)
{
xt::xarray<size_t> data = {{0,1}, {2,3}, {4,5}};
xt::xarray<size_t> data_new = xt::zeros<size_t>(data.shape());
xt::xarray<bool> mask = {{true, false},
{false, true},
{true, false}};

masked_view(data_new, mask) = masked_view(2UL*data + 1UL, mask);

xarray<size_t> expected = {{1, 0},
{0, 7},
{9, 0}};
EXPECT_EQ(data_new, expected);
}
}