8 #ifndef OPENFPM_DATA_SRC_SPACE_EMATRIX_HPP_ 
    9 #define OPENFPM_DATA_SRC_SPACE_EMATRIX_HPP_ 
   14 #include <Eigen/Dense> 
   15 #include "memory/ExtPreAlloc.hpp" 
   16 #include "memory/HeapMemory.hpp" 
   17 #include "Packer_Unpacker/Packer_util.hpp" 
   18 #include "Packer_Unpacker/Packer.hpp" 
   19 #include "Packer_Unpacker/Unpacker.hpp" 
   21 template<
typename _Scalar, 
int _Rows, 
int _Cols,
 
   22          int _Options = Eigen::AutoAlign |
 
   23 #if EIGEN_GNUC_AT(3,4) 
   29                           ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor
 
   30                           : !(_Cols==1 && _Rows!=1) ?  EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION
 
   33                           ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor
 
   34                           : (_Cols==1 && _Rows!=1) ? Eigen::ColMajor
 
   35                           : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
 
   44 template<
typename _Scalar, 
int _Rows, 
int _Cols, 
int _Options, 
int _MaxRows, 
int _MaxCols>
 
   45 struct traits<EMatrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
 
   48   enum { size = internal::size_at_compile_time<_Rows,_Cols>::ret };
 
   49   typedef typename find_best_packet<_Scalar,size>::type PacketScalar;
 
   51       row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
 
   52       is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
 
   53       max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
 
   54       default_alignment = compute_default_alignment<_Scalar,max_size>::value,
 
   55       actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
 
   56       required_alignment = unpacket_traits<PacketScalar>::alignment,
 
   57       packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
 
   61   typedef _Scalar Scalar;
 
   62   typedef Dense StorageKind;
 
   63   typedef Eigen::Index StorageIndex;
 
   64   typedef MatrixXpr XprKind;
 
   66     RowsAtCompileTime = _Rows,
 
   67     ColsAtCompileTime = _Cols,
 
   68     MaxRowsAtCompileTime = _MaxRows,
 
   69     MaxColsAtCompileTime = _MaxCols,
 
   70     Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
 
   72     InnerStrideAtCompileTime = 1,
 
   73     OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
 
   76     EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
 
   77     Alignment = actual_alignment
 
   87 template<
typename _Scalar, 
int _Rows, 
int _Cols, 
int _Options, 
int _MaxRows, 
int _MaxCols>
 
   88 class EMatrix : 
public Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>
 
   91     typedef typename Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>::Base Base;
 
   97     EIGEN_DENSE_PUBLIC_INTERFACE(EMatrix)
 
  106     template<
int ... prp> inline 
void packRequest(
size_t & req)
 const 
  109         req += 
sizeof(_Scalar)*this->rows()*this->cols() + 2*
sizeof(_Scalar);
 
  125         mem.
allocate(
sizeof(_Scalar)*this->rows()*this->cols());
 
  127         void * src = (
void *)this->data();
 
  129         memcpy(dst,src,
sizeof(_Scalar)*this->rows()*this->cols());
 
  147         this->resize(row,col);
 
  149         void * dst = this->data();
 
  152         memcpy(dst,src,
sizeof(_Scalar)*row*col);
 
  170     EIGEN_STRONG_INLINE EMatrix()
 
  171     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>()
 
  183     EIGEN_STRONG_INLINE EMatrix& operator=(
const Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>& other)
 
  185         ((Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> *)
this)->operator=(other);
 
  199     template<
typename OtherDerived>
 
  201     EIGEN_STRONG_INLINE EMatrix& operator=(
const Eigen::DenseBase<OtherDerived>& other)
 
  203         ((Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> *)
this)->operator=(other);
 
  211     template<
typename OtherDerived>
 
  213     EIGEN_STRONG_INLINE EMatrix& operator=(
const Eigen::EigenBase<OtherDerived> &other)
 
  215         ((Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> *)
this)->operator=(other);
 
  219     template<
