Distributed Ranges
Loading...
Searching...
No Matches
equal.hpp
1// SPDX-FileCopyrightText: Intel Corporation
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#pragma once
6
7#include <dr/sp/algorithms/fill.hpp>
8#include <dr/sp/algorithms/reduce.hpp>
9#include <dr/sp/detail.hpp>
10#include <dr/sp/init.hpp>
11#include <dr/sp/util.hpp>
12#include <dr/sp/views/views.hpp>
13#include <dr/sp/zip_view.hpp>
14
15namespace dr::sp {
16
17template <typename ExecutionPolicy, dr::distributed_range R1,
19 requires std::equality_comparable_with<rng::range_value_t<R1>,
20 rng::range_value_t<R2>>
21bool equal(ExecutionPolicy &&policy, R1 &&r1, R2 &&r2) {
22
23 if (rng::distance(r1) != rng::distance(r2)) {
24 return false;
25 }
26
27 // we must use ints instead of bools, because distributed ranges do not
28 // support bools
29 auto compare = [](auto &&elems) {
30 return elems.first == elems.second ? 1 : 0;
31 };
32
33 auto zipped_views = views::zip(r1, r2);
34 auto compared = sp::views::transform(zipped_views, compare);
35 auto min = [](double x, double y) { return std::min(x, y); };
36 auto result = sp::reduce(policy, compared, 1, min);
37 return result == 1;
38}
39
40template <dr::distributed_range R1, dr::distributed_range R2>
41bool equal(R1 &&r1, R2 &&r2) {
42 return equal(dr::sp::par_unseq, r1, r2);
43}
44} // namespace dr::sp
Definition: concepts.hpp:20