NUMCXX
0.13.20181108
Numerical library for small projects and teaching purposes
|
TArray is the common template base class for arrays and dense matrices of the numcxx project.
Definition at line 17 of file tarray.hxx.
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... | |
typedef T numcxx::TArray< T >::value_type |
Definition at line 30 of file tarray.hxx.
|
delete |
Copy constructor is deleted.
|
inlineprotected |
Construct an zero length 1D array.
Definition at line 245 of file tarray.ixx.
|
inlineprotected |
Construct an empty 1D array of length n0.
n0 | Size. |
Definition at line 195 of file tarray.ixx.
|
inlineprotected |
|
inlineprotected |
Construct an 1D array from data pointer.
n0 | Size. |
data | Pointer to data. |
deleter | Deleter method, |
Definition at line 204 of file tarray.ixx.
|
inlineprotected |
Construct an 1D array from data pointer.
n0 | Size. |
data | Pointer to data. |
deleter | Deleter method. |
Definition at line 213 of file tarray.ixx.
|
inlineprotected |
Construct an empty 2D array.
n0 | Number of rows |
n1 | Number of columns |
Definition at line 186 of file tarray.ixx.
|
inlineprotected |
Construct 2D Array from std::initializer list.
Definition at line 20 of file tarray.ixx.
|
inlineprotected |
Construct a 2D array from data pointer.
n0 | Number of rows |
n1 | Number of columns |
data | Pointer to data. |
deleter | Deleter method, |
Definition at line 217 of file tarray.ixx.
|
inlineprotected |
Construct a 2D array from data pointer.
n0 | Number of rows |
n1 | Number of columns |
data | Pointer to data. |
deleter | Deleter method. |
Definition at line 229 of file tarray.ixx.
|
inlineprotected |
Destructor.
Definition at line 234 of file tarray.ixx.
|
inline |
Access operator for 1D arrays.
i0 | Index of element to be accessed. |
Definition at line 36 of file tarray.hxx.
|
inline |
Definition at line 37 of file tarray.hxx.
|
inline |
Access operator for 2D arrays.
i0 | Row index of element to be accessed. |
i0 | Column index of element to be accessed. |
Definition at line 44 of file tarray.hxx.
|
inline |
Definition at line 45 of file tarray.hxx.
|
inline |
Obtain tensor dimension of array.
Tensor dimension is 1 for vectors, 2 for matrices.
Definition at line 52 of file tarray.hxx.
|
inline |
Obtain size of array.
This ist the overall number of elements in the array
Definition at line 58 of file tarray.hxx.
|
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.
dim | Tensor dimension. |
Definition at line 68 of file tarray.hxx.
|
inline |
Add value to all elements.
a | Summand for each element. |
Definition at line 74 of file tarray.hxx.
|
inline |
Subtract value from all elements.
a | Value to be subracted from each element. |
Definition at line 80 of file tarray.hxx.
|
inline |
Multiply all elements by value.
a | Multiplicator for each element. |
Definition at line 87 of file tarray.hxx.
|
inline |
Divide each element by value.
a | Divisor for each element. |
Definition at line 94 of file tarray.hxx.
|
inlinestatic |
Binary operation on arrays.
f | Function performing operation for each index. |
A | First array argument. |
B | Second array argument. |
Definition at line 314 of file tarray.ixx.
|
inlinestatic |
Ternary operation on arrays.
f | Function performing operation for each index. |
A | First array argument. |
B | Second array argument. |
C | Third array argument. |
Definition at line 320 of file tarray.ixx.
|
inline |
|
inline |
Const reference to entry for use in expression templates.
Definition at line 118 of file tarray.hxx.
|
inline |
Expression template compatible assignment operator.
Definition at line 122 of file tarray.hxx.
|
inline |
Obtain C-pointer of data array.
Definition at line 128 of file tarray.hxx.
|
inline |
Resize array.
Definition at line 282 of file tarray.ixx.
|
inline |
Definition at line 351 of file tarray.ixx.
|
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.
acc_dim | Dimension to be checked. |
acc_ndim | Tensor dimension to be checked. |
acc_dim | Index in dimension acc_dim to be checked. |
Definition at line 128 of file tarray.ixx.
|
inlineprotected |
Check if all shapes are the same.
Throw an exception on error
Definition at line 145 of file tarray.ixx.
|
inlineprotected |
1D Array index calculation with optional bounds check.
Definition at line 156 of file tarray.ixx.
|
inlineprotected |
2D Array index calculation with optional bounds check.
Definition at line 165 of file tarray.ixx.
|
inlineprotected |
3D Array index calculation with optional bounds check.
Definition at line 175 of file tarray.ixx.
|
inlineprotected |
Nullify contents of array (for move constructors)
Definition at line 254 of file tarray.ixx.
|
inlineprotected |
|
friend |
Print contents of array.
|
private |
Tensor dimension.
Definition at line 143 of file tarray.hxx.
|
private |
Size of array.
Definition at line 146 of file tarray.hxx.
|
private |
Shape vector.
Definition at line 149 of file tarray.hxx.
|
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.
|
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.
|
protected |
Data pointer.
Definition at line 186 of file tarray.hxx.