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 | List of all members
numcxx::TArray1< T > Class Template Reference

Description

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

One dimensional array class.

Instances of this class can be created in various ways. The preferred construction of empty array goes like this:

std::shared_ptr<numcxx::TArray1<double>> pA=numcxx::TArray1<double>::create(n)

As a derived class from numcxx::TArray<T> it is merely a facade to the content in the base class.

An alias numcxx::DArray1 for numcxx::TArray1<double> is available from numcxx.h.

For this class, expression templates are defined in expression.ixx which allow to use these arrays in standard linear algebra expressions.

Examples:
10-numcxx-expressions.cxx, 11-numcxx-ref.cxx, 12-numcxx-sharedptr.cxx, 13-numcxx-lapack.cxx, 15-numcxx-umfpack.cxx, 40-stationary-heat-fe.cxx, 41-stationary-heat-fv.cxx, 42-convtest-fem-sin.cxx, 43-convtest-fvm-sin.cxx, 44-transient-heat-fe.cxx, 45-convdiff1d.cxx, and 46-nonlin-fvm.cxx.

Definition at line 31 of file tarray1.hxx.

+ Inheritance diagram for numcxx::TArray1< T >:
+ Collaboration diagram for numcxx::TArray1< T >:

Public Types

typedef T value_type
 

Public Member Functions

 TArray1 (index n)
 Construct an empty 1D array. More...
 
 TArray1 (const std::initializer_list< T > &il)
 Construct 1D Array from std::initializer list. More...
 
 TArray1 (index n0, T *data, std::function< void(T *p)> deleter)
 Construct an 1D array from plain old C Array. More...
 
 TArray1 (index n0, T *data, std::shared_ptr< void > datamanager)
 Construct an 1D array from smartpointer managed array. More...
 
 TArray1 (std::shared_ptr< std::vector< T >> v)
 Construct 1D Array from smart pointer to std::vector. More...
 
std::shared_ptr< TArray1< T > > copy () const
 Create a copy. More...
 
std::shared_ptr< TArray1< T > > clone () const
 Create a clone of the array. More...
 
TArray1< T > & operator= (const TArray1< T > &expr)
 Assignment operator. More...
 
 TArray1 (const TArray1< T > &A)
 Copy constructor. More...
 
 TArray1 (TArray1< T > &&A)
 Move constructor. More...
 
TArray1< T > & operator= (TArray1< T > &&A)
 Move assignment. More...
 
template<typename EXPR , typename = typename std::enable_if<std::is_class<EXPR>::value, EXPR>::type>
 TArray1 (const EXPR &A)
 Copy constructor from expression. More...
 
item (index i0) const
 Element read access. More...
 
void itemset (index i0, T x)
 Element write access. More...
 
__getitem__ (index i0) const
 Element read access. More...
 
void __setitem__ (index i0, T x)
 Element write access. More...
 
bool is_matrix ()
 
 TArray1 ()
 Default constructor. More...
 
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...
 
T * data () const
 Obtain C-pointer of data array. More...
 
void resize (size_t n)
 Resize array. More...
 
void savetxt (std::ostream &s) const
 

Static Public Member Functions

static std::shared_ptr< TArray1< T > > create (index n1)
 Construct smart pointer empty 1D Array. More...
 
static std::shared_ptr< TArray1< T > > create (const std::initializer_list< T > il)
 Construct 1D Array from std::initializer list. More...
 
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...
 
void _nullify ()
 Nullify contents of array (for move constructors) More...
 
void _setshape (index shape0)
 Set shape of 1D array (for move constructors) 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...
 

Member Typedef Documentation

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

Definition at line 30 of file tarray.hxx.

Constructor & Destructor Documentation

template<typename T>
numcxx::TArray1< T >::TArray1 ( index  n)
inline

Construct an empty 1D array.

After construction, the entry values are unitialized

Parameters
n0Size.

Definition at line 46 of file tarray1.hxx.

46 :TArray<T>(n){};
template<typename T>
numcxx::TArray1< T >::TArray1 ( const std::initializer_list< T > &  il)
inline

Construct 1D Array from std::initializer list.

This is the preferable way for small arrays. It allows to write e.g.

TArray1<double> A={1,2,3};

Definition at line 54 of file tarray1.hxx.

54 :TArray<T>(il){};
template<typename T>
numcxx::TArray1< T >::TArray1 ( index  n0,
T *  data,
std::function< void(T *p)>  deleter 
)
inline

Construct an 1D array from plain old C Array.

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

Definition at line 61 of file tarray1.hxx.

61 :TArray<T>(n0,data,deleter){};
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
template<typename T>
numcxx::TArray1< T >::TArray1 ( index  n0,
T *  data,
std::shared_ptr< void >  datamanager 
)
inline

Construct an 1D array from smartpointer managed array.

Parameters
n0Size.
dataPointer to data.
datamanagerSmartpointer to object managing data.
See also
TArray<T>::_datamanager

Definition at line 69 of file tarray1.hxx.

69 :TArray<T>(n0,data,datamanager){};
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
template<typename T>
numcxx::TArray1< T >::TArray1 ( std::shared_ptr< std::vector< T >>  v)
inline

Construct 1D Array from smart pointer to std::vector.

Parameters
vSmart pointer to vector. A copy (increasing refcount) is stored as datamanager in created object.

Definition at line 76 of file tarray1.hxx.

76 :TArray<T>(v->size(),v->data(),v){};
template<typename T>
numcxx::TArray1< T >::TArray1 ( const TArray1< T > &  A)
inline

Copy constructor.

Definition at line 106 of file tarray1.hxx.

106 :TArray1<T>(A.shape(0)){assign(*this,A);}
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>
numcxx::TArray1< T >::TArray1 ( TArray1< T > &&  A)
inline

