42template <const
int n, const
int m,
typename T>
46 "Array requires Complex or arithmetic type");
52 using base_type = hila::arithmetic_type<T>;
53 using argument_type = T;
99 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
100 explicit inline Array(
const S rhs) {
101 for (
int i = 0; i < n * m; i++) {
112#pragma hila loop_function
113 inline Array(
const std::nullptr_t &z) {
114 for (
int i = 0; i < n * m; i++)
133 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
134 inline Array(std::initializer_list<S> rhs) {
135 assert(rhs.size() == n * m &&
"Array initializer list size must match variable size");
137 for (
auto it = rhs.begin(); it != rhs.end(); it++, i++) {
166 template <
int q = n,
int p = m, std::enable_if_t<q == 1,
int> = 0>
171 template <
int q = n,
int p = m, std::enable_if_t<p == 1,
int> = 0>
172 constexpr int size()
const {
176 template <
int q = n,
int p = m, std::enable_if_t<q == p,
int> = 0>
177 constexpr int size()
const {
197 inline T
e(
const int i,
const int j)
const {
203 inline T &
e(
const int i,
const int j) const_function {
209 template <
int q = n,
int p = m, std::enable_if_t<(q == 1 || p == 1),
int> = 0>
210 inline T
e(
const int i)
const {
224 template <
int q = n,
int p = m, std::enable_if_t<(q == 1 || p == 1),
int> = 0>
225 inline T &
e(
const int i) const_function {
249 static_assert(1 == m,
"asVector() only for column arrays");
254 static_assert(1 == m,
"asVector() only for column arrays");
259 static_assert(1 == m,
"asDiagonalMatrix() only for column arrays");
264 static_assert(1 == m,
"asDiagonalMatrix() only for column arrays");
271 template <typename S, std::enable_if_t<hila::is_assignable<S &, T>::value,
int> = 0>
274 for (
int i = 0; i < n * m; i++) {
288 for (
int i = 0; i < n * m; i++) {
319#pragma hila loop_function
320 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
322 for (
int i = 0; i < n * m; i++) {
339 template <
typename S,
int n1,
int m1>
341 if constexpr (n != n1 || m != m1)
344 for (
int i = 0; i < n; i++)
345 for (
int j = 0; j < m; j++) {
346 if (
e(i, j) != rhs.
e(i, j))
365 template <
typename S,
int n1,
int m1>
367 return !(*
this == rhs);
398#pragma hila loop_function
399 template <typename S, std::enable_if_t<std::is_convertible<S, T>::value,
int> = 0>
401 for (
int i = 0; i < n * m; i++) {
432 template <typename S, std::enable_if_t<std::is_convertible<S, T>::value,
int> = 0>
434 for (
int i = 0; i < n * m; i++) {
441 template <
typename S,
442 std::enable_if_t<std::is_convertible<hila::type_plus<T, S>, T>::value,
int> = 0>
444 for (
int i = 0; i < n * m; i++) {
451 template <
typename S,
452 std::enable_if_t<std::is_convertible<hila::type_minus<T, S>, T>::value,
int> = 0>
454 for (
int i = 0; i < n * m; i++) {
486 template <
typename S,
487 std::enable_if_t<std::is_convertible<hila::type_mul<T, S>, T>::value,
int> = 0>
489 for (
int i = 0; i < n * m; i++) {
496 template <
typename S,
497 std::enable_if_t<std::is_convertible<hila::type_mul<T, S>, T>::value,
int> = 0>
499 for (
int i = 0; i < n * m; i++) {
531 template <
typename S,
532 std::enable_if_t<std::is_convertible<hila::type_div<T, S>, T>::value,
int> = 0>
534 for (
int i = 0; i < n * m; i++) {
541 template <
typename S,
542 std::enable_if_t<std::is_convertible<hila::type_div<T, S>, T>::value,
int> = 0>
544 for (
int i = 0; i < n * m; i++) {
557 for (
int i = 0; i < n * m; i++) {
569 for (
int i = 0; i < m * n; i++) {
578 for (
int i = 0; i < m * n; i++) {
586 hila::arithmetic_type<T> result = 0;
587 for (
int i = 0; i < n * m; i++) {
599 for (
int i = 0; i < n * m; i++) {
612 for (
int i = 0; i < n * m; i++) {
619 std::string
str(
int prec = 8,
char separator =
' ')
const {
620 return this->
asMatrix().str(prec, separator);
627 hila::sort order = hila::sort::ascending)
const {
628 return this->
asMatrix().sort(permutation, order).asArray();
633 return this->
asMatrix().sort(order).asArray();
647template <const
int n, const
int m,
typename T>
661template <const
int n, const
int m,
typename T>
675template <const
int n, const
int m,
typename T>
713template <
int n,
int m,
typename T>
752template <
int n,
int m,
typename T>
759template <
int n,
int m,
typename T,
typename S,
760 std::enable_if_t<std::is_convertible<hila::type_plus<T, S>, T>::value,
int> = 0>
767template <
int n,
int m,
typename T,
typename S,
768 std::enable_if_t<std::is_convertible<hila::type_plus<T, S>, T>::value,
int> = 0>
775template <
int n,
int m,
typename T,
typename S,
776 std::enable_if_t<std::is_convertible<hila::type_minus<T, S>, T>::value,
int> = 0>
783template <
int n,
int m,
typename T,
typename S,
784 std::enable_if_t<std::is_convertible<hila::type_minus<S, T>, T>::value,
int> = 0>
786 for (
int i = 0; i < n * m; i++)
787 a.c[i] =
static_cast<T
>(b) - a.c[i];
824template <
int n,
int m,
typename T>
863template <
int n,
int m,
typename T>
870template <
int n,
int m,
typename T,
typename S,
871 std::enable_if_t<std::is_convertible<hila::type_mul<T, S>, T>::value,
int> = 0>
878template <
int n,
int m,
typename T,
typename S,
879 std::enable_if_t<std::is_convertible<hila::type_mul<T, S>, T>::value,
int> = 0>
886template <
int n,
int m,
typename T,
typename S,
887 std::enable_if_t<std::is_convertible<hila::type_div<T, S>, T>::value,
int> = 0>
894template <
int n,
int m,
typename T,
typename S,
895 std::enable_if_t<std::is_convertible<hila::type_div<S, T>, T>::value,
int> = 0>
897 for (
int i = 0; i < n * m; i++)
915template <
int n,
int m,
typename T>
933template <
int n,
int m,
typename T>
938template <
int n,
int m,
typename T>
940 return prettyprint(A.
asMatrix(), prec);
956template <
int n,
int m,
typename T>
978template <
int n,
int m,
typename T>
980 for (
int i = 0; i < n * m; i++)
981 a.c[i] = sqrt(a.c[i]);
988template <
int n,
int m,
typename T>
990 for (
int i = 0; i < n * m; i++)
991 a.c[i] = cbrt(a.c[i]);
998template <
int n,
int m,
typename T>
1000 for (
int i = 0; i < n * m; i++)
1001 a.c[i] = exp(a.c[i]);
1008template <
int n,
int m,
typename T>
1010 for (
int i = 0; i < n * m; i++)
1011 a.c[i] = log(a.c[i]);
1018template <
int n,
int m,
typename T>
1020 for (
int i = 0; i < n * m; i++)
1021 a.c[i] = sin(a.c[i]);
1028template <
int n,
int m,
typename T>
1030 for (
int i = 0; i < n * m; i++)
1031 a.c[i] = cos(a.c[i]);
1038template <
int n,
int m,
typename T>
1040 for (
int i = 0; i < n * m; i++)
1041 a.c[i] = tan(a.c[i]);
1048template <
int n,
int m,
typename T>
1050 for (
int i = 0; i < n * m; i++)
1051 a.c[i] = asin(a.c[i]);
1058template <
int n,
int m,
typename T>
1060 for (
int i = 0; i < n * m; i++)
1061 a.c[i] = acos(a.c[i]);
1068template <
int n,
int m,
typename T>
1070 for (
int i = 0; i < n * m; i++)
1071 a.c[i] = atan(a.c[i]);
1078template <
int n,
int m,
typename T>
1080 for (
int i = 0; i < n * m; i++)
1081 a.c[i] = sinh(a.c[i]);
1088template <
int n,
int m,
typename T>
1090 for (
int i = 0; i < n * m; i++)
1091 a.c[i] = cosh(a.c[i]);
1098template <
int n,
int m,
typename T>
1100 for (
int i = 0; i < n * m; i++)
1101 a.c[i] = tanh(a.c[i]);
1108template <
int n,
int m,
typename T>
1110 for (
int i = 0; i < n * m; i++)
1111 a.c[i] = asinh(a.c[i]);
1118template <
int n,
int m,
typename T>
1120 for (
int i = 0; i < n * m; i++)
1121 a.c[i] = acosh(a.c[i]);
1128template <
int n,
int m,
typename T>
1130 for (
int i = 0; i < n * m; i++)
1131 a.c[i] = atanh(a.c[i]);
1143template <
int n,
int m,
typename T>
1145 for (
int i = 0; i < n * m; i++)
1146 a.c[i] = pow(a.c[i], b);
1150template <
int n,
int m,
typename T>
1152 for (
int i = 0; i < n * m; i++)
1153 a.c[i] = pow(a.c[i], b);
1157template <
int n,
int m,
typename T>
1159 for (
int i = 0; i < n * m; i++)
1160 a.c[i] = pow(a.c[i], b.c[i]);
1169template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1171 for (
int i = 0; i < n * m; i++)
1172 a.c[i] = round(a.c[i]);
1181template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1183 for (
int i = 0; i < n * m; i++)
1184 a.c[i] = floor(a.c[i]);
1193template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1195 for (
int i = 0; i < n * m; i++)
1196 a.c[i] = ceil(a.c[i]);
1205template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1207 for (
int i = 0; i < n * m; i++)
1208 a.c[i] = trunc(a.c[i]);
1227template <
typename Ntype,
typename T,
int n,
int m,
1228 std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1231 for (
int i = 0; i < n * m; i++)
1232 res.c[i] = mat.c[i];
1236template <
typename Ntype,
typename T,
int n,
int m,
1237 std::enable_if_t<hila::is_complex<T>::value,
int> = 0>
1240 for (
int i = 0; i < n * m; i++)
1241 res.c[i] = cast_to<Ntype>(mat.c[i]);
1247template <
int n,
typename T =
double>
1251template <
int n,
int m,
typename T =
double>
Array< n, m, T > conj(const Array< n, m, T > &arg)
Return conjugate Array.
std::ostream & operator<<(std::ostream &strm, const Array< n, m, T > &A)
Stream operator.
Array< n, m, hila::arithmetic_type< T > > imag(const Array< n, m, T > &arg)
Return imaginary part of Array.
hila::arithmetic_type< T > squarenorm(const Array< n, m, T > &rhs)
Return square norm of Array.
Array< n, m, hila::arithmetic_type< T > > real(const Array< n, m, T > &arg)
Return real part of Array.
Array< n, m, T > operator/(Array< n, m, T > a, const Array< n, m, T > &b)
Division operator.
Array(const S rhs)
Scalar constructor.
Array(std::initializer_list< S > rhs)
Initializer list constructor.
Array< n, m, T > & operator+=(const Array< n, m, S > &rhs)
Add assign operator with Array or scalar.
Array< n, m, T > floor(Array< n, m, T > a)
Floor.
constexpr int rows() const
Returns number of rows.
Array(const std::nullptr_t &z)
Zero constructor.
constexpr int size() const
Returns size of Vector Array or square Array.
T & e(const int i, const int j)
Const overload.
std::string str(int prec=8, char separator=' ') const
Convert to string for printing.
Array< n, m, T > round(Array< n, m, T > a)
Rounding.
Array< n, m, T > operator+() const
Unary + operator.
Array< n, m, T > asin(Array< n, m, T > a)
Inverse Sine.
Array< n, m, T > & operator*=(const Array< n, m, S > &rhs)
Multiply assign scalar or array.
bool operator==(const Array< n1, m1, S > &rhs) const
Compare equality of Arrays.
Array< n, m, T > exp(Array< n, m, T > a)
Exponential.
T e(const int i) const
Const overload.
Array< n, m, T > tanh(Array< n, m, T > a)
Hyperbolic tangent.
Array< n, m, T > trunc(Array< n, m, T > a)
Truncation.
T & e(const int i)
Standard array indexing operation for 1D Array.
Array< n, m, T > sort(Vector< N, int > &permutation, hila::sort order=hila::sort::ascending) const
implement sort as casting to array
Array< n, m, hila::arithmetic_type< T > > real() const
Returns real part of Array.
Array< n, m, T > cosh(Array< n, m, T > a)
Hyperbolic Cosine.
Array< n, m, T > operator-(Array< n, m, T > a, const Array< n, m, T > &b)
Subtraction operator.
Array< n, m, T > tan(Array< n, m, T > a)
Tangent.
Array()=default
Default constructor.
Array< n, m, hila::arithmetic_type< T > > imag() const
return imaginary part
Array< n, m, T > & operator/=(const Array< n, m, S > &rhs)
Division assign with array or scalar.
Array< n, m, T > operator-() const
Unary - operator.
constexpr int columns() const
Returns number of columns.
Array< n, m, T > operator+(Array< n, m, T > a, const Array< n, m, T > &b)
Addition operator.
T e(const int i, const int j) const
Standard array indexing operation for 2D Array.
Array< n, m, T > cos(Array< n, m, T > a)
Cosine.
bool operator!=(const Array< n1, m1, S > &rhs) const
Compare non-equality of two Arrays.
Array< n, m, T > cbrt(Array< n, m, T > a)
Cuberoot.
hila::arithmetic_type< T > squarenorm() const
calculate square norm - sum of squared elements
Vector< n, T > & asVector()
Cast Array1D to Vector.
Array< n, m, T > acos(Array< n, m, T > a)
Inverse Cosine.
Array< n, m, T > & operator*=(const S rhs)
multiply assign with scalar
Array< n, m, T > acosh(Array< n, m, T > a)
Inverse Hyperbolic Cosine.
Array< n, m, T > sqrt(Array< n, m, T > a)
Square root.
Array< n, m, T > conj() const
Returns element wise Complex conjugate of Array.
Array< n, m, T > asinh(Array< n, m, T > a)
Inverse Hyperbolic Sine.
Matrix< n, m, T > & asMatrix()
Cast Array to Matrix.
Array< n, m, T > & random()
Fill Array with random elements.
Array< n, m, T > ceil(Array< n, m, T > a)
Ceiling.
Array< n, m, T > atan(Array< n, m, T > a)
Inverse Tangent.
Array< n, m, T > pow(Array< n, m, T > a, int b)
Power.
Array< n, m, T > & operator-=(const Array< n, m, S > &rhs)
Subtract assign operator with Array or scalar.
Array(const Array< n, m, T > &v)=default
Copy constructor.
Array< n, m, T > operator*(Array< n, m, T > a, const Array< n, m, T > &b)
Multiplication operator.
Array< n, m, Ntype > cast_to(const Array< n, m, T > &mat)
Array casting operation.
Array< n, m, T > sin(Array< n, m, T > a)
Sine.
Array< n, m, T > sinh(Array< n, m, T > a)
Hyperbolic Sine.
Array< n, m, T > & gaussian_random(double width=1.0)
Fill Array with Gaussian random elements.
Array< n, m, T > atanh(Array< n, m, T > a)
Inverse Hyperbolic Tangent.
Array< n, m, T > & operator=(const S rhs)
Scalar assignment operator.
Array< n, m, T > log(Array< n, m, T > a)
Logarithm.
Define type DiagonalMatrix<n,T>
Matrix class which defines matrix operations.
T arg(const Complex< T > &a)
Return argument of Complex number.
Definition of Matrix types.
Invert diagonal + const. matrix using Sherman-Morrison formula.
T gaussian_random()
Template function T hila::gaussian_random<T>(),generates gaussian random value of type T,...
double random()
Real valued uniform random number generator.
std::string to_string(const Array< n, m, T > &A, int prec=8, char separator=' ')
Converts Array object to string.
hila::is_complex_or_arithmetic<T>::value