TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Permutations

Detailed Description

Tools to create and work with permutations.

Functions

template<typename T , std::integral Int, size_t N>
constexpr std::array< T, N > nda::permutations::apply (std::array< Int, N > const &p, std::array< T, N > const &a)
 Apply a permutation to a std::array.
 
template<typename T , std::integral Int, size_t N>
constexpr std::array< T, N > nda::permutations::apply_inverse (std::array< Int, N > const &p, std::array< T, N > const &a)
 Apply the inverse of a permutation to a std::array.
 
template<std::integral Int, size_t N>
constexpr std::array< Int, N > nda::permutations::compose (std::array< Int, N > const &p1, std::array< Int, N > const &p2)
 Composition of two permutations.
 
template<size_t N>
constexpr std::array< int, N > nda::permutations::cycle (int p, int pos=N)
 Perform a forward (partial) cyclic permutation of the identity p times.
 
template<size_t N>
constexpr std::array< int, N > nda::decode (uint64_t binary_representation)
 Decode a uint64_t into a std::array<int, N>.
 
template<size_t N>
constexpr uint64_t nda::encode (std::array< int, N > const &a)
 Encode a std::array<int, N> in a uint64_t.
 
template<size_t N>
constexpr std::array< int, N > nda::permutations::identity ()
 Get the identity permutation.
 
template<std::integral Int, size_t N>
constexpr std::array< Int, N > nda::permutations::inverse (std::array< Int, N > const &p)
 Inverse of a permutation.
 
template<std::integral Int, size_t N>
constexpr bool nda::permutations::is_valid (std::array< Int, N > const &p)
 Check if a given array is a valid permutation.
 
template<size_t N>
constexpr std::array< int, N > nda::permutations::reverse_identity ()
 Get the reverse identity permutation.
 
template<size_t N>
constexpr std::array< int, N > nda::permutations::transposition (int i, int j)
 Get the permutation representing a single given transposition.
 

Function Documentation

◆ apply()

template<typename T , std::integral Int, size_t N>
std::array< T, N > nda::permutations::apply ( std::array< Int, N > const & p,
std::array< T, N > const & a )
constexpr

#include <nda/layout/permutation.hpp>

Apply a permutation to a std::array.

The application of a permutation p to an array a results in a new array b such that b[i] = a[p[i]].

Template Parameters
TValue type of the array.
IntIntegral type.
NSize/Degree of the array/permutation.
Parameters
pPermutation to apply.
astd::array to apply the permutation to.
Returns
Result of applying the permutation to the array.

Definition at line 186 of file permutation.hpp.

◆ apply_inverse()

template<typename T , std::integral Int, size_t N>
std::array< T, N > nda::permutations::apply_inverse ( std::array< Int, N > const & p,
std::array< T, N > const & a )
constexpr

#include <nda/layout/permutation.hpp>

Apply the inverse of a permutation to a std::array.

See also nda::permutations::apply and nda::permutations::inverse.

Template Parameters
TValue type of the array.
IntIntegral type.
NSize/Degree of the array/permutation.
Parameters
pPermutation to invert and apply.
astd::array to apply the inverse permutation to.
Returns
Result of applying the inverse permutation to the array.

Definition at line 165 of file permutation.hpp.

◆ compose()

template<std::integral Int, size_t N>
std::array< Int, N > nda::permutations::compose ( std::array< Int, N > const & p1,
std::array< Int, N > const & p2 )
constexpr

#include <nda/layout/permutation.hpp>

Composition of two permutations.

The second argument is applied first. Composition is not commutative in general, i.e. compose(p1, p2) != compose(p2, p1).

Template Parameters
IntIntegral type.
NDegree of the permutations.
Parameters
p1Permutation to apply second.
p2Permutation to apply first.
Returns
Composition of the two permutations.

Definition at line 125 of file permutation.hpp.

◆ cycle()

template<size_t N>
std::array< int, N > nda::permutations::cycle ( int p,
int pos = N )
constexpr

