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

Add tests for in-place and copying std::transform #343

Merged
merged 1 commit into from
Aug 31, 2021
Merged
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
82 changes: 82 additions & 0 deletions tests/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,88 @@ TEST_CASE("iterator.transform_reduce")
test(llama::ArrayDims{4, 2, 4});
}

TEST_CASE("iterator.transform_inplace")
{
auto test = [](auto arrayDims)
{
auto view = llama::allocView(llama::mapping::AoS{arrayDims, Position{}});

int i = 0;
for(auto vd : view)
{
vd(tag::X{}) = ++i;
vd(tag::Y{}) = ++i;
vd(tag::Z{}) = ++i;
}

std::transform(
begin(view),
end(view),
begin(view),
[](llama::One<Position> p)
{
p *= 2;
return p;
});

i = 0;
for(auto vd : view)
{
CHECK(vd(tag::X{}) == ++i * 2);
CHECK(vd(tag::Y{}) == ++i * 2);
CHECK(vd(tag::Z{}) == ++i * 2);
}
};
test(llama::ArrayDims{32});
test(llama::ArrayDims{4, 8});
test(llama::ArrayDims{4, 2, 4});
}

TEST_CASE("iterator.transform_to")
{
auto test = [](auto arrayDims)
{
auto view = llama::allocView(llama::mapping::AoS{arrayDims, Position{}});

int i = 0;
for(auto vd : view)
{
vd(tag::X{}) = ++i;
vd(tag::Y{}) = ++i;
vd(tag::Z{}) = ++i;
}

auto dst = llama::allocView(llama::mapping::SoA{arrayDims, Position{}});
std::transform(
begin(view),
end(view),
begin(dst),
[](llama::One<Position> p)
{
p *= 2;
return p;
});

i = 0;
for(auto vd : view)
{
CHECK(vd(tag::X{}) == ++i);
CHECK(vd(tag::Y{}) == ++i);
CHECK(vd(tag::Z{}) == ++i);
}
i = 0;
for(auto vd : dst)
{
CHECK(vd(tag::X{}) == ++i * 2);
CHECK(vd(tag::Y{}) == ++i * 2);
CHECK(vd(tag::Z{}) == ++i * 2);
}
};
test(llama::ArrayDims{32});
test(llama::ArrayDims{4, 8});
test(llama::ArrayDims{4, 2, 4});
}

TEST_CASE("iterator.different_record_dim")
{
struct Pos1
Expand Down