NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
numcxx::TArray< T > Class Template Reference

Description

template<typename T>
class numcxx::TArray< T >

TArray is the common template base class for arrays and dense matrices of the numcxx project.

Definition at line 17 of file tarray.hxx.

+ Inheritance diagram for numcxx::TArray< T >:

Public Types

typedef T value_type
 

Public Member Functions

T & operator() (const index i0)
 Access operator for 1D arrays. More...
 
const T & operator() (const index i0) const
 
T & operator() (const index i0, const index i1)
 Access operator for 2D arrays. More...
 
const T & operator() (const index i0, const index i1) const
 
index ndim () const
 Obtain tensor dimension of array. More...
 
size_t size () const
 Obtain size of array. More...
 
index shape (const index dim) const
 Obtain shape of array for given dimension. More...
 
template<typename VAL >
void operator+= (const VAL &a)
 Add value to all elements. More...
 
template<typename VAL >
void operator-= (const VAL &a)
 Subtract value from all elements. More...
 
template<typename VAL >
void operator*= (const VAL &a)
 Multiply all elements by value. More...
 
template<typename VAL >
void operator/= (const VAL &a)
 Divide each element by value. More...
 
T & operator[] (const index i)
 Alternative access operator for 1D arrays. More...
 
const T & operator[] (const index i) const
 Const reference to entry for use in expression templates. More...
 
template<typename VAL >
TArray< T > & operator= (const VAL &expr)
 Expression template compatible assignment operator. More...
 
T * data () const
 Obtain C-pointer of data array. More...
 
void resize (size_t n)
 Resize array. More...
 
 TArray (const TArray< T > &A)=delete
 Copy constructor is deleted. More...
 
void savetxt (std::ostream &s) const
 

Static Public Member Functions

static void operate (std::function< void(T &a, T &b)> f, TArray< T > &A, TArray< T > &B)
 Binary operation on arrays. More...
 
static void operate (std::function< void(T &a, T &b, T &c)> f, TArray< T > &A, TArray< T > &B, TArray< T > &C)
 Ternary operation on arrays. More...
 

Protected Member Functions

void _assert_square () const
 Check if all shapes are the same. More...
 
index _idx (index i0) const
 1D Array index calculation with optional bounds check. More...
 
index _idx (index i0, index i1) const
 2D Array index calculation with optional bounds check. More...
 
index _idx (index i0, index i1, index i2) const
 3D Array index calculation with optional bounds check. More...
 
 TArray ()
 Construct an zero length 1D array. More...
 
void _nullify ()
 Nullify contents of array (for move constructors) More...
 
void _setshape (index shape0)
 Set shape of 1D array (for move constructors) More...
 
 TArray (index n0)
 Construct an empty 1D array of length n0. More...
 
 TArray (const std::initializer_list< T > &il)
 Construct 1D Array from std::initializer list. More...
 
 TArray (index n0, T *data, std::function< void(T *p)> deleter)
 Construct an 1D array from data pointer. More...
 
 TArray (index n0, T *data, std::shared_ptr< void > datamanager)
 Construct an 1D array from data pointer. More...
 
 TArray (index n0, index n1)
 Construct an empty 2D array. More...
 
 TArray (const std::initializer_list< std::initializer_list< T >> &il)
 Construct 2D Array from std::initializer list. More...
 
 TArray (index n0, index n1, T *data, std::function< void(T *p)> deleter)
 Construct a 2D array from data pointer. More...
 
 TArray (index n0, index n1, T *data, std::shared_ptr< void > datamanager)
 Construct a 2D array from data pointer. More...
 
 ~TArray ()
 Destructor. More...
 

Protected Attributes

std::function< void(T *p)> _deleter =nullptr
 Deleter method. More...
 
std::shared_ptr< void > _datamanager =nullptr
 Data manager. More...
 
T * _data =nullptr
 Data pointer. More...
 

Private Member Functions

void _check_bounds (index acc_dim, index acc_ndim, index acc_idx) const
 Bounds checker. More...
 

Private Attributes

const index _ndim
 Tensor dimension. More...
 
size_t _size
 Size of array. More...
 
index _shape [3] ={0,0,0}
 Shape vector. More...
 

Friends

