Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Real2dData< F > Class Template Reference

#include <Real2dData.h>

Public Types

using Float = F
 
using DataVector = std::vector< F >
 
using Index = unsigned int
 
using IndexArray = std::array< Index, 2 >
 
using Norm = RealDftNormalization
 
using Complex = std::complex< Float >
 

Public Member Functions

 Real2dData ()
 
 Real2dData (const IndexArray &nsams)
 
 Real2dData (const IndexArray &nsams, const DataVector &data)
 
virtual ~Real2dData ()=default
 
void clear ()
 
void reset (const IndexArray &nsams)
 
Index rank () const
 
const IndexArraynSamples () const
 
Index nSamples (Index idim) const
 
Index size (Index idim) const
 
Index size () const
 
bool inRange (Index idim, Index idat) const
 
bool isZero (Index idat) const
 
bool isValid () const
 
Float badValue () const
 
const std::vector< F > & data () const
 
int copyDataIn (const DataVector &data)
 
template<typename T >
int copyDataIn (const T *pdat)
 
template<typename T >
int copyDataOut (T *pdat) const
 
Index globalIndex (const IndexArray &isams, Index *pchk=nullptr) const
 
Float value (const IndexArray &isams, Index *pchk=nullptr) const
 
Index setValue (const IndexArray &isams, Float val, Index *pchk=nullptr)
 
power () const
 

Static Public Member Functions

template<std::size_t N>
static Index dataSize (const std::array< Index, N > &nsams)
 

Private Attributes

IndexArray m_nsams
 
DataVector m_data
 

Detailed Description

template<typename F>
class Real2dData< F >

Definition at line 20 of file Real2dData.h.

Member Typedef Documentation

template<typename F>
using Real2dData< F >::Complex = std::complex<Float>

Definition at line 36 of file Real2dData.h.

template<typename F>
using Real2dData< F >::DataVector = std::vector<F>

Definition at line 32 of file Real2dData.h.

template<typename F>
using Real2dData< F >::Float = F

Definition at line 31 of file Real2dData.h.

template<typename F>
using Real2dData< F >::Index = unsigned int

Definition at line 33 of file Real2dData.h.

template<typename F>
using Real2dData< F >::IndexArray = std::array<Index,2>

Definition at line 34 of file Real2dData.h.

template<typename F>
using Real2dData< F >::Norm = RealDftNormalization

Definition at line 35 of file Real2dData.h.

Constructor & Destructor Documentation

template<typename F>
Real2dData< F >::Real2dData ( )
inline

Definition at line 52 of file Real2dData.h.

52 : m_nsams({0,0}) { }
IndexArray m_nsams
Definition: Real2dData.h:220
template<typename F>
Real2dData< F >::Real2dData ( const IndexArray nsams)
inline

Definition at line 56 of file Real2dData.h.

56 : m_nsams(nsams), m_data(dataSize(nsams), 0.0) { }
static Index dataSize(const std::array< Index, N > &nsams)
Definition: Real2dData.h:41
DataVector m_data
Definition: Real2dData.h:221
IndexArray m_nsams
Definition: Real2dData.h:220
template<typename F>
Real2dData< F >::Real2dData ( const IndexArray nsams,
const DataVector data 
)
inline

Definition at line 59 of file Real2dData.h.

60  : Real2dData(nsams) {
62  }
const std::vector< F > & data() const
Definition: Real2dData.h:117
int copyDataIn(const DataVector &data)
Definition: Real2dData.h:121
template<typename F>
virtual Real2dData< F >::~Real2dData ( )
virtualdefault

Member Function Documentation

template<typename F>
Float Real2dData< F >::badValue ( ) const
inline

Definition at line 111 of file Real2dData.h.

111  {
112  double bad = std::numeric_limits<Float>::quiet_NaN();
113  return bad;
114  }
unsigned int bad()
template<typename F>
void Real2dData< F >::clear ( )
inline

Definition at line 68 of file Real2dData.h.

68  {
69  for ( Index& nsam : m_nsams ) nsam = 0;
70  m_data.clear();
71  }
unsigned int Index
DataVector m_data
Definition: Real2dData.h:221
IndexArray m_nsams
Definition: Real2dData.h:220
template<typename F>
int Real2dData< F >::copyDataIn ( const DataVector data)
inline

