NUMCXX
0.13.20181108
Numerical library for small projects and teaching purposes
|
One 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::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.
Definition at line 31 of file tarray1.hxx.
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... | |
T | item (index i0) const |
Element read access. More... | |
void | itemset (index i0, T x) |
Element write access. More... | |
T | __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... | |
|
inherited |
Definition at line 30 of file tarray.hxx.
|
inline |
Construct an empty 1D array.
After construction, the entry values are unitialized
n0 | Size. |
Definition at line 46 of file tarray1.hxx.
|
inline |
Construct 1D Array from std::initializer list.
This is the preferable way for small arrays. It allows to write e.g.
Definition at line 54 of file tarray1.hxx.
|
inline |
Construct an 1D array from plain old C Array.
n0 | Size. |
data | Pointer to data. |
deleter | Deleter method, |
Definition at line 61 of file tarray1.hxx.
|
inline |
Construct an 1D array from smartpointer managed array.
n0 | Size. |
data | Pointer to data. |
datamanager | Smartpointer to object managing data. |
Definition at line 69 of file tarray1.hxx.
|
inline |
Construct 1D Array from smart pointer to std::vector.
v | Smart pointer to vector. A copy (increasing refcount) is stored as datamanager in created object. |
Definition at line 76 of file tarray1.hxx.
|
inline |
Copy constructor.
Definition at line 106 of file tarray1.hxx.
|
inline |
Move constructor.
Definition at line 109 of file tarray1.hxx.
|
inline |
Copy constructor from expression.
Definition at line 129 of file tarray1.hxx.
|
inline |
|
inlinestatic |
Construct smart pointer empty 1D Array.
Definition at line 81 of file tarray1.hxx.
|
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.
|
inline |
Create a copy.
Definition at line 92 of file tarray1.hxx.
|
inline |
Create a clone of the array.
Definition at line 98 of file tarray1.hxx.
|
inline |
Assignment operator.
Definition at line 103 of file tarray1.hxx.
|
inline |
Move assignment.
Definition at line 117 of file tarray1.hxx.
|
inline |
Element read access.
i0 | Index of element to be accessed. |
Definition at line 135 of file tarray1.hxx.
|
inline |
Element write access.
i0 | Index of element to be accessed. |
x | value to be copied to element at index. |
Definition at line 142 of file tarray1.hxx.
|
inline |
Element read access.
Getter routine for access from python.
i0 | Index of element to be accessed. |
Definition at line 150 of file tarray1.hxx.
|
inline |
Element write access.
Setter routine for access from python.
i0 | Index of element to be accessed. |
x | value to be copied to element at index. |
Definition at line 158 of file tarray1.hxx.
|
inline |
Definition at line 161 of file tarray1.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.