typename OtherDerived>
 
  221     EIGEN_STRONG_INLINE EMatrix& operator=(
const Eigen::ReturnByValue<OtherDerived>& func)
 
  223         ((Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> *)
this)->operator=(func);
 
  227 #if EIGEN_HAS_RVALUE_REFERENCES 
  229     EMatrix(Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> && other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
 
  230     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(other)
 
  234     EMatrix& operator=(Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> && other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
 
  239     #ifndef EIGEN_PARSED_BY_DOXYGEN 
  244     EIGEN_STRONG_INLINE 
explicit EMatrix(
const T& x)
 
  245     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(x)
 
  248     template<
typename T0, 
typename T1>
 
  250     EIGEN_STRONG_INLINE EMatrix(
const T0& x, 
const T1& y)
 
  251     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(x,y)
 
  257     explicit EMatrix(
const Scalar *data)
 
  258     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(data)
 
  273     EIGEN_STRONG_INLINE 
explicit EMatrix(Index dim)
 
  274     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(dim)
 
  278     EMatrix(
const Scalar& x)
 
  279     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(x)
 
  294     EMatrix(Index rows, Index cols)
 
  295     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(rows,cols)
 
  299     EMatrix(
const Scalar& x, 
const Scalar& y)
 
  300     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(x,y)
 
  306     EIGEN_STRONG_INLINE EMatrix(
const Scalar& x, 
const Scalar& y, 
const Scalar& z)
 
  307     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(x,y,z)
 
  312     EIGEN_STRONG_INLINE EMatrix(
const Scalar& x, 
const Scalar& y, 
const Scalar& z, 
const Scalar& w)
 
  313     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(x,y,z,w)
 
  319     EIGEN_STRONG_INLINE EMatrix(
const Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> & other)
 
  320     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(other)
 
  326     template<
typename OtherDerived>
 
  328     EIGEN_STRONG_INLINE EMatrix(
const Eigen::EigenBase<OtherDerived> &other)
 
  329     :Eigen::
Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>(other)
 
  334 typedef EMatrix< std::complex< double >, 2, 2 >     EMatrix2cd;
 
  335 typedef EMatrix< std::complex< float >, 2, 2 >  EMatrix2cf;
 
  336 typedef EMatrix< double, 2, 2 >     EMatrix2d;
 
  337 typedef EMatrix< float, 2, 2 >  EMatrix2f;
 
  338 typedef EMatrix< int, 2, 2 >    EMatrix2i;
 
  339 typedef EMatrix< std::complex< double >, 2, Eigen::Dynamic >    EMatrix2Xcd;
 
  340 typedef EMatrix< std::complex< float >, 2, Eigen::Dynamic >     EMatrix2Xcf;
 
  341 typedef EMatrix< double, 2, Eigen::Dynamic >    EMatrix2Xd;
 
  342 typedef EMatrix< float, 2, Eigen::Dynamic >     EMatrix2Xf;
 
  343 typedef EMatrix< int, 2, Eigen::Dynamic >   EMatrix2Xi;
 
  344 typedef EMatrix< std::complex< double >, 3, 3 >     EMatrix3cd;
 
  345 typedef EMatrix< std::complex< float >, 3, 3 >  EMatrix3cf;
 
  346 typedef EMatrix< double, 3, 3 >     EMatrix3d;
 
  347 typedef EMatrix< float, 3, 3 >  EMatrix3f;
 
  348 typedef EMatrix< int, 3, 3 >    EMatrix3i;
 
  349 typedef EMatrix< std::complex< double >, 3, Eigen::Dynamic >    EMatrix3Xcd;
 
  350 typedef EMatrix< std::complex< float >, 3, Eigen::Dynamic >     EMatrix3Xcf;
 
  351 typedef EMatrix< double, 3, Eigen::Dynamic >    EMatrix3Xd;
 
  352 typedef EMatrix< float, 3, Eigen::Dynamic >     EMatrix3Xf;
 
  353 typedef EMatrix< int, 3, Eigen::Dynamic >   EMatrix3Xi;
 
  354 typedef EMatrix< std::complex< double >, 4, 4 >     EMatrix4cd;
 
  355 typedef EMatrix< std::complex< float >, 4, 4 >  EMatrix4cf;
 
  356 typedef EMatrix< double, 4, 4 >     EMatrix4d;
 
  357 typedef EMatrix< float, 4, 4 >  EMatrix4f;
 
  358 typedef EMatrix< int, 4, 4 >    EMatrix4i;
 
  359 typedef EMatrix< std::complex< double >, 4, Eigen::Dynamic >    EMatrix4Xcd;
 
  360 typedef EMatrix< std::complex< float >, 4, Eigen::Dynamic >     EMatrix4Xcf;
 
  361 typedef EMatrix< double, 4, Eigen::Dynamic >    EMatrix4Xd;
 
  362 typedef EMatrix< float, 4, Eigen::Dynamic >     EMatrix4Xf;
 
  363 typedef EMatrix< int, 4, Eigen::Dynamic >   EMatrix4Xi;
 
  364 typedef EMatrix< std::complex< double >, Eigen::Dynamic, 2 >    EMatrixX2cd;
 
  365 typedef EMatrix< std::complex< float >, Eigen::Dynamic, 2 >     EMatrixX2cf;
 
  366 typedef EMatrix< double, Eigen::Dynamic, 2 >    EMatrixX2d;
 
  367 typedef EMatrix< float, Eigen::Dynamic, 2 >     EMatrixX2f;
 
  368 typedef EMatrix< int, Eigen::Dynamic, 2 >   EMatrixX2i;
 
  369 typedef EMatrix< std::complex< double >, Eigen::Dynamic, 3 >    EMatrixX3cd;
 
  370 typedef EMatrix< std::complex< float >, Eigen::Dynamic, 3 >     EMatrixX3cf;
 
  371 typedef EMatrix< double, Eigen::Dynamic, 3 >    EMatrixX3d;
 
  372 typedef EMatrix< float, Eigen::Dynamic, 3 >     EMatrixX3f;
 
  373 typedef EMatrix< int, Eigen::Dynamic, 3 >   EMatrixX3i;
 
  374 typedef EMatrix< std::complex< double >, Eigen::Dynamic, 4 >    EMatrixX4cd;
 
  375 typedef EMatrix< std::complex< float >, Eigen::Dynamic, 4 >     EMatrixX4cf;
 
  376 typedef EMatrix< double, Eigen::Dynamic, 4 >    EMatrixX4d;
 
  377 typedef EMatrix< float, Eigen::Dynamic, 4 >     EMatrixX4f;
 
  378 typedef EMatrix< int, Eigen::Dynamic, 4 >   EMatrixX4i;
 
  379 typedef EMatrix< std::complex< double >, Eigen::Dynamic, Eigen::Dynamic >   EMatrixXcd;
 
  380 typedef EMatrix< std::complex< float >, Eigen::Dynamic, Eigen::Dynamic >    EMatrixXcf;
 
  381 typedef EMatrix< double, Eigen::Dynamic, Eigen::Dynamic >   EMatrixXd;
 
  382 typedef EMatrix< float, Eigen::Dynamic, Eigen::Dynamic >    EMatrixXf;
 
  383 typedef EMatrix< int, Eigen::Dynamic, Eigen::Dynamic >  EMatrixXi;
 
  384 typedef EMatrix< std::complex< double >, 1, 2 >     ERowVector2cd;
 
  385 typedef EMatrix< std::complex< float >, 1, 2 >  ERowVector2cf;
 
  386 typedef EMatrix< double, 1, 2 >     ERowVector2d;
 
  387 typedef EMatrix< float, 1, 2 >  ERowVector2f;
 
  388 typedef EMatrix< int, 1, 2 >    ERowVector2i;
 
  389 typedef EMatrix< std::complex< double >, 1, 3 >     ERowVector3cd;
 
  390 typedef EMatrix< std::complex< float >, 1, 3 >  ERowVector3cf;
 
  391 typedef EMatrix< double, 1, 3 >     ERowVector3d;
 
  392 typedef EMatrix< float, 1, 3 >  ERowVector3f;
 
  393 typedef EMatrix< int, 1, 3 >    ERowVector3i;
 
  394 typedef EMatrix< std::complex< double >, 1, 4 >     ERowVector4cd;
 
  395 typedef EMatrix< std::complex< float >, 1, 4 >  ERowVector4cf;
 
  396 typedef EMatrix< double, 1, 4 >     ERowVector4d;
 
  397 typedef EMatrix< float, 1, 4 >  ERowVector4f;
 
  398 typedef EMatrix< int, 1, 4 >    ERowVector4i;
 
  399 typedef EMatrix< std::complex< double >, 1, Eigen::Dynamic >    ERowVectorXcd;
 
  400 typedef EMatrix< std::complex< float >, 1, Eigen::Dynamic >     ERowVectorXcf;
 
  401 typedef EMatrix< double, 1, Eigen::Dynamic >    ERowVectorXd;
 
  402 typedef EMatrix< float, 1, Eigen::Dynamic >     ERowVectorXf;
 
  403 typedef EMatrix< int, 1, Eigen::Dynamic >   ERowVectorXi;
 
  404 typedef EMatrix< std::complex< double >, 2, 1 >     EVector2cd;
 
  405 typedef EMatrix< std::complex< float >, 2, 1 >  EVector2cf;
 
  406 typedef EMatrix< double, 2, 1 >     EVector2d;
 
  407 typedef EMatrix< float, 2, 1 >  EVector2f;
 
  408 typedef EMatrix< int, 2, 1 >    EVector2i;
 
  409 typedef EMatrix< std::complex< double >, 3, 1 >     EVector3cd;
 
  410 typedef EMatrix< std::complex< float >, 3, 1 >  EVector3cf;
 
  411 typedef EMatrix< double, 3, 1 >     EVector3d;
 
  412 typedef EMatrix< float, 3, 1 >  EVector3f;
 
  413 typedef EMatrix< int, 3, 1 >    EVector3i;
 
  414 typedef EMatrix< std::complex< double >, 4, 1 >     EVector4cd;
 
  415 typedef EMatrix< std::complex< float >, 4, 1 >  EVector4cf;
 
  416 typedef EMatrix< double, 4, 1 >     EVector4d;
 
  417 typedef EMatrix< float, 4, 1 >  EVector4f;
 
  418 typedef EMatrix< int, 4, 1 >    EVector4i;
 
  419 typedef EMatrix< std::complex< double >, Eigen::Dynamic, 1 >    EVectorXcd;
 
  420 typedef EMatrix< std::complex< float >, Eigen::Dynamic, 1 >     EVectorXcf;
 
  421 typedef EMatrix< double, Eigen::Dynamic, 1 >    EVectorXd;
 
  422 typedef EMatrix< float, Eigen::Dynamic, 1 >     EVectorXf;
 
  423 typedef EMatrix< int, Eigen::Dynamic, 1 >   EVectorXi;
 
size_t getOffset()
Return the actual counter. 
 
virtual void * getPointer()
Return the pointer of the last allocation. 
 
virtual bool allocate(size_t sz)
Allocate a chunk of memory. 
 
void incReq()
Increment the request pointer. 
 
void * getPointerOffset(size_t offset)
Get the base memory pointer increased with an offset. 
 
This class implement an NxN (dense) matrix. 
 
void addOffset(size_t off)
Increment the offset pointer by off. 
 
static void unpack(ExtPreAlloc< Mem >, T &obj)
Error, no implementation. 
 
static void pack(ExtPreAlloc< Mem >, const T &obj)
Error, no implementation.