StatMech
Loading...
Searching...
No Matches
SparseCompressed< Scalar_t, Options_ > Class Template Reference
Collaboration diagram for SparseCompressed< Scalar_t, Options_ >:
Collaboration graph

Public Types

typedef Scalar_t Scalar
 
typedef Eigen::NumTraits< Scalar_t >::Real RealScalar
 

Public Member Functions

__host__ __device__ SparseCompressed ()
 
__host__ __device__ SparseCompressed (int rows, int cols)
 
__host__ __device__ SparseCompressed (SparseCompressed const &other)
 
template<typename Scalar_ >
__host__ __device__ SparseCompressed (SparseCompressed< Scalar_, Options_ > const &other)
 
template<class Derived >
__host__ SparseCompressed (Eigen::SparseMatrixBase< Derived > &other)
 
template<typename Derived >
__host__ SparseCompressed (Eigen::ReturnByValue< Derived > const &other)
 
__host__ __device__ int & rows ()
 
__host__ __device__ int rows () const
 
__host__ __device__ int & cols ()
 
__host__ __device__ int cols () const
 
__host__ __device__ int reserved () const
 
__host__ __device__ int outerSize () const
 
__host__ __device__ int innerSize () const
 
__host__ __device__ int & setNonZeros (int input)
 
__host__ __device__ int nonZeros () const
 
__host__ __device__ int * outerIndexPtr () const
 
__host__ __device__ int * innerIndexPtr () const
 
__host__ __device__ Scalar_t * valuePtr () const
 
template<typename NewScalar >
__host__ __device__ SparseCompressed< NewScalar, Options_ > cast () const
 
__host__ __device__ SparseCompressed adjoint () const
 
Storage management
__host__ __device__ ~SparseCompressed ()
 
__host__ __device__ void resize (int rows, int cols, int reserved=1)
 
__host__ __device__ void conservativeResize (Integer_t row, Integer_t col)
 

Static Public Attributes

static constexpr bool IsRowMajor = bool(Options_ == Eigen::RowMajor)
 

Private Attributes

int m_outerSize = -1
 
int m_innerSize = -1
 
int m_numNonZeros = 0
 
int * m_outerIndex = nullptr
 
int * m_innerIndex = nullptr
 
Scalar_t * m_value = nullptr
 
int m_reserved = 0
 

Static Private Attributes

static constexpr Eigen::StorageOptions m_scheme = Options_
 

Operator overloads

__host__ __device__ SparseCompressedoperator= (SparseCompressed const &other)
 
__host__ __device__ SparseCompressedoperator= (SparseCompressed &&other)
 
__host__ friend std::ostream & operator<< (std::ostream &os, SparseCompressed const &sparseMat)
 

Member Typedef Documentation

◆ RealScalar

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
typedef Eigen::NumTraits<Scalar_t>::Real SparseCompressed< Scalar_t, Options_ >::RealScalar

◆ Scalar

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
typedef Scalar_t SparseCompressed< Scalar_t, Options_ >::Scalar

Constructor & Destructor Documentation

◆ SparseCompressed() [1/6]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed< Scalar_t, Options_ >::SparseCompressed ( )
inline
297{ debug_constructor_printf(1); }

◆ SparseCompressed() [2/6]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed< Scalar_t, Options_ >::SparseCompressed ( int  rows,
int  cols 
)
inline
299 {
300 debug_constructor_printf(2);
301 this->resize(rows, cols);
302 }
__host__ __device__ void resize(int rows, int cols, int reserved=1)
Definition MatrixUtils.cuh:353
__host__ __device__ int & cols()
Definition MatrixUtils.cuh:403
__host__ __device__ int & rows()
Definition MatrixUtils.cuh:395