Definition at line 121 of file Real2dData.h.

121  {
122  if ( ! isValid() ) return 1;
123  if ( data.size() != m_data.size() ) return 2;
124  m_data = data;
125  return 0;
126  }
const std::vector< F > & data() const
Definition: Real2dData.h:117
DataVector m_data
Definition: Real2dData.h:221
bool isValid() const
Definition: Real2dData.h:102
template<typename F>
template<typename T >
int Real2dData< F >::copyDataIn ( const T *  pdat)
inline

Definition at line 131 of file Real2dData.h.

131  {
132  if ( ! isValid() ) return 1;
133  Index ndat = size();
134  for ( Index idat=0; idat<ndat; ++idat ) {
135  m_data[idat] = pdat[idat];
136  }
137  return 0;
138  }
Index size() const
Definition: Real2dData.h:94
unsigned int Index
DataVector m_data
Definition: Real2dData.h:221
bool isValid() const
Definition: Real2dData.h:102
template<typename F>
template<typename T >
int Real2dData< F >::copyDataOut ( T *  pdat) const
inline

Definition at line 143 of file Real2dData.h.

143  {
144  if ( ! isValid() ) return 1;
145  Index ndat = dataSize(nSamples());
146  for ( Index idat=0; idat<ndat; ++idat ) {
147  pdat[idat] = m_data[idat];
148  }
149  return 0;
150  }
const IndexArray & nSamples() const
Definition: Real2dData.h:86
unsigned int Index
static Index dataSize(const std::array< Index, N > &nsams)
Definition: Real2dData.h:41
DataVector m_data
Definition: Real2dData.h:221
bool isValid() const
Definition: Real2dData.h:102
template<typename F>
const std::vector<F>& Real2dData< F >::data ( ) const
inline

Definition at line 117 of file Real2dData.h.

117 { return m_data; }
DataVector m_data
Definition: Real2dData.h:221
template<typename F>
template<std::size_t N>
static Index Real2dData< F >::dataSize ( const std::array< Index, N > &  nsams)
inlinestatic

Definition at line 41 of file Real2dData.h.

41  {
42  Index ndat = 1;
43  Index ndim = nsams.size();
44  for ( Index idim=0; idim<ndim; ++idim ) {
45  Index nsam = nsams[idim];
46  ndat *= nsam;
47  }
48  return ndat;
49  }
unsigned int Index
template<typename F>
Index Real2dData< F >::globalIndex ( const IndexArray isams,
Index pchk = nullptr 
) const
inline

Definition at line 154 of file Real2dData.h.

154  {
155  if ( ! isValid() ) {
156  if ( pchk != nullptr ) *pchk = 1;
157  return size();
158  }
159  if ( isams.size() != rank() ) {
160  if ( pchk != nullptr ) *pchk = 2;
161  return size();
162  }
163  if ( pchk != nullptr ) {
164  for ( Index idim=0; idim<rank(); ++idim ) {
165  if ( ! inRange(idim, isams[idim]) ) {
166  *pchk = 10 + idim;
167  return size();
168  }
169  }
170  *pchk = 0;
171  }
172  Index idat = isams[0];
173  for ( Index idim=1; idim<rank(); ++idim ) {
174  idat *= m_nsams[idim];
175  idat += isams[idim];
176  }
177  return idat;
178  }
Index size() const
Definition: Real2dData.h:94
unsigned int Index
Index rank() const
Definition: Real2dData.h:82
bool inRange(Index idim, Index idat) const
Definition: Real2dData.h:97
IndexArray m_nsams
Definition: Real2dData.h:220
bool isValid() const
Definition: Real2dData.h:102
template<typename F>
bool Real2dData< F >::inRange ( Index  idim,
Index  idat 
) const
inline

Definition at line 97 of file Real2dData.h.

97 { return idim < rank() && idat < size(idim); }
Index size() const
Definition: Real2dData.h:94
Index rank() const
Definition: Real2dData.h:82
template<typename F>
bool Real2dData< F >::isValid ( ) const
inline

Definition at line 102 of file Real2dData.h.