#include <nda/layout/permutation.hpp>

Perform a forward (partial) cyclic permutation of the identity p times.

The permutation is partial if pos >= 0 && pos < N. In this case, only the first pos elements are permuted, while the rest is left unchanged w.r.t the identity.

Template Parameters
NDegree of the permutation.
Parameters
pNumber of times to perform the cyclic permutation.
posNumber of elements to permute. If pos < N, the permutation is partial.
Returns
Result of the cyclic permutation.

Definition at line 249 of file permutation.hpp.

◆ decode()

template<size_t N>
std::array< int, N > nda::decode ( uint64_t binary_representation)
constexpr

#include <nda/layout/permutation.hpp>

Decode a uint64_t into a std::array<int, N>.

The 64-bit code is split into 4-bit chunks, and each chunk is then decoded into a value in the range [0, 15]. The 4 least significant bits are decoded into the first element, the next 4-bits into second element, and so on.

Template Parameters
NSize of the array.
Parameters
binary_representation64-bit code.
Returns
std::array<int, N> containing values in the range [0, 15].

Definition at line 54 of file permutation.hpp.

◆ encode()

template<size_t N>
uint64_t nda::encode ( std::array< int, N > const & a)
constexpr

#include <nda/layout/permutation.hpp>

Encode a std::array<int, N> in a uint64_t.

The values in the array are assumed to be in the range [0, 15]. Then each value is encoded in 4 bits, i.e. the first element is encoded in the 4 least significant bits, the second element in the next 4 bits, and so on.

Template Parameters
NSize of the array.
Parameters
astd::array<int, N> to encode.
Returns
64-bit code.

Definition at line 71 of file permutation.hpp.

◆ identity()

template<size_t N>
std::array< int, N > nda::permutations::identity ( )
constexpr

#include <nda/layout/permutation.hpp>

Get the identity permutation.

Template Parameters
NDegree of the permutation.
Returns
Identity permutation of degree N.

Definition at line 200 of file permutation.hpp.

◆ inverse()

template<std::integral Int, size_t N>
std::array< Int, N > nda::permutations::inverse ( std::array< Int, N > const & p)
constexpr

#include <nda/layout/permutation.hpp>

Inverse of a permutation.

The inverse, inv, of a permutation p is defined such that compose(p, inv) == compose(inv, p) == identity.

Template Parameters
IntIntegral type.
NDegree of the permutations.
Parameters
pPermutation to invert.
Returns
Inverse of the permutation.

Definition at line 145 of file permutation.hpp.

◆ is_valid()

template<std::integral Int, size_t N>
bool nda::permutations::is_valid ( std::array< Int, N > const & p)
constexpr

#include <nda/layout/permutation.hpp>

Check if a given array is a valid permutation.

A valid permutation is an array of integers with values in the range [0, N - 1] where each value appears exactly once.

Template Parameters
IntIntegral type.
NDegree of the permutation.
Parameters
pstd:array to check.
Returns
True if the array is a valid permutation, false otherwise.

Definition at line 103 of file permutation.hpp.

◆ reverse_identity()

template<size_t N>
std::array< int, N > nda::permutations::reverse_identity ( )
constexpr

#include <nda/layout/permutation.hpp>

Get the reverse identity permutation.

Template Parameters
NDegree of the permutation.
Returns
Reverse of the identity permutation of degree N.

Definition at line 213 of file permutation.hpp.

◆ transposition()

template<size_t N>
std::array< int, N > nda::permutations::transposition ( int i,
int j )
constexpr

#include <nda/layout/permutation.hpp>

Get the permutation representing a single given transposition.

A transposition is a permutation in which only two elements are different from the identity permutation.

Template Parameters
NDegree of the permutation.
Parameters
iFirst index to transpose.
jSecond index to transpose.
Returns
Permutation corresponding to the transposition of i and j.

Definition at line 230 of file permutation.hpp.