std::ostream & operator (std::ostream &s, TArray< T > &A)
 Print contents of array. More...
 

Member Typedef Documentation

template<typename T>
typedef T numcxx::TArray< T >::value_type

Definition at line 30 of file tarray.hxx.

Constructor & Destructor Documentation

template<typename T>
numcxx::TArray< T >::TArray ( const TArray< T > &  A)
delete

Copy constructor is deleted.

template<typename T >
numcxx::TArray< T >::TArray ( )
inlineprotected

Construct an zero length 1D array.

Definition at line 245 of file tarray.ixx.

245  :
246  _data(0),
247  _size(0),
248  _ndim(1),
249  _shape{0,0},
250  _deleter([](T*p){;})
251  {};
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T >
numcxx::TArray< T >::TArray ( index  n0)
inlineprotected

Construct an empty 1D array of length n0.

Parameters
n0Size.

Definition at line 195 of file tarray.ixx.

195  :
196  _ndim(1),
197  _shape{n0},
198  _size(n0),
199  _data((T*)malloc(sizeof(T)*_size)),
200  _deleter([](T*p){free(p);})
201  {if (_data==nullptr) throw std::runtime_error("numcxx: TArray::TArray(): Memory allocation failed"); };
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T >
numcxx::TArray< T >::TArray ( const std::initializer_list< T > &  il)
inlineprotected

Construct 1D Array from std::initializer list.

Definition at line 12 of file tarray.ixx.

12  :TArray(il.size())
13  {
14  index i=0;
15  for (auto x = il.begin() ; x != il.end(); x++,i++) _data[i]= *x;
16  }
TArray()
Construct an zero length 1D array.
Definition: tarray.ixx:245
unsigned int index
Definition: numcxx.hxx:21
T * _data
Data pointer.
Definition: tarray.hxx:186
template<typename T >
numcxx::TArray< T >::TArray ( index  n0,
T *  data,
std::function< void(T *p)>  deleter 
)
inlineprotected

Construct an 1D array from data pointer.

Parameters
n0Size.
dataPointer to data.
deleterDeleter method,
See also
TArray<T>::_deleter

Definition at line 204 of file tarray.ixx.

204  :
205  _data(data),
206  _ndim(1),
207  _shape{n0},
208  _size(n0),
209  _deleter(deleter)
210  {};
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
template<typename T >
numcxx::TArray< T >::TArray ( index  n0,
T *  data,
std::shared_ptr< void >  datamanager 
)
inlineprotected

Construct an 1D array from data pointer.

Parameters
n0Size.
dataPointer to data.
deleterDeleter method.
See also
TArray<T>::_datamanager

Definition at line 213 of file tarray.ixx.

213  :
214  TArray(n0,data,[](T*p){;}){_datamanager=datamanager;};
TArray()
Construct an zero length 1D array.
Definition: tarray.ixx:245
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
template<typename T >
numcxx::TArray< T >::TArray ( index  n0,
index  n1 
)
inlineprotected

Construct an empty 2D array.

Parameters
n0Number of rows
n1Number of columns

Definition at line 186 of file tarray.ixx.

186  :
187  _ndim(2),
188  _shape{n0,n1},
189  _size((size_t)n0*(size_t)n1),
190  _data((T*)malloc(sizeof(T)*_size)),
191  _deleter([](T*p){free(p);})
192  {if (_data==nullptr) throw std::runtime_error("numcxx: TArray::TArray(): Memory allocation failed"); };
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T >
numcxx::TArray< T >::TArray ( const std::initializer_list< std::initializer_list< T >> &  il)
inlineprotected

Construct 2D Array from std::initializer list.

Definition at line 20 of file tarray.ixx.

20  :
21  TArray(il.size(), il.begin()->size())
22  {
23  index i=0;
24 
25  for (auto jl = il.begin() ; jl != il.end(); jl++,i++)
26  {
27  index j=0;
28  for (auto x = jl->begin() ; x != jl->end(); x++,j++)
29  _data[_idx(i,j)]= *x;
30  }
31  }
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
TArray()
Construct an zero length 1D array.
Definition: tarray.ixx:245
unsigned int index
Definition: numcxx.hxx:21
T * _data
Data pointer.
Definition: tarray.hxx:186

