NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
tarray2.hxx
Go to the documentation of this file.
1 
7 #ifndef NUMCXX_TARRAY2_H
8 #define NUMCXX_TARRAY2_H
9 
10 #include "tarray.hxx"
11 
12 
13 namespace numcxx
14 {
30  template<typename T>
31  class TArray2: public TArray<T>, public ExpressionBase
32  {
33  public:
34  using TArray<T>::size;
35  using TArray<T>::shape;
36  using TArray<T>::operator[];
37  using TArray<T>::operator=;
38 
39 
44  TArray2(index n0, index n1):TArray<T>(n0,n1) {};
45 
52  TArray2(index n0, index n1, T*data,std::function<void(T*p)> deleter):TArray<T>(n0,n1,data,deleter){};
53 
54 
62  TArray2(index n0, index n1, T*data,std::shared_ptr<void> datamanager):TArray<T>(n0,n1,data,datamanager) {};
63 
64 
66  TArray2(const std::initializer_list<std::initializer_list<T>> &il ):TArray<T>(il){};
67 
68 
70  TArray2(const TArray2<T>& A):TArray2<T>(A.shape(0),A.shape(1)){assign(*this,A);}
71 
72 
74  TArray2<T>& operator=(const TArray2<T> &expr) { return static_cast<TArray2<T>&>(assign(*this,expr));}
75 
76  // Construct zero size array.
77  TArray2():TArray<T>(){};;
78 
79 
83  static std::shared_ptr<TArray2 <T> > create(index n0,index n1) { return std::make_shared<TArray2 <T> >(n0,n1);}
84 
85 
87  static std::shared_ptr<TArray2 <T> > create(const std::initializer_list<std::initializer_list<T>> &il) { return std::make_shared<TArray2 <T> >(il);}
88 
92  std::shared_ptr<TArray2 <T> > copy() const { return std::make_shared<TArray2 <T> >(*this);}
93 
97  std::shared_ptr<TArray2 <T> > clone() const { return create(shape(0),shape(1));}
98 
99 
100 
106  T item(index i0,index i1) { return _data[_idx(i0,i1)];};
107 
108 
114  void itemset(index i0, index i1, T x) { _data[_idx(i0,i1)]=x;};
115 
122  std::shared_ptr<TArray1 <T> > const __getitem__(index i0){ return std::shared_ptr<TArray1<T>>(new TArray1<T>(shape(1), &_data[_idx(i0,0)], [](T*p){;}));}
123 
124 
125  bool is_matrix(){return false;}
126 
127  protected:
128  using TArray<T>::_data;
129  using TArray<T>::_idx;
130  };
131 
132 }
133 
134 #endif
std::shared_ptr< TArray2< T > > clone() const
Create a clone of the array.
Definition: tarray2.hxx:97
TArray2(index n0, index n1, T *data, std::shared_ptr< void > datamanager)
Construct a 2D array from data pointer.
Definition: tarray2.hxx:62
bool is_matrix()
Definition: tarray2.hxx:125
index _idx(index i0) const
1D Array index calculation with optional bounds check.
Definition: tarray.ixx:156
TArray is the common template base class for arrays and dense matrices of the numcxx project...
Definition: tarray.hxx:17
static std::shared_ptr< TArray2< T > > create(index n0, index n1)
Construct empty 2D Array.
Definition: tarray2.hxx:83
TArray2< T > & operator=(const TArray2< T > &expr)
Assignment operator.
Definition: tarray2.hxx:74
TArray2(index n0, index n1)
Construct an empty 2D array.
Definition: tarray2.hxx:44
T item(index i0, index i1)
Element read access.
Definition: tarray2.hxx:106
unsigned int index
Definition: numcxx.hxx:21
TArray2(index n0, index n1, T *data, std::function< void(T *p)> deleter)
Construct a 2D array from data pointer.
Definition: tarray2.hxx:52
One dimensional array class.
Definition: tarray1.hxx:31
TArray2(const std::initializer_list< std::initializer_list< T >> &il)
Construct 2D Array from std::initializer list.
Definition: tarray2.hxx:66
TArray2(const TArray2< T > &A)
Copy constructor.
Definition: tarray2.hxx:70
void itemset(index i0, index i1, T x)
Element write access.
Definition: tarray2.hxx:114
T * _data
Data pointer.
Definition: tarray.hxx:186
Numcxx template library.
Definition: expression.ixx:41
TArray< T > & assign(TArray< T > &A, const EXPR &expr, const EXPR *x=0)
Definition: tarray.ixx:35
index shape(const index dim) const
Obtain shape of array for given dimension.
Definition: tarray.hxx:68
Two-dimensional array class.
Definition: tarray2.hxx:31
static std::shared_ptr< TArray2< T > > create(const std::initializer_list< std::initializer_list< T >> &il)
Construct 2D Array from std::initializer list.
Definition: tarray2.hxx:87
std::shared_ptr< TArray1< T > > const __getitem__(index i0)
Getter routine for access from python.
Definition: tarray2.hxx:122
std::shared_ptr< TArray2< T > > copy() const
Create a copy of the array.
Definition: tarray2.hxx:92
T * data() const
Obtain C-pointer of data array.
Definition: tarray.hxx:128
Header for numcxx::TArray.