Skip to content

Commit deed560

Browse files
authored
dr::views::iota tests and missing functions; dr::mhp::subrange tests (#300)
1 parent 3595309 commit deed560

File tree

9 files changed

+110
-7
lines changed

9 files changed

+110
-7
lines changed

doc/spec/source/algorithms/copy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Interface
1616
MHP
1717
---
1818

19-
.. doxygenfunction:: dr::mhp::copy(dr::distributed_range auto &&in, dr::distributed_iterator auto out)
19+
.. doxygenfunction:: dr::mhp::copy(rng::forward_range auto &&in, dr::distributed_iterator auto out)
2020
:outline:
2121
.. doxygenfunction:: dr::mhp::copy(DI_IN &&first, DI_IN &&last, dr::distributed_iterator auto &&out)
2222
:outline:

doc/spec/source/algorithms/transform.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Interface
1616
MHP
1717
---
1818

19-
.. doxygenfunction:: dr::mhp::transform(dr::distributed_range auto &&in, dr::distributed_iterator auto out, auto op)
19+
.. doxygenfunction:: dr::mhp::transform(rng::forward_range auto &&in, dr::distributed_iterator auto out, auto op)
2020
.. doxygenfunction:: dr::mhp::transform(DI_IN &&first, DI_IN &&last, dr::distributed_iterator auto &&out, auto op)
2121

2222
SHP

include/dr/mhp/algorithms/copy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace dr::mhp {
1010

1111
/// Copy
12-
void copy(dr::distributed_range auto &&in, dr::distributed_iterator auto out) {
12+
void copy(rng::forward_range auto &&in, dr::distributed_iterator auto out) {
1313
if (rng::empty(in)) {
1414
return;
1515
}

include/dr/mhp/algorithms/transform.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
namespace dr::mhp {
1919

20-
void transform(dr::distributed_range auto &&in,
21-
dr::distributed_iterator auto out, auto op) {
20+
void transform(rng::forward_range auto &&in, dr::distributed_iterator auto out,
21+
auto op) {
2222
if (rng::empty(in)) {
2323
return;
2424
}
@@ -32,7 +32,7 @@ void transform(dr::distributed_range auto &&in,
3232
for_each(zip, transform_op);
3333
}
3434

35-
template <dr::distributed_iterator DI_IN>
35+
template <rng::forward_iterator DI_IN>
3636
void transform(DI_IN &&first, DI_IN &&last, dr::distributed_iterator auto &&out,
3737
auto op) {
3838
mhp::transform(rng::subrange(first, last), out, op);

include/dr/mhp/views/zip.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class zip_iterator {
150150
return iter;
151151
}
152152

153-
auto operator==(zip_iterator other) const {
153+
bool operator==(zip_iterator other) const {
154154
return rng_iter_ == other.rng_iter_;
155155
}
156156
auto operator<=>(zip_iterator other) const {

test/gtest/common/iota_view.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-FileCopyrightText: Intel Corporation
2+
//
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
#include "xhp-tests.hpp"
6+
7+
template <typename DistVecT> class IotaView : public testing::Test {
8+
public:
9+
};
10+
11+
TYPED_TEST_SUITE(IotaView, AllTypes);
12+
13+
TYPED_TEST(IotaView, ZipWithDR) {
14+
xhp::distributed_vector<int> dv(10);
15+
auto v = dr::views::iota(1, 10);
16+
17+
auto z = xhp::views::zip(dv, v);
18+
19+
xhp::for_each(z, [](auto ze) {
20+
auto [dve, ve] = ze;
21+
dve = ve;
22+
});
23+
24+
EXPECT_TRUE(equal(std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, dv));
25+
}
26+
27+
TYPED_TEST(IotaView, Copy) {
28+
TypeParam dv(10);
29+
auto v = dr::views::iota(1, 11);
30+
31+
xhp::copy(v, dv.begin());
32+
33+
barrier();
34+
EXPECT_TRUE(equal(std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, dv));
35+
}
36+
37+
TYPED_TEST(IotaView, Transform) {
38+
TypeParam dv(10);
39+
auto v = dr::views::iota(1, 11);
40+
auto negate = [](auto v) { return -v; };
41+
42+
xhp::transform(v, dv.begin(), negate);
43+
44+
EXPECT_TRUE(
45+
equal(dv, std::vector<int>{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}));
46+
}
47+
48+
TYPED_TEST(IotaView, ForEach) {
49+
TypeParam dv(10);
50+
auto v = dr::views::iota(1, 11);
51+
52+
auto negate = [](auto v) {
53+
auto &[in, out] = v;
54+
out = -in;
55+
};
56+
57+
auto z = xhp::views::zip(v, dv);
58+
59+
xhp::for_each(z, negate);
60+
61+
EXPECT_TRUE(
62+
equal(dv, std::vector<int>{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}));
63+
}

test/gtest/common/subrange.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,40 @@ TYPED_TEST(Subrange, Mutate) {
2727
ops, rng::subrange(ops.vec.begin() + 1, ops.vec.end() - 1),
2828
rng::subrange(ops.dist_vec.begin() + 1, ops.dist_vec.end() - 1)));
2929
}
30+
31+
TYPED_TEST(Subrange, ForEach) {
32+
Ops1<TypeParam> ops(23);
33+
34+
auto local = rng::subrange(ops.vec.begin() + 1, ops.vec.end() - 2);
35+
auto dist = rng::subrange(ops.dist_vec.begin() + 1, ops.dist_vec.end() - 2);
36+
37+
auto negate = [](auto v) { return -v; };
38+
rng::for_each(local, negate);
39+
xhp::for_each(dist, negate);
40+
EXPECT_EQ(ops.vec, ops.dist_vec);
41+
}
42+
43+
TYPED_TEST(Subrange, Transform) {
44+
TypeParam v1(13), v2(13);
45+
xhp::iota(v1, 10);
46+
xhp::fill(v2, -1);
47+
48+
auto s1 = rng::subrange(v1.begin() + 1, v1.end() - 2);
49+
auto s2 = rng::subrange(v2.begin() + 1, v2.end() - 2);
50+
51+
auto null_op = [](auto v) { return v; };
52+
xhp::transform(s1, s2.begin(), null_op);
53+
54+
EXPECT_TRUE(equal(v2, std::vector<int>{-1, 11, 12, 13, 14, 15, 16, 17, 18, 19,
55+
20, -1, -1}));
56+
}
57+
58+
TYPED_TEST(Subrange, Reduce) {
59+
Ops1<TypeParam> ops(23);
60+
61+
auto local = rng::subrange(ops.vec.begin() + 1, ops.vec.end() - 2);
62+
auto dist = rng::subrange(ops.dist_vec.begin() + 1, ops.dist_vec.end() - 2);
63+
64+
EXPECT_EQ(std::reduce(local.begin(), local.end(), 3, std::plus{}),
65+
xhp::reduce(dist, 3, std::plus{}));
66+
}

test/gtest/mhp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_executable(
1818
../common/for_each.cpp
1919
../common/inclusive_scan.cpp
2020
../common/iota.cpp
21+
../common/iota_view.cpp
2122
../common/reduce.cpp
2223
../common/subrange.cpp
2324
../common/take.cpp
@@ -62,6 +63,7 @@ if(NOT MPI_IMPL STREQUAL "openmpi")
6263
# MPI_Win_create fails for communicator with size 1
6364
add_mpi_test(mhp-tests-1 mhp-tests 1)
6465
endif()
66+
6567
add_mpi_test(mhp-tests-2 mhp-tests 2)
6668
add_mpi_test(mhp-tests-3 mhp-tests 3)
6769
add_mpi_test(mhp-tests-4 mhp-tests 4)

test/gtest/shp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_executable(
1616
../common/fill.cpp
1717
../common/for_each.cpp
1818
../common/iota.cpp
19+
# ../common/iota_view.cpp
1920
../common/reduce.cpp
2021
../common/subrange.cpp
2122
../common/take.cpp

0 commit comments

Comments
 (0)