Move constructor.

Definition at line 109 of file tarray1.hxx.

109  :TArray1<T>(A.shape(0), A._data, [](T*p){;})
110  {
111  TArray<T>::_deleter=std::move(A._deleter);
112  TArray<T>::_datamanager=A._datamanager;
113  A._nullify();
114  }
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183
template<typename T>
template<typename EXPR , typename = typename std::enable_if<std::is_class<EXPR>::value, EXPR>::type>
numcxx::TArray1< T >::TArray1 ( const EXPR &  A)
inline

Copy constructor from expression.

Definition at line 129 of file tarray1.hxx.

129 :TArray1<T>(A.size()){assign(*this,A);}
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>
numcxx::TArray1< T >::TArray1 ( )
inline

Default constructor.

Definition at line 164 of file tarray1.hxx.

164 :TArray<T>(){};

Member Function Documentation

template<typename T>
static std::shared_ptr<TArray1 <T> > numcxx::TArray1< T >::create ( index  n1)
inlinestatic

Construct smart pointer empty 1D Array.

Examples:
12-numcxx-sharedptr.cxx, 14-numcxx-lapack-sharedptr.cxx, and 16-numcxx-umfpack-sharedptr.cxx.

Definition at line 81 of file tarray1.hxx.

81 { return std::make_shared<TArray1 <T> >(n1);}
template<typename T>
static std::shared_ptr<TArray1 <T> > numcxx::TArray1< T >::create ( const std::initializer_list< T >  il)
inlinestatic

Construct 1D Array from std::initializer list.

Static factory method to be used in place of std::make_shared which has problems to detect the type of the initializer_list.

Definition at line 88 of file tarray1.hxx.

88 {return std::make_shared<TArray1 <T> >(il);}
template<typename T>
std::shared_ptr<TArray1 <T> > numcxx::TArray1< T >::copy ( ) const
inline

Create a copy.

Definition at line 92 of file tarray1.hxx.

92 {return std::make_shared<TArray1 <T>>(*this); }
template<typename T>
std::shared_ptr<TArray1 <T> > numcxx::TArray1< T >::clone ( ) const
inline

Create a clone of the array.

Returns
Array of the same size with empty contents.

Definition at line 98 of file tarray1.hxx.

98 { return create(size()); }
size_t size() const
Obtain size of array.
Definition: tarray.hxx:58
static std::shared_ptr< TArray1< T > > create(index n1)
Construct smart pointer empty 1D Array.
Definition: tarray1.hxx:81

+ Here is the call graph for this function:

template<typename T>
TArray1<T>& numcxx::TArray1< T >::operator= ( const TArray1< T > &  expr)
inline

Assignment operator.

Definition at line 103 of file tarray1.hxx.

103 {return static_cast<TArray1<T>&>(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>
TArray1<T>& numcxx::TArray1< T >::operator= ( TArray1< T > &&  A)
inline

Move assignment.

Definition at line 117 of file tarray1.hxx.

117  {
119  TArray<T>::_setshape(A.shape(0));
120  TArray<T>::_data=A._data;
121  TArray<T>::_deleter=A._deleter;
122  TArray<T>::_datamanager=A._datamanager;
123  A._nullify();
124  return *this;
125  }
std::function< void(T *p)> _deleter
Deleter method.
Definition: tarray.hxx:172
T * _data
Data pointer.
Definition: tarray.hxx:186
void _setshape(index shape0)
Set shape of 1D array (for move constructors)
Definition: tarray.ixx:266
std::shared_ptr< void > _datamanager
Data manager.
Definition: tarray.hxx:183

+ Here is the call graph for this function:

template<typename T>
T numcxx::TArray1< T >::item ( index  i0) const
inline

Element read access.

Parameters
i0Index of element to be accessed.
Returns
Value of element at i0

Definition at line 135 of file tarray1.hxx.

135 { 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>
void numcxx::TArray1< T >::itemset ( index  i0,
x 
)
inline

Element write access.

Parameters
i0Index of element to be accessed.
xvalue to be copied to element at index.

Definition at line 142 of file tarray1.hxx.

142 { _data[_idx(i0)]=x;};
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::TArray1< T >::__getitem__ ( index  i0) const
inline

Element read access.

Getter routine for access from python.

Parameters
i0Index of element to be accessed.
Returns
Value of element at i0

Definition at line 150 of file tarray1.hxx.

150 { 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>
void numcxx::TArray1< T >::__setitem__ ( index  i0,
x 
)
inline

Element write access.

Setter routine for access from python.

Parameters
i0Index of element to be accessed.
xvalue to be copied to element at index.

Definition at line 158 of file tarray1.hxx.

158 { _data[_idx(i0)]=x; };
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>
bool numcxx::TArray1< T >::is_matrix ( )
inline

Definition at line 161 of file tarray1.hxx.

161 {return false;};
template<typename T>
T& numcxx::TArray< T >::operator() ( const index  i0)
inlineinherited

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
inlineinherited

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 
)
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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)
inlineinherited

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)
inlineinherited

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)
inlineinherited

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)
inlineinherited

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 
)
inlinestaticinherited

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 
)
inlinestaticinherited

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)
inlineinherited

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
inlineinherited

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>
T* numcxx::TArray< T >::data ( ) const
inlineinherited

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)
inlineinherited

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
inlineinherited

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 >::_assert_square ( ) const
inlineprotectedinherited

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
inlineprotectedinherited

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
inlineprotectedinherited

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
inlineprotectedinherited

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 ( )
inlineprotectedinherited

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)
inlineprotectedinherited

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

Member Data Documentation

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

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
protectedinherited

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
protectedinherited

Data pointer.

Definition at line 186 of file tarray.hxx.


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