• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #843

01 Dec 2022 08:42PM UTC coverage: 85.634% (-0.05%) from 85.679%
#843

push

hkaiser
Leftover changes from recent namespace cleanups

3 of 3 new or added lines in 2 files covered. (100.0%)

171057 of 199754 relevant lines covered (85.63%)

1930208.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.08
/libs/full/segmented_algorithms/tests/unit/partitioned_vector_transform1.cpp
1
//  Copyright (c) 2017 Ajai V George
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#if !defined(HPX_COMPUTE_DEVICE_CODE)
9
#include <hpx/hpx_main.hpp>
10
#include <hpx/include/parallel_count.hpp>
11
#include <hpx/include/parallel_transform.hpp>
12
#include <hpx/include/partitioned_vector_predef.hpp>
13
#include <hpx/include/runtime.hpp>
14
#include <hpx/modules/testing.hpp>
15

16
#include <cstddef>
17
#include <vector>
18

19
///////////////////////////////////////////////////////////////////////////////
20
template <typename U>
21
struct pfo
22
{
23
    template <typename T>
24
    U operator()(T& val) const
24✔
25
    {
26
        return U((T(2) * val));
24✔
27
    }
28
};
29

30
template <typename U>
31
struct add
32
{
33
    template <typename T1, typename T2>
34
    U operator()(T1 const& v1, T2 const& v2) const
35
    {
36
        return U(v1 + v2);
37
    }
38
};
39

40
template <typename T>
41
struct cmp
42
{
43
    cmp(T const& val = T())
8✔
44
      : value_(val)
8✔
45
    {
46
    }
8✔
47

48
    template <typename T_>
49
    bool operator()(T_ const& val) const
48✔
50
    {
51
        return val == value_;
48✔
52
    }
53

54
    T value_;
55

56
    template <typename Archive>
57
    void serialize(Archive& ar, unsigned)
8✔
58
    {
59
        // clang-format off
60
        ar & value_;
8✔
61
        // clang-format on
62
    }
8✔
63
};
64

65
///////////////////////////////////////////////////////////////////////////////
66
template <typename ExPolicy, typename T, typename U = T>
67
void verify_values(
×
68
    ExPolicy&&, hpx::partitioned_vector<T> const& v, U const& val)
69
{
70
    typedef typename hpx::partitioned_vector<T>::const_iterator const_iterator;
71

72
    std::size_t size = 0;
×
73

74
    const_iterator end = v.end();
×
75
    for (const_iterator it = v.begin(); it != end; ++it, ++size)
×
76
    {
77
        HPX_TEST_EQ(*it, val);
×
78
    }
×
79

80
    HPX_TEST_EQ(size, v.size());
×
81
}
×
82

83
template <typename ExPolicy, typename T, typename U = T>
84
void verify_values_count(
×
85
    ExPolicy&& policy, hpx::partitioned_vector<T> const& v, U const& val)
86
{
87
    HPX_TEST_EQ(
×
88
        std::size_t(hpx::count(policy, v.begin(), v.end(), val)), v.size());
89
    HPX_TEST_EQ(
×
90
        std::size_t(hpx::count_if(policy, v.begin(), v.end(), cmp<T>(val))),
91
        v.size());
92
}
×
93

94
template <typename ExPolicy, typename T, typename U = T>
95
void test_transform(ExPolicy&& policy, hpx::partitioned_vector<T>& v,
×
96
    hpx::partitioned_vector<U>& w, U val)
97
{
98
    verify_values(policy, v, val);
×
99
    verify_values_count(policy, v, val);
×
100

101
    hpx::transform(policy, v.begin(), v.end(), w.begin(), pfo<U>());
×
102

103
    verify_values(policy, w, 2 * val);
×
104
    verify_values_count(policy, w, 2 * val);
×
105
}
×
106

107
template <typename ExPolicy, typename T, typename U = T>
108
void verify_values_count_async(
×
109
    ExPolicy&& policy, hpx::partitioned_vector<T> const& v, U const& val)
110
{
111
    HPX_TEST_EQ(std::size_t(hpx::count(policy, v.begin(), v.end(), val).get()),
×
112
        v.size());
113
    HPX_TEST_EQ(
×
114
        std::size_t(
115
            hpx::count_if(policy, v.begin(), v.end(), cmp<T>(val)).get()),
116
        v.size());
117
}
×
118

119
template <typename ExPolicy, typename T, typename U = T>
120
void test_transform_async(ExPolicy&& policy, hpx::partitioned_vector<T>& v,
×
121
    hpx::partitioned_vector<U>& w, U val)
122
{
123
    verify_values(policy, v, val);
×
124
    verify_values_count_async(policy, v, val);
×
125

126
    hpx::transform(policy, v.begin(), v.end(), w.begin(), pfo<U>()).get();
×
127

128
    verify_values(policy, w, 2 * val);
×
129
    verify_values_count_async(policy, w, 2 * val);
×
130
}
×
131

132
///////////////////////////////////////////////////////////////////////////////
133
template <typename T, typename U = T>
134
void transform_tests(std::vector<hpx::id_type>& localities)
×
135
{
136
    std::size_t const length = 12;
×
137

138
    {
139
        hpx::partitioned_vector<T> v;
×
140
        hpx::partitioned_vector<U> w;
×
141
        hpx::transform(
×
142
            hpx::execution::seq, v.begin(), v.end(), w.begin(), pfo<U>());
×
143
        hpx::transform(
×
144
            hpx::execution::par, v.begin(), v.end(), w.begin(), pfo<U>());
×
145
        hpx::transform(hpx::execution::seq(hpx::execution::task), v.begin(),
×
146
            v.end(), w.begin(), pfo<U>())
×
147
            .get();
×
148
        hpx::transform(hpx::execution::par(hpx::execution::task), v.begin(),
×
149
            v.end(), w.begin(), pfo<U>())
×
150
            .get();
×
151
    }
×
152

153
    {
154
        hpx::partitioned_vector<T> v(
×
155
            length, T(1), hpx::container_layout(localities));
×
156
        hpx::partitioned_vector<U> w(length, hpx::container_layout(localities));
×
157
        test_transform(hpx::execution::seq, v, w, U(1));
×
158
        test_transform(hpx::execution::par, v, w, U(1));
×
159
        test_transform_async(
×
160
            hpx::execution::seq(hpx::execution::task), v, w, U(1));
×
161
        test_transform_async(
×
162
            hpx::execution::par(hpx::execution::task), v, w, U(1));
×
163
    }
×
164
}
×
165

166
///////////////////////////////////////////////////////////////////////////////
167
int main()
×
168
{
169
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
170

171
    transform_tests<int, int>(localities);
×
172

173
    return hpx::util::report_errors();
×
174
}
×
175
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc