ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
NDArray< DataType > Struct Template Reference

#include <ERF_NCWpsFile.H>

Collaboration diagram for NDArray< DataType >:

Public Types

using DType = typename std::remove_const< DataType >::type
 

Public Member Functions

 NDArray (const std::string vname, const std::vector< size_t > &vshape)
 
 NDArray ()
 
 NDArray (const NDArray &array)
 
NDArrayoperator= (const NDArray &array)
 
 ~NDArray ()
 
decltype(auto) get_data ()
 
std::string get_vname ()
 
std::vector< size_t > get_vshape ()
 
size_t ndim ()
 
void set_vshape (std::vector< size_t > vshape)
 

Private Attributes

std::string name
 
std::vector< size_t > shape
 
std::atomic< size_t > ref_counted
 
bool owned
 
DTypedata
 

Member Typedef Documentation

◆ DType

template<typename DataType >
using NDArray< DataType >::DType = typename std::remove_const<DataType>::type

Constructor & Destructor Documentation

◆ NDArray() [1/3]

template<typename DataType >
NDArray< DataType >::NDArray ( const std::string  vname,
const std::vector< size_t > &  vshape 
)
inlineexplicit
56  : name{vname}, shape{vshape}, ref_counted{1}, owned{true} {
57  data = new DType [this->ndim()];
58  }
bool owned
Definition: ERF_NCWpsFile.H:121
std::string name
Definition: ERF_NCWpsFile.H:118
size_t ndim()
Definition: ERF_NCWpsFile.H:105
std::atomic< size_t > ref_counted
Definition: ERF_NCWpsFile.H:120
typename std::remove_const< DataType >::type DType
Definition: ERF_NCWpsFile.H:52
std::vector< size_t > shape
Definition: ERF_NCWpsFile.H:119
DType * data
Definition: ERF_NCWpsFile.H:122
Here is the call graph for this function:

◆ NDArray() [2/3]

template<typename DataType >
NDArray< DataType >::NDArray ( )
inline
61 : name{"null"}, ref_counted{1}, owned{false}, data{nullptr} {}

◆ NDArray() [3/3]

template<typename DataType >
NDArray< DataType >::NDArray ( const NDArray< DataType > &  array)
inline
64  {
65  name = array.name;
66  shape = array.shape;
67  data = array.data;
68  owned = false;
69  ref_counted.fetch_add(1, std::memory_order_relaxed);
70  }

◆ ~NDArray()

template<typename DataType >
NDArray< DataType >::~NDArray ( )
inline
83  {
84  ref_counted.fetch_sub(1, std::memory_order_acq_rel);
85  if (ref_counted == 1 && owned) delete[] data;
86  }

Member Function Documentation

◆ get_data()

template<typename DataType >
decltype(auto) NDArray< DataType >::get_data ( )
inline
89  {
90  ref_counted.fetch_add(1, std::memory_order_relaxed);
91  return data;
92  }

◆ get_vname()

template<typename DataType >
std::string NDArray< DataType >::get_vname ( )
inline
95  {
96  return name;
97  }

◆ get_vshape()

template<typename DataType >
std::vector<size_t> NDArray< DataType >::get_vshape ( )
inline
100  {
101  return shape;
102  }

◆ ndim()

template<typename DataType >
size_t NDArray< DataType >::ndim ( )
inline
105  {
106  size_t num = 1;
107  int isize = static_cast<int>(shape.size());
108  for (auto i=0; i<isize; ++i) num *= shape[i];
109  return num;
110  }

Referenced by NDArray< DataType >::NDArray().

Here is the caller graph for this function:

◆ operator=()

template<typename DataType >
NDArray& NDArray< DataType >::operator= ( const NDArray< DataType > &  array)
inline
73  {
74  name = array.name;
75  shape = array.shape;
76  data = array.data;
77  owned = false;
78  ref_counted.fetch_add(1, std::memory_order_relaxed);
79  return *this;
80  }

◆ set_vshape()

template<typename DataType >
void NDArray< DataType >::set_vshape ( std::vector< size_t >  vshape)
inline
113  {
114  shape = vshape;
115  }

Member Data Documentation

◆ data

◆ name

template<typename DataType >
std::string NDArray< DataType >::name
private

◆ owned

template<typename DataType >
bool NDArray< DataType >::owned
private

◆ ref_counted

template<typename DataType >
std::atomic<size_t> NDArray< DataType >::ref_counted
mutableprivate

◆ shape


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