102  {
103  if ( rank() != 2 ) return false;
104  if ( m_nsams.size() != rank() ) return false;
105  if ( size() == 0 ) return false;
106  return true;
107  }
Index size() const
Definition: Real2dData.h:94
Index rank() const
Definition: Real2dData.h:82
IndexArray m_nsams
Definition: Real2dData.h:220
template<typename F>
bool Real2dData< F >::isZero ( Index  idat) const
inline

Definition at line 98 of file Real2dData.h.

98 { return idat == 0; }
template<typename F>
const IndexArray& Real2dData< F >::nSamples ( ) const
inline

Definition at line 86 of file Real2dData.h.

86 { return m_nsams; }
IndexArray m_nsams
Definition: Real2dData.h:220
template<typename F>
Index Real2dData< F >::nSamples ( Index  idim) const
inline

Definition at line 87 of file Real2dData.h.

87  {
88  if ( idim > rank() ) return 0;
89  return nSamples()[idim];
90  }
const IndexArray & nSamples() const
Definition: Real2dData.h:86
Index rank() const
Definition: Real2dData.h:82
template<typename F>
F Real2dData< F >::power ( ) const
inline

Definition at line 206 of file Real2dData.h.

206  {
207  F pwr = 0.0;
208  IndexArray idats;
209  for ( idats[0]=0; idats[0]<size(0); ++idats[0] ) {
210  for ( idats[1]=0; idats[1]<size(1); ++idats[1] ) {
211  F val = value(idats);
212  pwr += val*val;
213  }
214  }
215  return pwr;
216  }
Index size() const
Definition: Real2dData.h:94
DftData::IndexArray IndexArray
Float value(const IndexArray &isams, Index *pchk=nullptr) const
Definition: Real2dData.h:184
template<typename F>
Index Real2dData< F >::rank ( ) const
inline

Definition at line 82 of file Real2dData.h.

82 { return 2; }
template<typename F>
void Real2dData< F >::reset ( const IndexArray nsams)
inline

Definition at line 74 of file Real2dData.h.

74  {
75  m_nsams = nsams;
76  m_data.clear();
77  Index ndat = dataSize(m_nsams);
78  m_data.resize(ndat, 0.0);
79  }
unsigned int Index
static Index dataSize(const std::array< Index, N > &nsams)
Definition: Real2dData.h:41
DataVector m_data
Definition: Real2dData.h:221
IndexArray m_nsams
Definition: Real2dData.h:220
template<typename F>
Index Real2dData< F >::setValue ( const IndexArray isams,
Float  val,
Index pchk = nullptr 
)
inline

Definition at line 197 of file Real2dData.h.

197  {
198  Index idat = globalIndex(isams, pchk);
199  if ( pchk != nullptr && *pchk > 0 ) return size();
200  if ( idat >= size() ) return size();
201  m_data[idat] = val;
202  return idat;
203  }
Index globalIndex(const IndexArray &isams, Index *pchk=nullptr) const
Definition: Real2dData.h:154
Index size() const
Definition: Real2dData.h:94
unsigned int Index
DataVector m_data
Definition: Real2dData.h:221
template<typename F>
Index Real2dData< F >::size ( Index  idim) const
inline

Definition at line 91 of file Real2dData.h.

91 { return nSamples(idim); }
const IndexArray & nSamples() const
Definition: Real2dData.h:86
template<typename F>
Index Real2dData< F >::size ( ) const
inline

Definition at line 94 of file Real2dData.h.

94 { return m_data.size(); }
DataVector m_data
Definition: Real2dData.h:221
template<typename F>
Float Real2dData< F >::value ( const IndexArray isams,
Index pchk = nullptr 
) const
inline

Definition at line 184 of file Real2dData.h.

184  {
185  Index idat = globalIndex(isams, pchk);
186  if ( idat >= size() ) return this->badValue();
187  return m_data[idat];
188  }
Index globalIndex(const IndexArray &isams, Index *pchk=nullptr) const
Definition: Real2dData.h:154
Index size() const
Definition: Real2dData.h:94
unsigned int Index
Float badValue() const
Definition: Real2dData.h:111
DataVector m_data
Definition: Real2dData.h:221

Member Data Documentation

template<typename F>
DataVector Real2dData< F >::m_data
private

Definition at line 221 of file Real2dData.h.

template<typename F>
IndexArray Real2dData< F >::m_nsams
private

Definition at line 220 of file Real2dData.h.


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