ezarpack/storages/eigen.hpp
- Eigen 3¶
This storage backend depends on Eigen version 3.3 or newer.
-
struct eigen_storage¶
Eigen 3 storage backend tag.
Passing this tag as the second template parameter of ezarpack::arpack_solver instructs it to use Eigen’s vector/matrix/view types.
-
template<>
struct storage_traits<eigen_storage>¶ Traits of the Eigen 3 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 = Eigen::Matrix<T, Eigen::Dynamic, 1>¶ Eigen vector (matrix with one column and a dynamic number of rows).
- Template Parameters:
T – Vector element type.
-
template<typename T>
using matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>¶ Dynamic Eigen matrix.
- Template Parameters:
T – Matrix element type.
-
template<typename T>
using vector_view = Eigen::VectorBlock<vector<T>, Eigen::Dynamic>¶ Vector view type (block of a vector).
- Template Parameters:
T – Vector element type.
-
template<typename T>
using vector_const_view = Eigen::VectorBlock<const vector<T>, Eigen::Dynamic>¶ Constant vector view type (block of a constant vector).
- Template Parameters:
T – Vector 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>
.
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 an Eigen 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 an Eigen matrix will automatically be freed by its destructor.
- Template Parameters:
T – Matrix element type.
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 ofdi
, see below.di – If
di[i]
is zero, then thei
-th chunk ofz
contains a real Ritz vector. Otherwise,di[i] = -di[i+1] != 0
, in which case thei
-th and(i+1)
-th chunks ofz
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 ofdi
, see below.di – If
di[i]
is zero, then thei
-th chunk ofz
contains a real Ritz vector. Otherwise,di[i] = -di[i+1] != 0
, in which case thei
-th and(i+1)
-th chunks ofz
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 inz
is exactlynconv
.N – Dimension of the eigenproblem.
nconv – Number of the converged Ritz vectors.
- Returns:
Complex matrix, whose columns are Ritz vectors (eigenvectors).
-
template<typename T>