NUMCXX
0.13.20181108
Numerical library for small projects and teaching purposes
|
Two-dimensional array class.
Instances of this class can be created in various ways. The preferred construction of empty array goes like this:
As a derived class from numcxx::TArray<T> it is merely a facade to the content in the base class.
An alias numcxx::DArray2 for numcxx::TArray2<double> is available from numcxx.h.
Definition at line 31 of file tarray2.hxx.
Public Types | |
typedef T | value_type |
Public Member Functions | |
TArray2 (index n0, index n1) | |
Construct an empty 2D array. More... | |
TArray2 (index n0, index n1, T *data, std::function< void(T *p)> deleter) | |
Construct a 2D array from data pointer. More... | |
TArray2 (index n0, index n1, T *data, std::shared_ptr< void > datamanager) | |
Construct a 2D array from data pointer. More... | |
TArray2 (const std::initializer_list< std::initializer_list< T >> &il) | |
Construct 2D Array from std::initializer list. More... | |
TArray2 (const TArray2< T > &A) | |
Copy constructor. More... | |
TArray2< T > & | operator= (const TArray2< T > &expr) |
Assignment operator. More... | |
TArray2 () | |
std::shared_ptr< TArray2< T > > | copy () const |
Create a copy of the array. More... | |
std::shared_ptr< TArray2< T > > | clone () const |
Create a clone of the array. More... | |
T | item (index i0, index i1) |
Element read access. More... | |
void | itemset (index i0, index i1, T x) |
Element write access. More... | |
std::shared_ptr< TArray1< T > > const | __getitem__ (index i0) |
Getter routine for access from python. More... | |
bool | is_matrix () |
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< TArray2< T > > | create (index n0, index n1) |
Construct empty 2D Array. More... | |
static std::shared_ptr< TArray2< T > > | create (const std::initializer_list< std::initializer_list< T >> &il) |
Construct 2D 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... | |
|
inherited |
Definition at line 30 of file tarray.hxx.
|
inline |
Construct an empty 2D array.
n0 | Number of rows |
n1 | Number of columns |
Definition at line 44 of file tarray2.hxx.
|
inline |
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 52 of file tarray2.hxx.
|
inline |
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 62 of file tarray2.hxx.
|
inline |
Construct 2D Array from std::initializer list.
Definition at line 66 of file tarray2.hxx.
|
inline |
Copy constructor.
Definition at line 70 of file tarray2.hxx.
|
inline |
Definition at line 77 of file tarray2.hxx.
|
inline |
Assignment operator.
Definition at line 74 of file tarray2.hxx.
|
inlinestatic |
|
inlinestatic |
Construct 2D Array from std::initializer list.
Definition at line 87 of file tarray2.hxx.
|
inline |
Create a copy of the array.
Definition at line 92 of file tarray2.hxx.
|
inline |
Create a clone of the array.
Definition at line 97 of file tarray2.hxx.
|
inline |
Element read access.
i0 | Row index of element to be accessed. |
i1 | Column index of element to be accessed. |
Definition at line 106 of file tarray2.hxx.
|
inline |
Element write access.
i0 | Row index of element to be accessed. |
i1 | Column index of element to be accessed. |
x | value to be copied to element at index. |
Definition at line 114 of file tarray2.hxx.
|
inline |
Getter routine for access from python.
This access is rather expensive, as it constructs a smart pointer to the row.
i0 | row index of element to be accessed. |
Definition at line 122 of file tarray2.hxx.
|
inline |
Definition at line 125 of file tarray2.hxx.
|
inlineinherited |
Access operator for 1D arrays.
i0 | Index of element to be accessed. |
Definition at line 36 of file tarray.hxx.
|
inlineinherited |
Definition at line 37 of file tarray.hxx.
|
inlineinherited |
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.
|
inlineinherited |
Definition at line 45 of file tarray.hxx.
|
inlineinherited |
Obtain tensor dimension of array.
Tensor dimension is 1 for vectors, 2 for matrices.
Definition at line 52 of file tarray.hxx.
|
inlineinherited |
Obtain size of array.
This ist the overall number of elements in the array
Definition at line 58 of file tarray.hxx.
|
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.
dim | Tensor dimension. |
Definition at line 68 of file tarray.hxx.
|
inlineinherited |
Add value to all elements.
a | Summand for each element. |
Definition at line 74 of file tarray.hxx.
|
inlineinherited |
Subtract value from all elements.
a | Value to be subracted from each element. |
Definition at line 80 of file tarray.hxx.
|
inlineinherited |
Multiply all elements by value.
a | Multiplicator for each element. |
Definition at line 87 of file tarray.hxx.
|
inlineinherited |
Divide each element by value.
a | Divisor for each element. |
Definition at line 94 of file tarray.hxx.
|
inlinestaticinherited |
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.
|
inlinestaticinherited |
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.
|
inlineinherited |
|
inlineinherited |
Const reference to entry for use in expression templates.
Definition at line 118 of file tarray.hxx.
|
inlineinherited |
Obtain C-pointer of data array.
Definition at line 128 of file tarray.hxx.
|
inlineinherited |
Resize array.
Definition at line 282 of file tarray.ixx.
|
inlineinherited |
Definition at line 351 of file tarray.ixx.
|
inlineprotectedinherited |
Check if all shapes are the same.
Throw an exception on error
Definition at line 145 of file tarray.ixx.
|
inlineprotectedinherited |
1D Array index calculation with optional bounds check.
Definition at line 156 of file tarray.ixx.
|
inlineprotectedinherited |
2D Array index calculation with optional bounds check.
Definition at line 165 of file tarray.ixx.
|
inlineprotectedinherited |
3D Array index calculation with optional bounds check.
Definition at line 175 of file tarray.ixx.
|
inlineprotectedinherited |
Nullify contents of array (for move constructors)
Definition at line 254 of file tarray.ixx.
|
inlineprotectedinherited |
|
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.
|
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.
|
protectedinherited |
Data pointer.
Definition at line 186 of file tarray.hxx.