ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Eigen.h File Reference

The matrices of ADS as matrices of Eigen (https://eigen.tuxfamily.org), so that the solvers, the decompositions and the products of Eigen run on them, beyond the book: More...

#include "ADS/Contract.h"
#include "ADS/numeric/CsrMatrix.h"
#include "ADS/numeric/DenseMatrix.h"
#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  ADS
namespace  ADS::eigen

Typedefs

template<class T>
using ADS::eigen::RowMatrix
 a dense matrix of Eigen by rows, the layout of DenseMatrix
template<class T, class I = int>
using ADS::eigen::RowSparse = Eigen::SparseMatrix< T , Eigen::RowMajor , I >
 a sparse matrix of Eigen by rows, of the index type I

Functions

template<class T>
Eigen::Map< RowMatrix< T > > ADS::eigen::map (DenseMatrix< T > &A)
 the entries of \( A \) as a dense matrix of Eigen, with no copy
template<class T>
Eigen::Map< const RowMatrix< T > > ADS::eigen::map (const DenseMatrix< T > &A)
 the entries of a constant \( A \) as a dense matrix of Eigen, with no copy
template<class T, std::signed_integral I>
Eigen::Map< const RowSparse< T, I > > ADS::eigen::map (const BasicCsrMatrix< T, I, I > &A)
 \( A \) as a sparse matrix of Eigen by rows, its offsets, columns and values read in place: the columns and the offsets of one signed type, the StorageIndex of Eigen
template<class S = int, class T, class I, class P>
RowSparse< T, S > ADS::eigen::toEigen (const BasicCsrMatrix< T, I, P > &A)
 \( A \) copied into a sparse matrix of Eigen by rows of the index type S, in \( O( m + \mathit{nnz} ) \) time, for the layouts that map() does not take
template<class I = std::uint32_t, class P = detail::CsrOffset< I >, class D>
BasicCsrMatrix< typename D::Scalar, I, P > ADS::eigen::fromEigen (const Eigen::SparseMatrixBase< D > &S)
 the sparse expression \( S \) of Eigen copied into a BasicCsrMatrix of the columns I and the offsets P, by its triplets

Detailed description

The matrices of ADS as matrices of Eigen (https://eigen.tuxfamily.org), so that the solvers, the decompositions and the products of Eigen run on them, beyond the book:

  • map( A ) of a DenseMatrix< T > is an Eigen::Map of a row-major dense matrix over its entries, with no copy, writable if \( A \) is;
  • map( A ) of a BasicCsrMatrix< T , I , I > whose columns and offsets have the same signed type I (e.g., BasicCsrMatrix< double , int >) is an Eigen::Map of a row-major Eigen::SparseMatrix< T , Eigen::RowMajor , I > over its three arrays, with no copy, since these are the compressed arrays of Eigen (which requires one signed type for both, its StorageIndex);
  • toEigen( A ) copies a BasicCsrMatrix of any types into an Eigen::SparseMatrix< T , Eigen::RowMajor , S >, the arrays copied one by one in \( O( m + \mathit{nnz} ) \) time, which the default CsrMatrix (32-bit unsigned columns and std::size_t offsets) needs, as its layout is not one of Eigen;
  • fromEigen( S ) copies a sparse expression of Eigen into a BasicCsrMatrix, through its triplets.

Eigen has its own sparse and dense matrices, and ADS does not replace them: a program that keeps its data in the structures of ADS calls Eigen on them through these views, and the copies are only for the layouts that Eigen cannot read.

This header is of the set interop: no entry point of ADS includes it, and it needs the headers of Eigen (3.4 or later), found by CMake when ADS_WITH_EIGEN is AUTO or ON (the target ADS::Eigen). The contracts [see Contract.h]: a map does not outlive its matrix, nor sees a matrix that changes its size; the indices of a copy fit its type.

See also
G. Guennebaud, B. Jacob, et al., Eigen v3, 2010, https://eigen.tuxfamily.org
Y. Saad, Iterative Methods for Sparse Linear Systems, 2nd ed., SIAM, 2003, section 3.4
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa