Skip to content

Commit

Permalink
mxp: Test .view(...).view(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpfeil committed Jan 24, 2025
1 parent b400179 commit ec5cab7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/test_mxp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,48 @@ TEST(mxp, view_slice_2D)
}
}

TEST(mxp, view_view_axaxaxpy)
{
const int nx{3};
const int ny{5};
const float x_init{exp2f(-23)};
const float y_init{1.f};
const float a{1.f / 3.f};

EXPECT_NE(y_init, y_init + x_init);

const std::vector<float> x(nx, x_init);
/* */ std::vector<float> y(ny, y_init);

const auto gt_x = gt::adapt<1>(x.data(), x.size());
/* */ auto gt_y = gt::adapt<1>(y.data(), y.size());

using gt::placeholders::_s;

gt_y.view(_s(1, -1)).view(_s(1, -1)) =
gt_y.view(_s(1, -1)).view(_s(1, -1)) + a * gt_x.view(_s(1, -1)) +
a * gt_x.view(_s(1, -1)) + a * gt_x.view(_s(1, -1));

EXPECT_EQ(y[0], y_init);
EXPECT_EQ(y[1], y_init);
EXPECT_EQ(y[2], y_init);
EXPECT_EQ(y[3], y_init);
EXPECT_EQ(y[4], y_init);

const auto mxp_x = mxp::adapt<1, double>(x.data(), x.size());
/* */ auto mxp_y = mxp::adapt<1, double>(y.data(), y.size());

mxp_y.view(_s(1, -1)).view(_s(1, -1)) =
mxp_y.view(_s(1, -1)).view(_s(1, -1)) + a * mxp_x.view(_s(1, -1)) +
a * mxp_x.view(_s(1, -1)) + a * mxp_x.view(_s(1, -1));

EXPECT_EQ(y[0], y_init);
EXPECT_EQ(y[1], y_init);
EXPECT_EQ(y[2], y_init + x_init);
EXPECT_EQ(y[3], y_init);
EXPECT_EQ(y[4], y_init);
}

TEST(mxp, view_complex_axaxaxpy)
{
using complex32_t = gt::complex<float>;
Expand Down

0 comments on commit ec5cab7

Please sign in to comment.