51#ifndef __ADS_interop_eigen_Eigen
52 #define __ADS_interop_eigen_Eigen
59#if ! __has_include( <Eigen/SparseCore> )
60 #error "the interoperation with Eigen needs the headers of Eigen"
68#include <Eigen/SparseCore>
93 Eigen::Matrix< T , Eigen::Dynamic , Eigen::Dynamic , Eigen::RowMajor >;
96template<
class T ,
class I =
int >
97using RowSparse = Eigen::SparseMatrix< T , Eigen::RowMajor , I >;
107 return( Eigen::Map<
RowMatrix< T > >( A.data() , Eigen::Index( A.rows() ) ,
108 Eigen::Index( A.cols() ) ) );
114[[nodiscard]] Eigen::Map< const RowMatrix< T > >
118 A.data() , Eigen::Index( A.rows() ) , Eigen::Index( A.cols() ) ) );
124template<
class T , std::
signed_
integral I >
125[[nodiscard]] Eigen::Map< const RowSparse< T , I > >
129 Eigen::Index( A.rows() ) , Eigen::Index( A.cols() ) ,
130 Eigen::Index( A.nonzeros() ) , A.rowStart() , A.columns() , A.values() ) );
141template<
class S =
int ,
class T ,
class I ,
class P >
145 ADS_PRE( ( A.rows() <= std::size_t( std::numeric_limits< S >::max() ) ) &&
146 ( A.cols() <= std::size_t( std::numeric_limits< S >::max() ) ) &&
147 ( A.nonzeros() <= std::size_t( std::numeric_limits< S >::max() ) ) );
149 E.resizeNonZeros( Eigen::Index( A.nonzeros() ) );
150 std::transform( A.rowStart() , A.rowStart() + A.rows() + 1 ,
152 []( P p ) { return( S( p ) ); } );
153 std::transform( A.columns() , A.columns() + A.nonzeros() , E.innerIndexPtr() ,
154 []( I j ) { return( S( j ) ); } );
155 std::copy( A.values() , A.values() + A.nonzeros() , E.valuePtr() );
162template<
class I = std::u
int32_t ,
class P = detail::CsrOffset< I > ,
167 using T =
typename D::Scalar;
169 std::vector< typename BasicCsrMatrix< T , I , P >::Triplet > E;
170 E.reserve( std::size_t( R.nonZeros() ) );
171 for( Eigen::Index i = 0 ; i < R.outerSize() ; ++i )
175 E.emplace_back( std::size_t( it.row() ) , std::size_t( it.col() ) ,
178 std::size_t( R.rows() ) , std::size_t( R.cols() ) , std::move( E ) ) );
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A sparse matrix in compressed sparse rows (CSR), beyond the book: the nonzeros of each row,...
The dense matrices by rows, beyond the book: DenseMatrix keeps the entries by rows in one contiguous...
a sparse matrix of values T in compressed sparse rows, the columns of the type I and the offsets of ...
Definition CsrMatrix.h:129
an matrix by rows in one contiguous vector
Definition DenseMatrix.h:187
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
RowSparse< T, S > toEigen(const BasicCsrMatrix< T, I, P > &A)
copied into a sparse matrix of Eigen by rows of the index type S, in time, for the layouts that map(...
Definition Eigen.h:143
Eigen::Map< RowMatrix< T > > map(DenseMatrix< T > &A)
the entries of as a dense matrix of Eigen, with no copy
Definition Eigen.h:105
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > RowMatrix
a dense matrix of Eigen by rows, the layout of DenseMatrix
Definition Eigen.h:92
BasicCsrMatrix< typename D::Scalar, I, P > fromEigen(const Eigen::SparseMatrixBase< D > &S)
the sparse expression of Eigen copied into a BasicCsrMatrix of the columns I and the offsets P,...
Definition Eigen.h:165
Eigen::SparseMatrix< T, Eigen::RowMajor, I > RowSparse
a sparse matrix of Eigen by rows, of the index type I
Definition Eigen.h:97