ezarpack/storages/nda.hpp - TRIQS/nda

This storage backend depends on TRIQS/nda version 1.1.0 or newer.

struct nda_storage

TRIQS/nda storage backend tag.

Passing this tag as the second template parameter of ezarpack::arpack_solver instructs it to use nda’s vector/matrix/view types.

template<>
struct storage_traits<nda_storage>

Traits of the nda storage backend.

Member typedefs of this structure describe types of objects that will be used by arpack_solver to store numerical arrays and expose their partial views. Structure’s static member functions are called to control arrays’ lifetime, create the partial views, and perform some data post-processing operations.

Private implementation details

template<typename T>
using vector = nda::vector<T>

nda vector.

Template Parameters:

T – Vector element type.

template<typename T>
using matrix = nda::matrix<T, nda::F_layout>

nda matrix.

Template Parameters:

T – Matrix element type.

template<typename T>
using vector_view = nda::vector_view<T>

Vector view type.

Template Parameters:

T – Vector element type.

template<typename T>
using vector_const_view = nda::vector_const_view<T>

Constant vector view type.

Template Parameters:

T – Vector element type.

template<typename T>
using matrix_view = nda::matrix_view<T, nda::F_stride_layout>

Matrix view type.

Template Parameters:

T – Matrix element type.

template<typename T>
using matrix_const_view = nda::matrix_const_view<T, nda::F_stride_layout>

Constant matrix view type.

Template Parameters:

T – Matrix element type.

Vector and matrix storage types

using real_vector_type = vector<double>

One-dimensional container owning a contiguous array of double.

using complex_vector_type = vector<dcomplex>

One-dimensional container owning a contiguous array of std::complex<double>.

using int_vector_type = vector<int>

One-dimensional container owning a contiguous array of int.

using real_matrix_type = matrix<double>

Two-dimensional container owning a contiguous array of double. The storage order is column-major.

using complex_matrix_type = matrix<dcomplex>

Two-dimensional container owning a contiguous array of std::complex<double>. The storage order is column-major.

View types

using real_vector_view_type = vector_view<double>

Contiguous partial view of a real vector (subvector).

using real_vector_const_view_type = vector_const_view<double>

Contiguous partial constant view of a real vector (subvector).

using complex_vector_view_type = vector_view<dcomplex>

Contiguous partial view of a complex vector (subvector).

using complex_vector_const_view_type = vector_const_view<dcomplex>

Contiguous partial constant view of a complex vector (subvector).

using real_matrix_const_view_type = matrix_const_view<double>

Contiguous partial constant view of a real matrix (matrix block) that includes a number of the leftmost columns.

using complex_matrix_const_view_type = matrix_const_view<dcomplex>

Contiguous partial constant view of a complex matrix (matrix block) that includes a number of the leftmost columns.

Functions to create/destroy/resize data containers

static inline real_vector_type make_real_vector(int size)

Constructs a real vector container.

Parameters:

size – Size of the vector.

Returns:

Constructed vector.

static inline complex_vector_type make_complex_vector(int size)

Constructs a complex vector container.

Parameters:

size – Size of the vector.

Returns:

Constructed vector.

static inline int_vector_type make_int_vector(int size)

Constructs an integer vector container.

Parameters:

size – Size of the vector.

Returns:

Constructed vector.

static inline real_matrix_type make_real_matrix(int rows, int cols)

Constructs a real matrix container.

Parameters:
  • rows – Number of matrix rows.

  • cols – Number of matrix columns.

Returns:

Constructed matrix.

static inline complex_matrix_type make_complex_matrix(int rows, int cols)

Constructs a complex matrix container.

Parameters:
  • rows – Number of matrix rows.

  • cols – Number of matrix columns.

Returns:

Constructed matrix.

template<typename T>
static inline void destroy(vector<T>&)

Destroys a vector container. This function is, in fact, no-op, because memory owned by a nda vector will automatically be freed by its destructor.

Template Parameters:

T – Vector element type.

template<typename T>
static inline void destroy(matrix<T>&)

Destroys a matrix container. This function is, in fact, no-op, because memory owned by a nda matrix will automatically be freed by its destructor.

Template Parameters:

T – Matrix element type.

template<typename T>
static inline void resize(vector<T> &v, int size)

Resizes a vector container.

Template Parameters:

T – Vector element type.

Parameters:
  • v – Vector container to resize.

  • size – New vector size.

template<typename T>
static inline void resize(matrix<T> &m, int rows, int cols)

Resizes a matrix container.

Template Parameters:

T – Matrix element type.

Parameters:
  • m – Matrix container to resize.

  • rows – New number of matrix rows.

  • cols – New number of matrix columns.

Access to underlying memory buffers

template<typename T>
static inline T *get_data_ptr(vector<T> &v)

Returns a pointer to the underlying data array owned by a vector.

Template Parameters:

T – Vector element type.

Parameters:

v – Vector to retrieve the data pointer from.

Returns:

Pointer to the data array.

template<typename T>
static inline T *get_data_ptr(matrix<T> &m)

Returns a pointer to the underlying data array owned by a matrix.

Template Parameters:

T – Matrix element type.

Parameters:

