Skip to content

Commit cae96da

Browse files
committed
Fix SIMD assignment to xfunctor_view destinations (#2892)
xt::real(e) = w failed to compile with XTENSOR_USE_XSIMD: the SIMD gate only probed load_simd, but the linear assigner also needs data() on the destination, which functor views lack. Gate the SIMD paths on data_interface_expression<E1> instead; functor views fall back to scalar assignment while containers keep the SIMD path. Adds a regression test (test_xcomplex.assign_to_real_part).
1 parent 3c61330 commit cae96da

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

include/xtensor/core/xassign.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ namespace xt
392392

393393
static constexpr bool simd_interface()
394394
{
395-
return has_simd_interface<E1, requested_value_type>()
395+
return data_interface_expression<E1>
396+
&& has_simd_interface<E1, requested_value_type>()
396397
&& has_simd_interface<E2, requested_value_type>();
397398
}
398399

test/test_xcomplex.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ namespace xt
319319
EXPECT_EQ(a(4, 4), cmplx(-123.321L, -123.321L));
320320
}
321321

322+
TEST(xcomplex, assign_to_real_part)
323+
{
324+
using cpx = std::complex<double>;
325+
xt::xtensor<cpx, 1> a = {cpx(1, 2), cpx(3, 4), cpx(5, 6), cpx(7, 8), cpx(9, 10)};
326+
xt::xtensor<double, 1> wr = {11, 12, 13, 14, 15};
327+
xt::real(a) = wr;
328+
xt::xtensor<cpx, 1> expected = {cpx(11, 2), cpx(12, 4), cpx(13, 6), cpx(14, 8), cpx(15, 10)};
329+
EXPECT_EQ(a, expected);
330+
}
331+
322332
TEST(xcomplex, build_from_double)
323333
{
324334
xt::xarray<double> r = {1., 2., 3.};

0 commit comments

Comments
 (0)