◆ SparseCompressed() [3/6]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed< Scalar_t, Options_ >::SparseCompressed ( SparseCompressed< Scalar_t, Options_ > const &  other)
inline
304 {
305 debug_constructor_printf(3 - a(Copy));
306 this->resize(other.rows(), other.cols(), other.nonZeros());
307 m_numNonZeros = other.nonZeros();
308 memcpy(m_outerIndex, other.outerIndexPtr(), (m_outerSize + 1) * sizeof(int));
309 memcpy(m_innerIndex, other.innerIndexPtr(), m_numNonZeros * sizeof(int));
310 memcpy(m_value, other.valuePtr(), m_numNonZeros * sizeof(Scalar_t));
311 }
int m_outerSize
Definition MatrixUtils.cuh:282
int * m_outerIndex
Definition MatrixUtils.cuh:285
int m_numNonZeros
Definition MatrixUtils.cuh:284
Scalar_t * m_value
Definition MatrixUtils.cuh:287
int * m_innerIndex
Definition MatrixUtils.cuh:286

◆ SparseCompressed() [4/6]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
template<typename Scalar_ >
__host__ __device__ SparseCompressed< Scalar_t, Options_ >::SparseCompressed ( SparseCompressed< Scalar_, Options_ > const &  other)
inline
313 {
314 debug_constructor_printf(3 - b(Copy));
315 this->resize(other.rows(), other.cols(), other.nonZeros());
316 m_numNonZeros = other.nonZeros();
317 memcpy(m_outerIndex, other.outerIndexPtr(), (m_outerSize + 1) * sizeof(int));
318 memcpy(m_innerIndex, other.innerIndexPtr(), m_numNonZeros * sizeof(int));
319
320 Scalar_t* valuePtr;
321 cuCHECK(cudaMalloc((void**)&valuePtr, m_numNonZeros * sizeof(Scalar_t)));
322 for(int j = 0; j != m_numNonZeros; ++j)
323 valuePtr[j] = static_cast<Scalar_t>(other.valuePtr()[j]);
324 memcpy(m_value, valuePtr, m_numNonZeros * sizeof(Scalar_t));
325 cuCHECK(cudaFree(valuePtr));
326 }
__host__ __device__ int nonZeros() const
Definition MatrixUtils.cuh:418
__host__ __device__ int * innerIndexPtr() const
Definition MatrixUtils.cuh:421
__host__ __device__ int * outerIndexPtr() const
Definition MatrixUtils.cuh:420
__host__ __device__ Scalar_t * valuePtr() const
Definition MatrixUtils.cuh:422
cuCHECK(cudaFuncGetAttributes(&attr, MatrixElementsInSector))

◆ SparseCompressed() [5/6]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
template<class Derived >
__host__ SparseCompressed< Scalar_t, Options_ >::SparseCompressed ( Eigen::SparseMatrixBase< Derived > &  other)
inline
329 {
330 debug_constructor_printf(4(Copy));
331 other.makeCompressed();
332 this->resize(other.rows(), other.cols(), other.nonZeros());
333 m_numNonZeros = other.nonZeros();
334 memcpy(m_outerIndex, other.outerIndexPtr(), (m_outerSize + 1) * sizeof(int));
335 memcpy(m_innerIndex, other.innerIndexPtr(), m_numNonZeros * sizeof(int));
336 memcpy(m_value, other.valuePtr(), m_numNonZeros * sizeof(Scalar_t));
337 }

◆ SparseCompressed() [6/6]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
template<typename Derived >
__host__ SparseCompressed< Scalar_t, Options_ >::SparseCompressed ( Eigen::ReturnByValue< Derived > const &  other)
inline
341 : SparseCompressed(other.eval()) {
342 debug_constructor_printf(5(Copy from expression));
343 }
__host__ __device__ SparseCompressed()
Definition MatrixUtils.cuh:297

◆ ~SparseCompressed()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed< Scalar_t, Options_ >::~SparseCompressed ( )
inline
347 {
348 cuCHECK(cudaFree(m_outerIndex));
349 cuCHECK(cudaFree(m_innerIndex));
350 cuCHECK(cudaFree(m_value));
351 }