m – Matrix to retrieve the data pointer from.

Returns:

Pointer to the data array.

template<typename T>
static inline int get_col_spacing(matrix<T> const &m)

Returns the spacing between the beginning of two columns of a matrix.

The spacing can be different from the number of matrix rows if padding elements are added to the stored data array. Returning a negative value signals that the spacing equals the number of rows.

Template Parameters:

T – Matrix element type.

Parameters:

m – Matrix to retrieve the spacing from.

Returns:

Column spacing.

Functions to create vector/matrix views

template<typename T>
static inline vector_view<T> make_vector_view(vector<T> &v)

Makes a complete view of a vector.

Template Parameters:

T – Vector element type.

Parameters:

v – Vector container to make a view of.

Returns:

View of the full vector.

template<typename T>
static inline vector_view<T> make_vector_view(vector<T> &v, int start, int size)

Makes a partial view of a vector.

Template Parameters:

T – Vector element type.

Parameters:
  • v – Vector container to make a view of.

  • start – Position of the starting element in the partial view.

  • size – Number of elements in the partial view.

Returns:

Subvector view.

template<typename T>
static inline vector_const_view<T> make_vector_const_view(vector<T> const &v, int start, int size)

Makes a constant partial view of a vector.

Template Parameters:

T – Vector element type.

Parameters:
  • v – Vector container to make a view of.

  • start – Position of the starting element in the partial view.

  • size – Number of elements in the partial view.

Returns:

Subvector view.

template<typename T>
static inline matrix_const_view<T> make_matrix_const_view(matrix<T> const &m)

Makes a complete view of a matrix.

Template Parameters:

T – Matrix element type.

Parameters:

m – Matrix container to make a view of.

Returns:

View of the full matrix.

template<typename T>
static inline matrix_const_view<T> make_matrix_const_view(matrix<T> const &m, int rows, int cols)

Makes a constant partial view of a matrix including a number of the leftmost columns.

Template Parameters:

T – Matrix element type.

Parameters:
  • m – Matrix container to make a view of.

  • rows[ignored] Number of matrix rows.

  • cols – Number of the leftmost columns in the resulting view.

Returns:

Submatrix view.

Post-processing required to compute eigenvalues/eigenvectors

static inline complex_vector_type make_asymm_eigenvalues(real_vector_type const &dr, real_vector_type const &di, int nconv)

Combines real and imaginary parts of eigenvalues computed by ezarpack::arpack_solver<Asymmetric, Backend>.

Parameters:
  • dr – Real parts of the computed eigenvalues.

  • di – Imaginary parts of the computed eigenvalues.

  • nconv – Number of the converged eigenvalues.

Returns:

Complex vector of eigenvalues.

template<typename A>
static inline complex_vector_type make_asymm_eigenvalues(real_vector_type const &z, real_vector_type const &di, A &&a, int N, int nconv)

Given a linear operator \( \hat A \), computes nconv eigenvalues from Ritz vectors \( \mathbf{x} \) as Rayleigh quotients \( \frac{\mathbf{x}^\dagger \hat A \mathbf{x}} {\mathbf{x}^\dagger \hat M \mathbf{x}} \). This function is called by ezarpack::arpack_solver<Asymmetric, Backend>::eigenvalues(A &&) const.

Template Parameters:

A – Type of the callable object representing the linear operator \( \hat A \).

Parameters:
  • z – Holds components of the Ritz vectors \( \mathbf{x} \) as a sequence of nconv length-N chunks. Meaning of each chunk depends on the corresponding component of di, see below.

  • di – If di[i] is zero, then the i-th chunk of z contains a real Ritz vector. Otherwise, di[i] = -di[i+1] != 0, in which case the i-th and (i+1)-th chunks of z are real and imaginary parts of a complex Ritz vector respectively. Every real Ritz vector corresponds to one real eigenvalue, while every complex vector gives rise to a complex conjugate pair of eigenvalues.

  • a – Callable object representing \( \hat A \).

  • N – Dimension of the eigenproblem.

  • nconv – Number of the converged Ritz vectors.

Returns:

Complex vector of eigenvalues.

static inline complex_matrix_type make_asymm_eigenvectors(real_vector_type const &z, real_vector_type const &di, int N, int nconv)

Extracts nconv complex Ritz vectors from ARPACK-NG’s internal representation. This function is called by ezarpack::arpack_solver<Asymmetric, Backend>::eigenvectors() const.

Parameters:
  • z – Holds components of the Ritz vectors \( \mathbf{x} \) as a sequence of nconv length-N chunks. Meaning of each chunk depends on the corresponding component of di, see below.

  • di – If di[i] is zero, then the i-th chunk of z contains a real Ritz vector. Otherwise, di[i] = -di[i+1] != 0, in which case the i-th and (i+1)-th chunks of z are real and imaginary parts of a complex Ritz vector respectively. Every such pair corresponds to a complex conjugate pair of Ritz vectors, so that the total amount of vectors stored in z is exactly nconv.

  • N – Dimension of the eigenproblem.

  • nconv – Number of the converged Ritz vectors.

Returns:

Complex matrix, whose columns are Ritz vectors (eigenvectors).