32 if (indices.size() != values.size())
33 throw std::runtime_error(
"Cannot sort two arrays of different lengths");
35 using T =
typename std::pair<typename U::value_type, typename V::value_type>;
36 std::vector<T> data(indices.size());
37 std::ranges::transform(indices, values, data.begin(),
38 [](
auto& idx,
auto& v) -> T { return {idx, v}; });
41 std::ranges::sort(data);
42 auto it = std::ranges::unique(data, [](
auto& a,
auto& b)
43 {
return a.first == b.first; })
46 std::vector<typename U::value_type> indices_new;
47 std::vector<typename V::value_type> values_new;
48 indices_new.reserve(data.size());
49 values_new.reserve(data.size());
50 std::transform(data.begin(), it, std::back_inserter(indices_new),
51 [](
auto& d) { return d.first; });
52 std::transform(data.begin(), it, std::back_inserter(values_new),
53 [](
auto& d) { return d.second; });
55 return {std::move(indices_new), std::move(values_new)};
void check_error(MPI_Comm comm, int code)
Check MPI error code. If the error code is not equal to MPI_SUCCESS, then std::abort is called.
Definition MPI.cpp:80
std::pair< std::vector< typename U::value_type >, std::vector< typename V::value_type > > sort_unique(const U &indices, const V &values)
Sort two arrays based on the values in array indices.
Definition utils.h:30