Member Function Documentation

◆ adjoint()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed SparseCompressed< Scalar_t, Options_ >::adjoint ( ) const
inline
430 {
431 debug_printf("%s\n", __PRETTY_FUNCTION__);
433 res.resize(this->cols(), this->rows(), this->nonZeros());
434 res.setNonZeros(this->nonZeros());
435 for(int j = 0; j != this->outerSize(); ++j) {
436 for(int k = this->outerIndexPtr()[j]; k != this->outerIndexPtr()[j + 1]; ++k) {
437 // debug_printf("\t res.innerIndexPtr()[%d] = %d\n", k, j);
438 res.innerIndexPtr()[k] = j;
439 }
440 }
441 Eigen::ArrayX<int> resOuterIndex(res.nonZeros());
442 for(int j = 0; j != this->nonZeros(); ++j) {
443 resOuterIndex(j) = this->innerIndexPtr()[j];
444 res.valuePtr()[j] = conj(this->valuePtr()[j]);
445 }
446
447#ifdef __CUDA_ARCH__
448 Eigen::ArrayX<int> resOuterIndexCpy(resOuterIndex);
449 thrust::sort_by_key(thrust::seq, resOuterIndexCpy.data(),
450 resOuterIndexCpy.data() + res.nonZeros(), res.valuePtr());
451 thrust::sort_by_key(thrust::seq, resOuterIndex.data(),
452 resOuterIndex.data() + res.nonZeros(), res.innerIndexPtr());
453#else
454 Eigen::ArrayX< std::tuple<int, int, Scalar_t> > data(res.nonZeros());
455 #pragma omp parallel
456 {
457 #pragma omp for
458 for(int j = 0; j < res.nonZeros(); ++j) {
459 data(j) = std::tuple<int, int, Scalar_t>(
460 resOuterIndex(j), res.innerIndexPtr()[j], res.valuePtr()[j]);
461 }
462 #pragma omp single
463 std::sort(data.data(), data.data() + res.nonZeros(),
464 [](auto& lhs, auto& rhs) { return std::get<0>(lhs) < std::get<0>(rhs); });
465 #pragma omp for
466 for(int j = 0; j < res.nonZeros(); ++j) {
467 resOuterIndex(j) = std::get<0>(data(j));
468 res.innerIndexPtr()[j] = std::get<1>(data(j));
469 res.valuePtr()[j] = std::get<2>(data(j));
470 }
471 }
472#endif
473
474 int prev = 0;
475 res.outerIndexPtr()[0] = 0;
476 res.outerIndexPtr()[res.outerSize()] = res.nonZeros();
477 for(int count = 0; count != res.nonZeros(); ++count) {
478 if(prev != resOuterIndex(count)) {
479 assert(resOuterIndex(count) < res.nonZeros()
480 && "Out of bounds for resOuterIndex.");
481 for(int j = prev + 1; j != resOuterIndex(count); ++j) {
482 res.outerIndexPtr()[j] = res.outerIndexPtr()[prev];
483 }
484 res.outerIndexPtr()[resOuterIndex(count)] = count;
485 }
486 prev = resOuterIndex(count);
487 }
488 return res;
489 }
Definition MatrixUtils.cuh:280
__host__ __device__ int & setNonZeros(int input)
Definition MatrixUtils.cuh:417
__host__ __device__ int outerSize() const
Definition MatrixUtils.cuh:414

◆ cast()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
template<typename NewScalar >
__host__ __device__ SparseCompressed< NewScalar, Options_ > SparseCompressed< Scalar_t, Options_ >::cast ( ) const
inline
425 {
426 if constexpr(std::is_same_v<Scalar, NewScalar>) return *this;
428 }

