8#ifndef OPENFPM_DATA_SRC_SPACE_EMATRIX_HPP_
9#define OPENFPM_DATA_SRC_SPACE_EMATRIX_HPP_
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"
21template<
typename _Scalar,
int _Rows,
int _Cols,
22 int _Options = Eigen::AutoAlign |
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 ),
44template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
45struct 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
87template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
88class 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)
334typedef EMatrix< std::complex< double >, 2, 2 > EMatrix2cd;
335typedef EMatrix< std::complex< float >, 2, 2 > EMatrix2cf;
336typedef EMatrix< double, 2, 2 > EMatrix2d;
337typedef EMatrix< float, 2, 2 > EMatrix2f;
338typedef EMatrix< int, 2, 2 > EMatrix2i;
339typedef EMatrix< std::complex< double >, 2, Eigen::Dynamic > EMatrix2Xcd;
340typedef EMatrix< std::complex< float >, 2, Eigen::Dynamic > EMatrix2Xcf;
341typedef EMatrix< double, 2, Eigen::Dynamic > EMatrix2Xd;
342typedef EMatrix< float, 2, Eigen::Dynamic > EMatrix2Xf;
343typedef EMatrix< int, 2, Eigen::Dynamic > EMatrix2Xi;
344typedef EMatrix< std::complex< double >, 3, 3 > EMatrix3cd;
345typedef EMatrix< std::complex< float >, 3, 3 > EMatrix3cf;
346typedef EMatrix< double, 3, 3 > EMatrix3d;
347typedef EMatrix< float, 3, 3 > EMatrix3f;
348typedef EMatrix< int, 3, 3 > EMatrix3i;
349typedef EMatrix< std::complex< double >, 3, Eigen::Dynamic > EMatrix3Xcd;
350typedef EMatrix< std::complex< float >, 3, Eigen::Dynamic > EMatrix3Xcf;
351typedef EMatrix< double, 3, Eigen::Dynamic > EMatrix3Xd;
352typedef EMatrix< float, 3, Eigen::Dynamic > EMatrix3Xf;
353typedef EMatrix< int, 3, Eigen::Dynamic > EMatrix3Xi;
354typedef EMatrix< std::complex< double >, 4, 4 > EMatrix4cd;
355typedef EMatrix< std::complex< float >, 4, 4 > EMatrix4cf;
356typedef EMatrix< double, 4, 4 > EMatrix4d;
357typedef EMatrix< float, 4, 4 > EMatrix4f;
358typedef EMatrix< int, 4, 4 > EMatrix4i;
359typedef EMatrix< std::complex< double >, 4, Eigen::Dynamic > EMatrix4Xcd;
360typedef EMatrix< std::complex< float >, 4, Eigen::Dynamic > EMatrix4Xcf;
361typedef EMatrix< double, 4, Eigen::Dynamic > EMatrix4Xd;
362typedef EMatrix< float, 4, Eigen::Dynamic > EMatrix4Xf;
363typedef EMatrix< int, 4, Eigen::Dynamic > EMatrix4Xi;
364typedef EMatrix< std::complex< double >, Eigen::Dynamic, 2 > EMatrixX2cd;
365typedef EMatrix< std::complex< float >, Eigen::Dynamic, 2 > EMatrixX2cf;
366typedef EMatrix< double, Eigen::Dynamic, 2 > EMatrixX2d;
367typedef EMatrix< float, Eigen::Dynamic, 2 > EMatrixX2f;
368typedef EMatrix< int, Eigen::Dynamic, 2 > EMatrixX2i;
369typedef EMatrix< std::complex< double >, Eigen::Dynamic, 3 > EMatrixX3cd;
370typedef EMatrix< std::complex< float >, Eigen::Dynamic, 3 > EMatrixX3cf;
371typedef EMatrix< double, Eigen::Dynamic, 3 > EMatrixX3d;
372typedef EMatrix< float, Eigen::Dynamic, 3 > EMatrixX3f;
373typedef EMatrix< int, Eigen::Dynamic, 3 > EMatrixX3i;
374typedef EMatrix< std::complex< double >, Eigen::Dynamic, 4 > EMatrixX4cd;
375typedef EMatrix< std::complex< float >, Eigen::Dynamic, 4 > EMatrixX4cf;
376typedef EMatrix< double, Eigen::Dynamic, 4 > EMatrixX4d;
377typedef EMatrix< float, Eigen::Dynamic, 4 > EMatrixX4f;
378typedef EMatrix< int, Eigen::Dynamic, 4 > EMatrixX4i;
379typedef EMatrix< std::complex< double >, Eigen::Dynamic, Eigen::Dynamic > EMatrixXcd;
380typedef EMatrix< std::complex< float >, Eigen::Dynamic, Eigen::Dynamic > EMatrixXcf;
381typedef EMatrix< double, Eigen::Dynamic, Eigen::Dynamic > EMatrixXd;
382typedef EMatrix< float, Eigen::Dynamic, Eigen::Dynamic > EMatrixXf;
383typedef EMatrix< int, Eigen::Dynamic, Eigen::Dynamic > EMatrixXi;
384typedef EMatrix< std::complex< double >, 1, 2 > ERowVector2cd;
385typedef EMatrix< std::complex< float >, 1, 2 > ERowVector2cf;
386typedef EMatrix< double, 1, 2 > ERowVector2d;
387typedef EMatrix< float, 1, 2 > ERowVector2f;
388typedef EMatrix< int, 1, 2 > ERowVector2i;
389typedef EMatrix< std::complex< double >, 1, 3 > ERowVector3cd;
390typedef EMatrix< std::complex< float >, 1, 3 > ERowVector3cf;
391typedef EMatrix< double, 1, 3 > ERowVector3d;
392typedef EMatrix< float, 1, 3 > ERowVector3f;
393typedef EMatrix< int, 1, 3 > ERowVector3i;
394typedef EMatrix< std::complex< double >, 1, 4 > ERowVector4cd;
395typedef EMatrix< std::complex< float >, 1, 4 > ERowVector4cf;
396typedef EMatrix< double, 1, 4 > ERowVector4d;
397typedef EMatrix< float, 1, 4 > ERowVector4f;
398typedef EMatrix< int, 1, 4 > ERowVector4i;
399typedef EMatrix< std::complex< double >, 1, Eigen::Dynamic > ERowVectorXcd;
400typedef EMatrix< std::complex< float >, 1, Eigen::Dynamic > ERowVectorXcf;
401typedef EMatrix< double, 1, Eigen::Dynamic > ERowVectorXd;
402typedef EMatrix< float, 1, Eigen::Dynamic > ERowVectorXf;
403typedef EMatrix< int, 1, Eigen::Dynamic > ERowVectorXi;
404typedef EMatrix< std::complex< double >, 2, 1 > EVector2cd;
405typedef EMatrix< std::complex< float >, 2, 1 > EVector2cf;
406typedef EMatrix< double, 2, 1 > EVector2d;
407typedef EMatrix< float, 2, 1 > EVector2f;
408typedef EMatrix< int, 2, 1 > EVector2i;
409typedef EMatrix< std::complex< double >, 3, 1 > EVector3cd;
410typedef EMatrix< std::complex< float >, 3, 1 > EVector3cf;
411typedef EMatrix< double, 3, 1 > EVector3d;
412typedef EMatrix< float, 3, 1 > EVector3f;
413typedef EMatrix< int, 3, 1 > EVector3i;
414typedef EMatrix< std::complex< double >, 4, 1 > EVector4cd;
415typedef EMatrix< std::complex< float >, 4, 1 > EVector4cf;
416typedef EMatrix< double, 4, 1 > EVector4d;
417typedef EMatrix< float, 4, 1 > EVector4f;
418typedef EMatrix< int, 4, 1 > EVector4i;
419typedef EMatrix< std::complex< double >, Eigen::Dynamic, 1 > EVectorXcd;
420typedef EMatrix< std::complex< float >, Eigen::Dynamic, 1 > EVectorXcf;
421typedef EMatrix< double, Eigen::Dynamic, 1 > EVectorXd;
422typedef EMatrix< float, Eigen::Dynamic, 1 > EVectorXf;
423typedef EMatrix< int, Eigen::Dynamic, 1 > EVectorXi;
void * getPointerOffset(size_t offset)
Get the base memory pointer increased with an offset.
virtual void * getPointer()
Return the pointer of the last allocation.
virtual bool allocate(size_t sz)
Allocate a chunk of memory.
This class implement an NxN (dense) matrix.
void incReq()
Increment the request pointer.
static void pack(ExtPreAlloc< Mem >, const T &obj)
Error, no implementation.
size_t getOffset()
Return the actual counter.
void addOffset(size_t off)
Increment the offset pointer by off.
static void unpack(ExtPreAlloc< Mem >, T &obj)
Error, no implementation.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data