QMCPACK
ConstantSizeMatrix< T, ALLOC > Class Template Reference

Drop in replacement for OhmmsMatrix as a storage object backed by PooledMemory, does not support PETE. More...

+ Inheritance diagram for ConstantSizeMatrix< T, ALLOC >:
+ Collaboration diagram for ConstantSizeMatrix< T, ALLOC >:

Public Member Functions

 ConstantSizeMatrix (size_t m, size_t n, size_t m_max, size_t n_max, T val=T())
 
 ConstantSizeMatrix (const ConstantSizeMatrix &csm)
 
const T * operator[] (size_t i) const
 
T * operator[] (size_t i)
 
template<typename Allocator = ALLOC, typename = IsHostSafe<Allocator>>
T & operator() (size_t i)
 
template<typename Allocator = ALLOC, typename = IsHostSafe<Allocator>>
operator() (size_t i) const
 
template<typename Allocator = ALLOC, typename = IsHostSafe<Allocator>>
T & operator() (size_t i, size_t j)
 
template<typename Allocator = ALLOC, typename = IsHostSafe<Allocator>>
const T & operator() (size_t i, size_t j) const
 
T * data ()
 
const T * data () const
 
size_t capacity ()
 
size_t n_capacity ()
 
size_t size () const
 
size_t cols () const
 
size_t rows () const
 
void resize (size_t m, size_t n)
 
auto begin ()
 
auto end ()
 
auto begin () const
 
auto end () const
 
template<class RHS , typename allocator = ALLOC, typename = IsHostSafe<allocator>>
void copy (const RHS &rhs)
 Methods for assignment or copy of identically sized or smaller ConstantSizeMatrix<T, ALLOC>. More...
 
void copy (const ConstantSizeMatrix &rhs)
 
ConstantSizeMatrixoperator= (const ConstantSizeMatrix &rhs)
 
template<template< typename, class > class RHS, typename TP , class ALLOCP , typename = IsHostSafe<ALLOC>, typename = IsHostSafe<ALLOCP>>
ConstantSizeMatrix< T, ALLOC > & operator= (const RHS< TP, ALLOCP > &rhs)
 
template<class TP , class ALLOCP , typename = IsHostSafe<ALLOC>, typename = IsHostSafe<ALLOCP>>
ConstantSizeMatrix< T, ALLOC > & operator= (const Matrix< TP, ALLOCP > &rhs)
 

Private Attributes

size_t m_
 
size_t n_
 
size_t m_max_
 
size_t n_max_
 
size_t capacity_
 
std::vector< T, ALLOC > data_
 

Detailed Description

template<class T, typename ALLOC = std::allocator<T>>
class qmcplusplus::ConstantSizeMatrix< T, ALLOC >

Drop in replacement for OhmmsMatrix as a storage object backed by PooledMemory, does not support PETE.

rows are contiguous i.e. it's row major like OhmmsMatrix Constant size removes worry about synchronizing DataSet in Walker.

Reproduces some creative operator semantics from OhmmsMatrix, be careful.

This is intended as a host object, Not for use on accelerators.

Definition at line 23 of file ConstantSizeMatrix.hpp.

Constructor & Destructor Documentation

◆ ConstantSizeMatrix() [1/2]

ConstantSizeMatrix ( size_t  m,
size_t  n,
size_t  m_max,
size_t  n_max,
val = T() 
)
inline

Definition at line 26 of file ConstantSizeMatrix.hpp.

27  : m_(m), n_(n), m_max_(m_max), n_max_(n_max), capacity_(n_max * m_max), data_(n_max * m_max, val)
28  {
29  if (n_max <= 0 || n > n_max || m_max <= 0 || m > m_max)
30  throw std::runtime_error("Cannot construct ConstantSizeMatrix with an invalid size");
31  }

◆ ConstantSizeMatrix() [2/2]

ConstantSizeMatrix ( const ConstantSizeMatrix< T, ALLOC > &  csm)
inline

