- std::vector<unsigned int>
- reverse_permutation(const std::vector<unsigned int> &permutation)
+ template <typename Integer>
+ std::vector<Integer>
+ reverse_permutation(const std::vector<Integer> &permutation)
{
- const unsigned int n = permutation.size();
+ const std::size_t n = permutation.size();
- std::vector<unsigned int> out(n);
- for (unsigned int i = 0; i < n; ++i)
+ std::vector<Integer> out(n);
+ for (std::size_t i = 0; i < n; ++i)
out[i] = n - 1 - permutation[i];
return out;
- std::vector<unsigned int>
- invert_permutation(const std::vector<unsigned int> &permutation)
+ template <typename Integer>
+ std::vector<Integer>
+ invert_permutation(const std::vector<Integer> &permutation)
{
- const unsigned int n = permutation.size();
+ const std::size_t n = permutation.size();
- std::vector<unsigned int> out(n, numbers::invalid_unsigned_int);
+ std::vector<Integer> out(n, numbers::invalid_unsigned_int);
- for (unsigned int i = 0; i < n; ++i)
+ for (std::size_t i = 0; i < n; ++i)
{
AssertIndexRange(permutation[i], n);
out[permutation[i]] = i;
return out;
}
- std::vector<std::uint64_t>
- reverse_permutation(const std::vector<std::uint64_t> &permutation)
- {
- const std::uint64_t n = permutation.size();
- std::vector<std::uint64_t> out(n);
- for (std::uint64_t i = 0; i < n; ++i)
- out[i] = n - 1 - permutation[i];
- return out;
+ std::vector<unsigned int>
+ reverse_permutation(const std::vector<unsigned int> &permutation)
+ {
+ return reverse_permutation<unsigned int>(permutation);
}
- std::vector<std::uint64_t>
- invert_permutation(const std::vector<std::uint64_t> &permutation)
+ std::vector<unsigned int>
+ invert_permutation(const std::vector<unsigned int> &permutation)
{
- const std::uint64_t n = permutation.size();
-
- std::vector<std::uint64_t> out(n, numbers::invalid_dof_index);
-
- for (std::uint64_t i = 0; i < n; ++i)
- {
- AssertIndexRange(permutation[i], n);
- out[permutation[i]] = i;
- }
-
- // check that we have actually reached
- // all indices
- for (std::uint64_t i = 0; i < n; ++i)
- Assert(out[i] != numbers::invalid_unsigned_int,
- ExcMessage("The given input permutation had duplicate entries!"));
-
- return out;
+ return invert_permutation<unsigned int>(permutation);
}
- template <typename Integer>
- std::vector<Integer>
- reverse_permutation(const std::vector<Integer> &permutation)
- {
- const std::size_t n = permutation.size();
-
- std::vector<Integer> out(n);
- for (std::size_t i = 0; i < n; ++i)
- out[i] = n - 1 - permutation[i];
- return out;
+ std::vector<std::uint64_t>
+ reverse_permutation(const std::vector<std::uint64_t> &permutation)
+ {
+ return reverse_permutation<std::uint64_t>(permutation);
}
- template <typename Integer>
- std::vector<Integer>
- invert_permutation(const std::vector<Integer> &permutation)
+ std::vector<std::uint64_t>
+ invert_permutation(const std::vector<std::uint64_t> &permutation)
{
- const std::size_t n = permutation.size();
-
- std::vector<Integer> out(n, numbers::invalid_unsigned_int);
-
- for (std::size_t i = 0; i < n; ++i)
- {
- AssertIndexRange(permutation[i], n);
- out[permutation[i]] = i;
- }
-
- // check that we have actually reached
- // all indices
- for (unsigned int i = 0; i < n; ++i)
- Assert(out[i] != numbers::invalid_unsigned_int,
- ExcMessage("The given input permutation had duplicate entries!"));
-
- return out;
+ return invert_permutation<std::uint64_t>(permutation);
}