+ Here is the call graph for this function:

template<typename T >
numcxx::TArray< T >::TArray ( index  n0,
index  n1,
T *  data,
std::function< void(T *p)>  deleter 
)
inlineprotected

Construct a 2D array from data pointer.

Parameters
n0Number of rows
n1Number of columns
dataPointer to data.
deleterDeleter method,
See also
TArray<T>::_deleter

Definition at line 217 of file tarray.ixx.

217  :
218  _data(data),
219  _ndim(2),
220  _shape{n0,n1},
221  _size(n0*n1),
222  _deleter(deleter)
223  {};
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
template<typename T >
numcxx::TArray< T >::TArray ( index  n0,
index  n1,
T *  data,
std::shared_ptr< void >  datamanager 
)
inlineprotected

Construct a 2D array from data pointer.

Parameters
n0Number of rows
n1Number of columns
dataPointer to data.
deleterDeleter method.
See also
TArray<T>::_datamanager

Definition at line 229 of file tarray.ixx.

229  :
230  TArray(n0,n1,data, [](T*p){;})
231  {_datamanager=datamanager;};
TArray()
Construct an zero length 1D array.
Definition: tarray.ixx:245
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
template<typename T >
numcxx::TArray< T >::~TArray ( )
inlineprotected

Destructor.

Definition at line 234 of file tarray.ixx.

235  {
236  if (_datamanager==nullptr)
237  {
238  _deleter(_data);
239  }
240  // otherwise we assume that datamaager takes care
241  // of the data pointer
242  };
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
T * _data
Data pointer.
Definition: tarray.hxx:186
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183

Member Function Documentation

template<typename T>
T& numcxx::TArray< T >::operator() ( const index  i0)
inline

Access operator for 1D arrays.

Parameters
i0Index of element to be accessed.
Returns
Reference to element to be accessed.

Definition at line 36 of file tarray.hxx.

36 { return _data[_idx(i0)];};
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
T * _data
Data pointer.
Definition: tarray.hxx:186

+ Here is the call graph for this function:

template<typename T>
const T& numcxx::TArray< T >::operator() ( const index  i0) const
inline

Definition at line 37 of file tarray.hxx.

37 { return _data[_idx(i0)];};
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
T * _data
Data pointer.
Definition: tarray.hxx:186

+ Here is the call graph for this function:

template<typename T>
T& numcxx::TArray< T >::operator() ( const index  i0,
const index  i1 
)
inline

Access operator for 2D arrays.

Parameters
i0Row index of element to be accessed.
i0Column index of element to be accessed.
Returns
Reference to element to be accessed.

Definition at line 44 of file tarray.hxx.

44 { return _data[_idx(i0,i1)];};
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
T * _data
Data pointer.
Definition: tarray.hxx:186

+ Here is the call graph for this function:

template<typename T>
const T& numcxx::TArray< T >::operator() ( const index  i0,
const index  i1 
) const
inline

Definition at line 45 of file tarray.hxx.

45 { return _data[_idx(i0,i1)];};
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
T * _data
Data pointer.
Definition: tarray.hxx:186

+ Here is the call graph for this function:

template<typename T>
index numcxx::TArray< T >::ndim ( ) const
inline

Obtain tensor dimension of array.

Tensor dimension is 1 for vectors, 2 for matrices.

Returns
Dimension.

Definition at line 52 of file tarray.hxx.

52 {return _ndim;}
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T>
size_t numcxx::TArray< T >::size ( ) const
inline

Obtain size of array.

This ist the overall number of elements in the array

Returns
Size.
Examples:
11-numcxx-ref.cxx, 12-numcxx-sharedptr.cxx, 44-transient-heat-fe.cxx, and 45-convdiff1d.cxx.

Definition at line 58 of file tarray.hxx.

58 { return _size;}
size_t _size
Size of array.
Definition: tarray.hxx:146
template<typename T>
index numcxx::TArray< T >::shape ( const index  dim) const
inline

Obtain shape of array for given dimension.

For 1D arrays, shape(0) is equivalent to the size For 2D arrays, shape(0) is the number of rows and shape(1) the number of columns. This corresponds to the "row major" storage format.

Parameters
dimTensor dimension.
Returns
Number of elements in given dimension.