Definition at line 33 of file ConstantSizeMatrix.hpp.

34  : m_(csm.m_), n_(csm.n_), m_max_(csm.m_max_), n_max_(csm.n_max_), capacity_(csm.capacity_), data_(csm.capacity_)
35  {
36  //I don't just do an = here because of the posible semantics of allocator propagation.
37  data_.assign(csm.begin(), csm.end());
38  }

Member Function Documentation

◆ begin() [1/2]

auto begin ( )
inline

◆ begin() [2/2]

auto begin ( ) const
inline

Definition at line 189 of file ConstantSizeMatrix.hpp.

189 { return data_.begin(); }

◆ capacity()

◆ cols()

size_t cols ( ) const
inline

Definition at line 158 of file ConstantSizeMatrix.hpp.

Referenced by qmcplusplus::TEST_CASE().

◆ copy() [1/2]

void copy ( const RHS &  rhs)
inline

Methods for assignment or copy of identically sized or smaller ConstantSizeMatrix<T, ALLOC>.

Definition at line 46 of file ConstantSizeMatrix.hpp.

Referenced by Walker< qmcplusplus::QMCTraits, qmcplusplus::PtclOnLatticeTraits >::makeCopy().

47  {
48  if (this->data_.capacity() < rhs.size())
49  throw std::runtime_error("Constant size vector cannot fit matrix to be copied.");
50  data_.assign(rhs.begin(), rhs.end());
51  }

◆ copy() [2/2]

void copy ( const ConstantSizeMatrix< T, ALLOC > &  rhs)
inline

Definition at line 52 of file ConstantSizeMatrix.hpp.

53  {
54  if (this->data_.capacity() < rhs.size())
55  throw std::runtime_error("Constant size vector cannot fit matrix to be copied.");
56  if (&rhs == this)
57  throw std::runtime_error("ConstantSizeMatrix.copy(ConstantSizeMatrix& rhs) &rhs == this");
58  data_.assign(rhs.data_.begin(), rhs.data_.end());
59  }

◆ data() [1/2]

◆ data() [2/2]

const T* data ( ) const
inline

Definition at line 152 of file ConstantSizeMatrix.hpp.

152 { return data_.data(); }

◆ end() [1/2]

auto end ( )
inline

◆ end() [2/2]

auto end ( ) const
inline

Definition at line 190 of file ConstantSizeMatrix.hpp.

190 { return data_.end(); }

◆ n_capacity()

size_t n_capacity ( )
inline

Definition at line 155 of file ConstantSizeMatrix.hpp.

◆ operator()() [1/4]

T& operator() ( size_t  i)
inline

Definition at line 120 of file ConstantSizeMatrix.hpp.

121  {
122  // As far as I know no code does this and none should
123  if (n_ <= i)
124  throw std::runtime_error("ConstantSizeMatrix doesn't support access to second row values through operator()");
125  return data_[i];
126  }

◆ operator()() [2/4]

T operator() ( size_t  i) const
inline

Definition at line 129 of file ConstantSizeMatrix.hpp.

130  {
131  // As far as I know no code does this and none should
132  if (n_ <= i)
133  throw std::runtime_error("ConstantSizeMatrix doesn't support access to second row values through operator()");
134  return data_[i];
135  }

◆ operator()() [3/4]

T& operator() ( size_t  i,
size_t  j 
)
inline

Definition at line 139 of file ConstantSizeMatrix.hpp.

140  {
141  return data_[i * n_max_ + j];
142  }

◆ operator()() [4/4]

const T& operator() ( size_t  i,
size_t  j 
) const
inline

Definition at line 146 of file ConstantSizeMatrix.hpp.

147  {
148  return data_[i * n_max_ + j];
149  }

◆ operator=() [1/3]

ConstantSizeMatrix& operator= ( const ConstantSizeMatrix< T, ALLOC > &  rhs)
inline