◆ cols() [1/2]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int & SparseCompressed< Scalar_t, Options_ >::cols ( )
inline
403 {
404 if constexpr(IsRowMajor) { return m_innerSize; }
405 return m_outerSize;
406 }
int m_innerSize
Definition MatrixUtils.cuh:283
static constexpr bool IsRowMajor
Definition MatrixUtils.cuh:295

◆ cols() [2/2]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int SparseCompressed< Scalar_t, Options_ >::cols ( ) const
inline
407 {
408 if constexpr(IsRowMajor) { return m_innerSize; }
409 return m_outerSize;
410 }

◆ conservativeResize()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ void SparseCompressed< Scalar_t, Options_ >::conservativeResize ( Integer_t  row,
Integer_t  col 
)
inline
388 {
389 debug_printf("%s: For compatibility to Eigen's interface. Does nothing for now.\n\n",
390 __PRETTY_FUNCTION__);
391 return;
392 };

◆ innerIndexPtr()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int * SparseCompressed< Scalar_t, Options_ >::innerIndexPtr ( ) const
inline
421{ return m_innerIndex; }

◆ innerSize()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int SparseCompressed< Scalar_t, Options_ >::innerSize ( ) const
inline
416{ return m_innerSize; }

◆ nonZeros()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int SparseCompressed< Scalar_t, Options_ >::nonZeros ( ) const
inline
418{ return m_numNonZeros; }

◆ operator=() [1/2]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed & SparseCompressed< Scalar_t, Options_ >::operator= ( SparseCompressed< Scalar_t, Options_ > &&  other)
inline
503 {
504 debug_printf("%s:\n\tMove assignment operator\n", __PRETTY_FUNCTION__);
505 delete[] m_outerIndex;
506 delete[] m_innerIndex;
507 delete[] m_value;
508
509 m_outerSize = other.m_outerSize;
510 m_innerSize = other.m_innerSize;
512 m_reserved = other.m_reserved;
515 m_value = other.m_value;
516
517 other.m_outerIndex = nullptr;
518 other.m_innerIndex = nullptr;
519 other.m_value = nullptr;
520 return *this;
521 }
int m_reserved
Definition MatrixUtils.cuh:288

◆ operator=() [2/2]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ SparseCompressed & SparseCompressed< Scalar_t, Options_ >::operator= ( SparseCompressed< Scalar_t, Options_ > const &  other)
inline
493 {
494 debug_printf("%s: Copy assignment operator\n", __PRETTY_FUNCTION__);
495 this->resize(other.rows(), other.cols(), other.nonZeros());
496 m_numNonZeros = other.m_numNonZeros;
497 memcpy(m_outerIndex, other.m_outerIndex, (m_outerSize + 1) * sizeof(int));
498 memcpy(m_innerIndex, other.m_innerIndex, m_numNonZeros * sizeof(int));
499 memcpy(m_value, other.m_value, m_numNonZeros * sizeof(Scalar_t));
500 return *this;
501 }

◆ outerIndexPtr()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int * SparseCompressed< Scalar_t, Options_ >::outerIndexPtr ( ) const
inline
420{ return m_outerIndex; }

◆ outerSize()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int SparseCompressed< Scalar_t, Options_ >::outerSize ( ) const
inline
414{ return m_outerSize; }

◆ reserved()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int SparseCompressed< Scalar_t, Options_ >::reserved ( ) const
inline
411{ return m_reserved; }

