Tools to use and detect symmetries in nda::Array objects.
Here is a simple example of how symmetries can be used in nda:
#include <array>
#include <complex>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <tuple>
#include <vector>
int main() {
constexpr int N = 3;
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 &)>;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) A(i, j) = std::conj(A(j, i));
}
auto h_symmetry = [](idx_t const &x) {
idx_t xp = {x[1], x[0]};
return sym_t{xp, nda::operation{false, true}};
};
auto grp = nda::sym_grp{A, std::vector<sym_func_t>{h_symmetry}};
auto init_func = [&A](idx_t const &x) { return std::apply(A, x); };
grp.init(B, init_func);
std::cout << A << std::endl;
std::cout << B << std::endl;
auto vec = grp.get_representative_data(A);
}
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...
basic_array_view< ValueType, Rank, Layout, 'A', default_accessor, borrowed<> > array_view
Alias template of an nda::basic_array_view with an 'A' algebra, nda::default_accessor and nda::borrow...
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
Includes all relevant headers for the core nda library.
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.
|
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.
|
|
◆ 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
-
- Parameters
-
- Returns
- True if the index is not out of bounds, false otherwise.
Definition at line 88 of file sym_grp.hpp.