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

Detailed Description

Tools to use and detect symmetries in nda::Array objects.

Here is a simple example of how symmetries can be used in nda:

#include <nda/nda.hpp>
#include <nda/sym_grp.hpp>
#include <array>
#include <complex>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <tuple>
#include <vector>
int main() {
constexpr int N = 3;
// typedefs for the symmetry group
using idx_t = std::array<long, 2>;
using sym_t = std::tuple<idx_t, nda::operation>;
using sym_func_t = std::function<sym_t(idx_t const &)>;
// create an hermitian matrix
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) A(i, j) = std::conj(A(j, i));
}
// hermitian symmetry (satisfies nda::NdaSymmetry)
auto h_symmetry = [](idx_t const &x) {
idx_t xp = {x[1], x[0]};
return sym_t{xp, nda::operation{false, true}}; // sign flip = false, complex conjugate = true
};
// construct the symmetry group
auto grp = nda::sym_grp{A, std::vector<sym_func_t>{h_symmetry}};
// create an initializer function (satisfies nda::NdaInitFunc)
auto init_func = [&A](idx_t const &x) { return std::apply(A, x); };
// initialize a second array using the symmetry group and array A
grp.init(B, init_func);
// output A and B
std::cout << A << std::endl;
std::cout << B << std::endl;
// get representative dat (should be a vector of size 6)
auto vec = grp.get_representative_data(A);
std::cout << "\n" << nda::array_view<std::complex<double>, 1>(vec) << std::endl;
}
A generic view of a multi-dimensional array.
A generic multi-dimensional array.
Class representing a symmetry group.
Definition sym_grp.hpp:145
auto rand(std::array< Int, Rank > const &shape)
Make an array of the given shape and initialize it with random values from the uniform distribution o...
Includes all relevant headers for the core nda library.
A structure to capture combinations of complex conjugation and sign flip operations.
Definition sym_grp.hpp:47
Provides tools to use symmetries with nda objects.

Output:

A:
[[(0.79407,0.479187),(0.0316266,-0.885449),(0.620883,-0.589129)]
[(0.0316266,0.885449),(0.431919,0.784867),(0.25658,-0.197428)]
[(0.620883,0.589129),(0.25658,0.197428),(0.972195,0.354817)]]
B:
[[(0.79407,0.479187),(0.0316266,-0.885449),(0.620883,-0.589129)]
[(0.0316266,0.885449),(0.431919,0.784867),(0.25658,-0.197428)]
[(0.620883,0.589129),(0.25658,0.197428),(0.972195,0.354817)]]
Representative data:
[(0.79407,0.479187),(0.0316266,-0.885449),(0.620883,-0.589129),(0.431919,0.784867),(0.25658,-0.197428),(0.972195,0.354817)]

It first creates a hermitian matrix A and uses the symmetry h_symmetry, i.e. A(i, j) = std::conj(A(j, i)), to construct the corresponding symmetry group. The symmetry group can then be used to initialize other arrays, get the representative data of an array with the same symmetry and more.

Concepts

concept  nda::NdaSymmetry
 Concept defining a symmetry in nda.
 
concept  nda::NdaInitFunc
 Concept defining an initializer function.
 

Classes

struct  nda::operation
 A structure to capture combinations of complex conjugation and sign flip operations. More...
 
class  nda::sym_grp< F, A >
 Class representing a symmetry group. More...
 

Functions

template<Array A>
bool nda::is_valid (A const &a, std::array< long, static_cast< std::size_t >(get_rank< A >)> const &idx)
 Check if a multi-dimensional index is valid, i.e. not out of bounds, w.r.t. to a given nda::Array object.
 

Function Documentation

◆ is_valid()

template<Array A>
bool nda::is_valid ( A const & a,
std::array< long, static_cast< std::size_t >(get_rank< A >)> const & idx )

#include <nda/sym_grp.hpp>

Check if a multi-dimensional index is valid, i.e. not out of bounds, w.r.t. to a given nda::Array object.

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
idxMulti-dimensional index.
Returns
True if the index is not out of bounds, false otherwise.

Definition at line 88 of file sym_grp.hpp.