Definition at line 61 of file ConstantSizeMatrix.hpp.

62  {
63  if (this->data_.capacity() < rhs.size())
64  throw std::runtime_error("ConstantSizeMatrix cannot take assignment of larger than max size");
65  if (&rhs != this)
66  {
67  if (rhs.n_max_ == n_max_)
68  data_.assign(rhs.data_.begin(), rhs.data_.end());
69  else
70  throw std::runtime_error("ConstnatSizedMatrix assignment for mismatched n_max not yet supported.");
71  }
72  return *this;
73  }

◆ operator=() [2/3]

ConstantSizeMatrix<T, ALLOC>& operator= ( const RHS< TP, ALLOCP > &  rhs)
inline

Definition at line 80 of file ConstantSizeMatrix.hpp.

81  {
82  if (this->data_.capacity() < rhs.size())
83  throw std::runtime_error("ConstantSizeMatrix cannot be assigned a matrix larger than itself.");
84  data_.assign(rhs.begin(), rhs.end());
85  return *this;
86  }

◆ operator=() [3/3]

ConstantSizeMatrix<T, ALLOC>& operator= ( const Matrix< TP, ALLOCP > &  rhs)
inline

Definition at line 89 of file ConstantSizeMatrix.hpp.

90  {
91  if (this->data_.capacity() < rhs.size())
92  {
93  std::basic_ostringstream<char> error;
94  error << "ConstantSizeMatrix cannot take assignment of larger than max size (" << n_max_ << " by " << m_max_
95  << ") \n";
96  throw std::runtime_error(error.str());
97  }
98  if (this->n_max_ < rhs.cols())
99  {
100  std::basic_ostringstream<char> error;
101  error << "ConstantSizeMatrix cannot be assigned a matrix dimension larger than n_max (" << n_max_ << ")\n";
102  throw std::runtime_error(error.str());
103  }
104  n_ = rhs.cols();
105  m_ = rhs.rows();
106  for (size_t row = 0; row < rhs.rows(); ++row)
107  std::copy(rhs[row], rhs[row] + n_, (*this)[row]);
108  return *this;
109  }
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
void error(char const *m)
Definition: Standard.h:204

◆ operator[]() [1/2]

const T* operator[] ( size_t  i) const
inline

Definition at line 113 of file ConstantSizeMatrix.hpp.

113 { return data_.data() + i * n_max_; }

◆ operator[]() [2/2]

T* operator[] ( size_t  i)
inline

Definition at line 116 of file ConstantSizeMatrix.hpp.

116 { return data_.data() + i * n_max_; }

◆ resize()

void resize ( size_t  m,
size_t  n 
)
inline

Definition at line 161 of file ConstantSizeMatrix.hpp.

Referenced by MCPopulation::createWalkers(), MCWalkerConfiguration::resetWalkerProperty(), Walker< qmcplusplus::QMCTraits, qmcplusplus::PtclOnLatticeTraits >::resizeProperty(), and qmcplusplus::TEST_CASE().

162  {
163  if (n * m > capacity())
164  {
165  std::ostringstream error;
166  error << "You cannot resize a constant size matrix beyond its initial max dimensions ( " << m << "," << n << " > "
167  << m_max_ << "," << n_max_ << " )\n";
168  throw std::domain_error(error.str());
169  }
170 
171  if (n > n_max_)
172  {
173  n_max_ = n;
174  m_max_ = capacity() / n_max_;
175  }
176 
177  if (m > m_max_)
178  {
179  m_max_ = m;
180  n_max_ = capacity() / m_max_;
181  }
182 
183  n_ = n;
184  m_ = m;
185  }
void error(char const *m)
Definition: Standard.h:204

◆ rows()

size_t rows ( ) const
inline

Definition at line 159 of file ConstantSizeMatrix.hpp.

◆ size()

Member Data Documentation

◆ capacity_

◆ data_

◆ m_

◆ m_max_

◆ n_

◆ n_max_


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