Definition at line 68 of file tarray.hxx.

68 {return _shape[dim];}
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
template<typename T>
template<typename VAL >
void numcxx::TArray< T >::operator+= ( const VAL &  a)
inline

Add value to all elements.

Parameters
aSummand for each element.

Definition at line 74 of file tarray.hxx.

74 {xadd(*this,a);}
void xadd(TArray< T > &A, const EXPR &expr, const EXPR *x=0)
Definition: tarray.ixx:54

+ Here is the call graph for this function:

template<typename T>
template<typename VAL >
void numcxx::TArray< T >::operator-= ( const VAL &  a)
inline

Subtract value from all elements.

Parameters
aValue to be subracted from each element.

Definition at line 80 of file tarray.hxx.

80 {xsub(*this,a);}
void xsub(TArray< T > &A, const EXPR &expr, const EXPR *x=0)
Definition: tarray.ixx:73

+ Here is the call graph for this function:

template<typename T>
template<typename VAL >
void numcxx::TArray< T >::operator*= ( const VAL &  a)
inline

Multiply all elements by value.

Parameters
aMultiplicator for each element.

Definition at line 87 of file tarray.hxx.

87 {xmul(*this,a);}
void xmul(TArray< T > &A, const EXPR &expr, const EXPR *x=0)
Definition: tarray.ixx:92

+ Here is the call graph for this function:

template<typename T>
template<typename VAL >
void numcxx::TArray< T >::operator/= ( const VAL &  a)
inline

Divide each element by value.

Parameters
aDivisor for each element.

Definition at line 94 of file tarray.hxx.

94 {xdiv(*this,a);}
void xdiv(TArray< T > &A, const EXPR &expr, const EXPR *x=0)
Definition: tarray.ixx:111

+ Here is the call graph for this function:

template<typename T >
void numcxx::TArray< T >::operate ( std::function< void(T &a, T &b)>  f,
TArray< T > &  A,
TArray< T > &  B 
)
inlinestatic

Binary operation on arrays.

Parameters
fFunction performing operation for each index.
AFirst array argument.
BSecond array argument.

Definition at line 314 of file tarray.ixx.

315  {
316  for(index i=0;i<A._size;i++) f(A._data[i],B._data[i]);
317  }
unsigned int index
Definition: numcxx.hxx:21
double B(double x)
template<typename T >
void numcxx::TArray< T >::operate ( std::function< void(T &a, T &b, T &c)>  f,
TArray< T > &  A,
TArray< T > &  B,
TArray< T > &  C 
)
inlinestatic

Ternary operation on arrays.

Parameters
fFunction performing operation for each index.
AFirst array argument.
BSecond array argument.
CThird array argument.

Definition at line 320 of file tarray.ixx.

321  {
322  for(index i=0;i<A._size;i++) f(A._data[i],B._data[i],C._data[i]);
323  }
unsigned int index
Definition: numcxx.hxx:21
double B(double x)
template<typename T>
T& numcxx::TArray< T >::operator[] ( const index  i)
inline

Alternative access operator for 1D arrays.

Definition at line 115 of file tarray.hxx.

115 { return _data[i];}
T * _data
Data pointer.
Definition: tarray.hxx:186
template<typename T>
const T& numcxx::TArray< T >::operator[] ( const index  i) const
inline

Const reference to entry for use in expression templates.

Definition at line 118 of file tarray.hxx.

118 { return _data[i];};
T * _data
Data pointer.
Definition: tarray.hxx:186
template<typename T>
template<typename VAL >
TArray<T>& numcxx::TArray< T >::operator= ( const VAL &  expr)
inline

Expression template compatible assignment operator.

Definition at line 122 of file tarray.hxx.

122 {return assign(*this,expr);}
TArray< T > & assign(TArray< T > &A, const EXPR &expr, const EXPR *x=0)
Definition: tarray.ixx:35

+ Here is the call graph for this function:

template<typename T>
T* numcxx::TArray< T >::data ( ) const
inline

Obtain C-pointer of data array.

Returns
Address of C-Array managed by the class which holds the data

Definition at line 128 of file tarray.hxx.

128 { return _data;}
T * _data
Data pointer.
Definition: tarray.hxx:186