◆ resize()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ void SparseCompressed< Scalar_t, Options_ >::resize ( int  rows,
int  cols,
int  reserved = 1 
)
inline
353 {
354 debug_printf("%s\n", __PRETTY_FUNCTION__);
355 assert(rows >= 0 && cols >= 0 && reserved >= 1);
356 int outerDim, innerDim;
357 if constexpr(IsRowMajor) {
358 outerDim = rows;
359 innerDim = cols;
360 }
361 else {
362 outerDim = cols;
363 innerDim = rows;
364 }
365
366 if(outerDim > m_outerSize) {
367 m_outerSize = outerDim;
368 cuCHECK(cudaFree(m_outerIndex));
369 cuCHECK(cudaMalloc((void**)&m_outerIndex, (m_outerSize + 1) * sizeof(int)));
370 memset(m_outerIndex, 0, (m_outerSize + 1) * sizeof(int));
371 }
372 if(reserved > m_reserved) {
374 cuCHECK(cudaFree(m_innerIndex));
375 cuCHECK(cudaFree(m_value));
376 cuCHECK(cudaMalloc((void**)&m_innerIndex, m_reserved * sizeof(int)));
377 cuCHECK(cudaMalloc((void**)&m_value, m_reserved * sizeof(Scalar_t)));
378 m_innerIndex[0] = 0;
379 m_value[0] = {0, 0};
380 }
381
382 m_outerSize = outerDim;
383 m_innerSize = innerDim;
384 m_numNonZeros = 0;
385 return;
386 }
__host__ __device__ int reserved() const
Definition MatrixUtils.cuh:411

◆ rows() [1/2]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int & SparseCompressed< Scalar_t, Options_ >::rows ( )
inline
395 {
396 if constexpr(IsRowMajor) { return m_outerSize; }
397 return m_innerSize;
398 }

◆ rows() [2/2]

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int SparseCompressed< Scalar_t, Options_ >::rows ( ) const
inline
399 {
400 if constexpr(IsRowMajor) { return m_outerSize; }
401 return m_innerSize;
402 }

◆ setNonZeros()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ int & SparseCompressed< Scalar_t, Options_ >::setNonZeros ( int  input)
inline
417{ return m_numNonZeros = input; }

◆ valuePtr()

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ __device__ Scalar_t * SparseCompressed< Scalar_t, Options_ >::valuePtr ( ) const
inline
422{ return m_value; }

Friends And Related Symbol Documentation

◆ operator<<

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
__host__ friend std::ostream & operator<< ( std::ostream &  os,
SparseCompressed< Scalar_t, Options_ > const &  sparseMat 
)
friend
524 {
525 assert(sparseMat.m_numNonZeros <= sparseMat.m_reserved
526 && "Failed: sparseMat.m_numNonZeros <= sparseMat.m_reserved");
527 Eigen::Map< Eigen::SparseMatrix<Scalar_t, Options_> > map(
528 sparseMat.rows(), sparseMat.cols(), sparseMat.m_numNonZeros, sparseMat.m_outerIndex,
529 sparseMat.m_innerIndex, sparseMat.m_value);
530 os << Eigen::MatrixX<Scalar_t>(map);
531 return os;
532 }

Member Data Documentation

◆ IsRowMajor

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
constexpr bool SparseCompressed< Scalar_t, Options_ >::IsRowMajor = bool(Options_ == Eigen::RowMajor)
staticconstexpr

◆ m_innerIndex

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
int* SparseCompressed< Scalar_t, Options_ >::m_innerIndex = nullptr
private

◆ m_innerSize

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
int SparseCompressed< Scalar_t, Options_ >::m_innerSize = -1
private

◆ m_numNonZeros

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
int SparseCompressed< Scalar_t, Options_ >::m_numNonZeros = 0
private

◆ m_outerIndex

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
int* SparseCompressed< Scalar_t, Options_ >::m_outerIndex = nullptr
private

◆ m_outerSize

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
int SparseCompressed< Scalar_t, Options_ >::m_outerSize = -1
private

◆ m_reserved

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
int SparseCompressed< Scalar_t, Options_ >::m_reserved = 0
private

◆ m_scheme

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
constexpr Eigen::StorageOptions SparseCompressed< Scalar_t, Options_ >::m_scheme = Options_
staticconstexprprivate

◆ m_value

template<typename Scalar_t = Complex_t<Real_t>, Eigen::StorageOptions Options_ = Eigen::ColMajor>
Scalar_t* SparseCompressed< Scalar_t, Options_ >::m_value = nullptr
private

The documentation for this class was generated from the following file: