39 if (indices.size() != values.size())
40 throw std::runtime_error(
"Cannot sort two arrays of different lengths");
42 using T = std::pair<typename U::value_type, typename V::value_type>;
43 std::vector<T> data(indices.size());
44 std::ranges::transform(indices, values, data.begin(),
45 [](
const auto& idx,
const auto& v) -> T
46 { return {idx, v}; });
50 std::ranges::sort(data);
51 auto it = std::ranges::unique(data, [](
const auto& a,
const auto& b)
52 {
return a.first == b.first; })
55 std::vector<typename U::value_type> indices_new;
56 std::vector<typename V::value_type> values_new;
57 std::size_t n = std::ranges::distance(data.begin(), it);
58 indices_new.reserve(n);
59 values_new.reserve(n);
60 std::transform(data.begin(), it, std::back_inserter(indices_new),
61 [](
const auto& d) { return d.first; });
62 std::transform(data.begin(), it, std::back_inserter(values_new),
63 [](
const auto& d) { return d.second; });
65 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:89
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:37