HILA
|
\( n\times m \) Array type More...
#include <array.h>
Public Member Functions | |
Array ()=default | |
Construct a new Matrix object. | |
constexpr int | rows () const |
Returns number of rows. | |
constexpr int | columns () const |
Returns number of columns. | |
template<int q = n, int p = m, std::enable_if_t< q==1, int > = 0> | |
constexpr int | size () const |
Returns size of Vector Array or square Array. | |
T | e (const int i, const int j) const |
Standard array indexing operation for 2D and 1D Arrays. | |
Matrix< n, m, T > & | asMatrix () |
Cast Array to Matrix. | |
Vector< n, T > & | asVector () |
Cast Array1D to Vector. | |
Array< n, m, T > | operator- () const |
Unary - operator. | |
Array< n, m, T > | operator+ () const |
Unary + operator. | |
template<typename S , std::enable_if_t< hila::is_assignable< T &, S >::value, int > = 0> | |
Array< n, m, T > & | operator= (const S rhs) & |
Assignment operator = to assign values to Array. | |
template<typename S , int n1, int m1> | |
bool | operator== (const Array< n1, m1, S > &rhs) const |
Compare equality of Arrays. | |
template<typename S , int n1, int m1> | |
bool | operator!= (const Array< n1, m1, S > &rhs) const |
Compare non-equality of two Arrays. | |
template<typename S , std::enable_if_t< std::is_convertible< S, T >::value, int > = 0> | |
Array< n, m, T > & | operator+= (const Array< n, m, S > &rhs) & |
Add assign operator with Array or scalar. | |
template<typename S , std::enable_if_t< std::is_convertible< S, T >::value, int > = 0> | |
Array< n, m, T > & | operator-= (const Array< n, m, S > &rhs) & |
Subtract assign operator with Array or scalar. | |
template<typename S , std::enable_if_t< std::is_convertible< hila::type_mul< T, S >, T >::value, int > = 0> | |
Array< n, m, T > & | operator*= (const Array< n, m, S > &rhs) & |
Multiply assign scalar or array. | |
template<typename S , std::enable_if_t< std::is_convertible< hila::type_mul< T, S >, T >::value, int > = 0> | |
Array< n, m, T > & | operator*= (const S rhs) & |
multiply assign with scalar | |
template<typename S , std::enable_if_t< std::is_convertible< hila::type_div< T, S >, T >::value, int > = 0> | |
Array< n, m, T > & | operator/= (const Array< n, m, S > &rhs) & |
Division assign with array or scalar. | |
Array< n, m, T > | conj () const |
Returns element wise Complex conjugate of Array. | |
Array< n, m, hila::arithmetic_type< T > > | real () const |
Returns real part of Array. | |
Array< n, m, hila::arithmetic_type< T > > | imag () const |
return imaginary part | |
hila::arithmetic_type< T > | squarenorm () const |
calculate square norm - sum of squared elements | |
Array< n, m, T > & | random () |
Fill Array with random elements. | |
Array< n, m, T > & | gaussian_random (double width=1.0) |
Fill Array with Gaussian random elements. | |
std::string | str (int prec=8, char separator=' ') const |
Convert to string for printing. | |
template<int N> | |
Array< n, m, T > | sort (Vector< N, int > &permutation, hila::sort order=hila::sort::ascending) const |
implement sort as casting to array | |
\( n\times m \) Array type
Acts as array class which stores data in a simple C style array.
Main functionality which the Array class offers is to supplement the fall backs of storing information in a Matrix data structure.
For example assigning a value to each element with the Matrix class is not directly possible using the assignment operator=. This is because assignment with matrices is defined as \( M = a = a*I \) where M is a general matrix, a is a scalar and I an identity matrix. The result would only assign a to the diagonal elements.
Unlike the Matrix object, the Array object assigns element wise. This allows filling the Array with the assignment operator. Additionally element wise operations are useable as long as they are defined for the Array type. For example the operation:
is defined, since the \(sin\) function is defined for doubles.
The above operation would not work for matrices, but with casting operations. Matrix::asArray and Array::asMatrix one can take full advantage of element wise operations.
n | Number of rows |
m | Number of columns |
T | Array element type |
Construct a new Matrix object.
The following ways of constructing a matrix are:
NOTE: n,m are integers and MyType is a HILA standard type or Complex.
Default constructor:
Allocates undefined \( n\times m\) Array.
Scalar constructor:
Construct with given scalar which is assigned to all elements in array
Copy constructor:
Construction from previously defined Array.
Initializer list:
Construction from c++ initializer list.
|
inlineconstexpr |
|
inline |
Standard array indexing operation for 2D and 1D Arrays.
Accessing singular elements is insufficient, but matrix elements are often quite small.
Exammple for 2D Array:
Example for Vector Array:
i | row index |
j | column index |
|
inline |
Compare non-equality of two Arrays.
Negation of operator==()
S | |
n1 | |
m1 |
rhs |
|
inline |
Multiply assign scalar or array.
Multiplication works element wise
Multiply assign operator can be used in the following ways
Multiply assign Array:
Multiply assign scalar:
S |
rhs |
|
inline |
Add assign operator with Array or scalar.
Add assign operator can be used in the following ways
Add assign Array:
Requires that Arrays have same dimensions
Add assign scalar:
Adds scalar \( a \) to Array uniformly
S | Element type of rhs |
rhs | Array to add |
|
inline |
Subtract assign operator with Array or scalar.
Subtract assign operator can be used in the following ways
Subtract assign Array:
Subtract assign scalar:
Subtract scalar uniformly from square matrix
S |
rhs |
|
inline |
Division assign with array or scalar.
Division works element wise
Division assign operator can be used in the following ways
Division assign Array:
Division assign scalar:
S |
rhs |
|
inline |
Assignment operator = to assign values to Array.
The following ways to assign an Array are:
Assignment from Array:
Assignment from scalar:
Assignment from scalar assigns the scalar to the diagonal elements as \( A = I\cdot a\)
Initializer list:
Assignment from c++ initializer list.
|
inlineconstexpr |
|
inlineconstexpr |