Skip to content

Commit 31d1981

Browse files
committed
fix
1 parent 8e4cee3 commit 31d1981

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

test/test_xoperation.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,29 @@ namespace xt
858858
EXPECT_EQ(expected1, res3);
859859
EXPECT_EQ(expected2, res4);
860860
}
861+
862+
TEST_CASE("divide_4d")
863+
{
864+
using T4 = xt::xtensor<float, 4, xt::layout_type::row_major>;
865+
using shape_type = typename T4::shape_type;
866+
867+
shape_type shape = {2, 3, 2, 2};
868+
T4 a(shape, 4.5f);
869+
T4 b(shape, 1.3f);
870+
871+
EXPECT_EQ((a / b)(0, 0, 0, 0), a(0, 0, 0, 0) / b(0, 0, 0, 0));
872+
873+
float sb = 1.2f;
874+
EXPECT_EQ((a / sb)(0, 0, 0, 0), a(0, 0, 0, 0) / sb);
875+
876+
float sa = 4.6f;
877+
EXPECT_EQ((sa / b)(0, 0, 0, 0), sa / b(0, 0, 0, 0));
878+
879+
// self-divide assignment: a = a / b (no zeros in b)
880+
auto a_before = a(1, 2, 1, 1);
881+
a = a / b;
882+
EXPECT_EQ(a(1, 2, 1, 1), a_before / b(1, 2, 1, 1));
883+
}
861884
}
862885

863886
#undef XOPERATION_TEST_TYPES

test/test_xview.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,13 +1864,20 @@ namespace xt
18641864

18651865
TEST(xview, drop_on_1dim_array)
18661866
{
1867-
const auto my_array = xt::xtensor<double, 1>({1, 2, 3});
1867+
auto my_array = xt::xtensor<double, 1>({1, 2, 3});
18681868

1869-
xt::view(my_array, xt::drop(1));
1870-
EXPECT_EQ(my_array, (xt::xtensor<double, 1>{1, 3}));
1869+
// drop(1) creates a view excluding index 1
1870+
auto v1 = xt::view(my_array, xt::drop(1));
1871+
EXPECT_EQ(v1, (xt::xtensor<double, 1>{1, 3}));
18711872

1873+
// Assign through the drop view
1874+
xt::view(my_array, xt::drop(1)) = 0.;
1875+
EXPECT_EQ(my_array, (xt::xtensor<double, 1>{0, 2, 0}));
1876+
1877+
// Reset, then test drop with a variable (the original compilation issue)
1878+
my_array = xt::xtensor<double, 1>({1, 2, 3});
18721879
const size_t index = 1;
1873-
xt::view(my_array, xt::drop(index));
1874-
EXPECT_EQ(my_array, (xt::xtensor<double, 1>{1}));
1880+
auto v2 = xt::view(my_array, xt::drop(index));
1881+
EXPECT_EQ(v2, (xt::xtensor<double, 1>{1, 3}));
18751882
}
18761883
}

0 commit comments

Comments
 (0)