+ Here is the call graph for this function:

template<typename T >
void numcxx::TArray< T >::resize ( size_t  n)
inline

Resize array.

Definition at line 282 of file tarray.ixx.

283  {
284  if (_size==n) return;
285 
286  if (_ndim>1)
287  {
288  char errormsg[80];
289  snprintf(errormsg,80,"numcxx::TArray::resize: unable to resize 2D Array to 1D.\n");
290  throw std::runtime_error(errormsg);
291  }
292 
293  if (_datamanager==nullptr)
294  {
295  _deleter(_data);
296  _data=(T*)malloc(sizeof(T)*n);
297  if (_data==nullptr) throw std::runtime_error("numcxx: TArray::resize(): Memory allocation failed");
298  _deleter=[](T*p){free(p);};
299  _size=n;
300  _shape[0]=n;
301  _shape[1]=0;
302  }
303  else
304  {
305  char errormsg[80];
306  snprintf(errormsg,80,"numcxx::TArray::resize: unable to resize - data managed by different object.\n");
307  throw std::runtime_error(errormsg);
308  }
309  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T >
void numcxx::TArray< T >::savetxt ( std::ostream &  s) const
inline

Definition at line 351 of file tarray.ixx.

352  {
353  if (ndim()==1)
354  for (index i=0;i<size();i++) s << _data[i] << std::endl << std::flush;
355  else
356  {
357  for (index i=0;i<shape(0);i++)
358  {
359  for (index j=0;j<shape(1);j++)
360  s << _data[_idx(i,j)] << " ";
361  s<< std::endl;
362  }
363  s << std::flush;
364  }
365  }
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
size_t size() const
Obtain size of array.
Definition: tarray.hxx:58
unsigned int index
Definition: numcxx.hxx:21
index ndim() const
Obtain tensor dimension of array.
Definition: tarray.hxx:52
T * _data
Data pointer.
Definition: tarray.hxx:186
index shape(const index dim) const
Obtain shape of array for given dimension.
Definition: tarray.hxx:68

+ Here is the call graph for this function:

template<typename T >
void numcxx::TArray< T >::_check_bounds ( index  acc_dim,
index  acc_ndim,
index  acc_idx 
) const
inlineprivate

Bounds checker.

Bounds check is enabled if the code is compiled with -DNUMCXX_CHECK_BOUNDS.

On error it throws std::out_of_range exception.

Parameters
acc_dimDimension to be checked.
acc_ndimTensor dimension to be checked.
acc_dimIndex in dimension acc_dim to be checked.

Definition at line 128 of file tarray.ixx.

129  {
130  if (acc_ndim!=_ndim)
131  {
132  char errormsg[80];
133  snprintf(errormsg,80,"numcxx::TArray::_check_bounds: attempt of %uD access of %uD array",acc_ndim,_ndim);
134  throw std::out_of_range(errormsg);
135  }
136  if ((acc_idx<0) || (acc_idx>=_shape[acc_dim]))
137  {
138  char errormsg[80];
139  snprintf(errormsg,80,"numcxx::TArray::_check_bounds: _shape[%u]=%u but i%u=%u",acc_dim,_shape[acc_dim],acc_dim,acc_idx);
140  throw std::out_of_range(errormsg);
141  }
142  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T >
void numcxx::TArray< T >::_assert_square ( ) const
inlineprotected

Check if all shapes are the same.

Throw an exception on error

Definition at line 145 of file tarray.ixx.

146  {
147  if (_ndim!=2 || _shape[0]!=_shape[1])
148  {
149  char errormsg[80];
150  snprintf(errormsg,80,"numcxx::TArray::_assert_square: unexpected non-equal array dimensions\n");
151  throw std::length_error(errormsg);
152  }
153  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143
template<typename T >
index numcxx::TArray< T >::_idx ( index  i0) const
inlineprotected

1D Array index calculation with optional bounds check.

Definition at line 156 of file tarray.ixx.

157  {
158 #ifdef NUMCXX_CHECK_BOUNDS
159  _check_bounds(0,1,i0);
160 #endif
161  return i0;
162  }
void _check_bounds(index acc_dim, index acc_ndim, index acc_idx) const
Bounds checker.
Definition: tarray.ixx:128

+ Here is the call graph for this function:

template<typename T >
index numcxx::TArray< T >::_idx ( index  i0,
index  i1 
) const
inlineprotected

2D Array index calculation with optional bounds check.

Definition at line 165 of file tarray.ixx.

166  {
167 #ifdef NUMCXX_CHECK_BOUNDS
168  _check_bounds(0,2,i0);
169  _check_bounds(1,2,i1);
170 #endif
171  return i0*_shape[1]+i1;
172  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
void _check_bounds(index acc_dim, index acc_ndim, index acc_idx) const
Bounds checker.
Definition: tarray.ixx:128

+ Here is the call graph for this function:

template<typename T >
index numcxx::TArray< T >::_idx ( index  i0,
index  i1,
index  i2 
) const
inlineprotected

3D Array index calculation with optional bounds check.

Definition at line 175 of file tarray.ixx.

176  {
177 #ifdef NUMCXX_CHECK_BOUNDS
178  _check_bounds(0,3,i0);
179  _check_bounds(1,3,i1);
180  _check_bounds(2,3,i2);
181 #endif
182  return (i0*_shape[0]+i1)*_shape[1]+i2;
183  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
void _check_bounds(index acc_dim, index acc_ndim, index acc_idx) const
Bounds checker.
Definition: tarray.ixx:128

+ Here is the call graph for this function:

template<typename T >
void numcxx::TArray< T >::_nullify ( )
inlineprotected

Nullify contents of array (for move constructors)

Definition at line 254 of file tarray.ixx.

255  {
256  _shape[0]=0;
257  _shape[1]=0;
258  _shape[2]=0;
259  _size=0;
260  _deleter=[](T*p){;};
261  _datamanager=nullptr;
262  _data=nullptr;
263  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
size_t _size
Size of array.
Definition: tarray.hxx:146
T * _data
Data pointer.
Definition: tarray.hxx:186
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183
template<typename T >
void numcxx::TArray< T >::_setshape ( index  shape0)
inlineprotected

Set shape of 1D array (for move constructors)

Definition at line 266 of file tarray.ixx.

267  {
268  if (_ndim!=1)
269  {
270  char errormsg[80];
271  snprintf(errormsg,80,"numcxx::TArray::resize: unable to set 1D shape for 2D array.\n");
272  throw std::runtime_error(errormsg);
273  }
274  _shape[0]=shape0;
275  _shape[1]=0;
276  _shape[2]=0;
277  _size=shape0;
278  }
index _shape[3]
Shape vector.
Definition: tarray.hxx:149
size_t _size
Size of array.
Definition: tarray.hxx:146
const index _ndim
Tensor dimension.
Definition: tarray.hxx:143

Friends And Related Function Documentation

template<typename T>
std::ostream& operator ( std::ostream &  s,
TArray< T > &  A 
)
friend

Print contents of array.

Member Data Documentation

template<typename T>
const index numcxx::TArray< T >::_ndim
private

Tensor dimension.

Definition at line 143 of file tarray.hxx.

template<typename T>
size_t numcxx::TArray< T >::_size
private

Size of array.

Definition at line 146 of file tarray.hxx.

template<typename T>
index numcxx::TArray< T >::_shape[3] ={0,0,0}
private

Shape vector.

Definition at line 149 of file tarray.hxx.

template<typename T>
std::function<void(T*p)> numcxx::TArray< T >::_deleter =nullptr
protected

Deleter method.

This is the proper method to be used to destroy the data pointer in the array if data manager is null. Depending on the way it was constructed, it may do nothing, free the memory, delete[] the memory, or something else.

Definition at line 172 of file tarray.hxx.

template<typename T>
std::shared_ptr<void> numcxx::TArray< T >::_datamanager =nullptr
protected

Data manager.

Smart pointer to some other object managing the data pointer. If it is not nullptr, the deleter is not called and the memory corresponding to the data pointer is freed when the object behind the data manager is destroyed.

An example in case is the use of shared_ptr<vector> v as datamanager and v->data() as data pointer

Definition at line 183 of file tarray.hxx.

template<typename T>
T* numcxx::TArray< T >::_data =nullptr
protected

Data pointer.

Definition at line 186 of file tarray.hxx.


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