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;
55 static constexpr bool is_array() {
109 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
110 explicit inline Array(
const S rhs) {
111 for (
int i = 0; i < n * m; i++) {
117 inline Array(
const std::nullptr_t &z) {
118 for (
int i = 0; i < n * m; i++)
125 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
126 inline Array(std::initializer_list<S> rhs) {
127 assert(rhs.size() == n * m &&
"Array initializer list size must match variable size");
129 for (
auto it = rhs.begin(); it != rhs.end(); it++, i++) {
158 template <
int q = n,
int p = m, std::enable_if_t<q == 1,
int> = 0>
163 template <
int q = n,
int p = m, std::enable_if_t<p == 1,
int> = 0>
164 constexpr int size()
const {
168 template <
int q = n,
int p = m, std::enable_if_t<q == p,
int> = 0>
169 constexpr int size()
const {
195#pragma hila loop_function
196 inline T
e(
const int i,
const int j)
const {
200 inline T &
e(
const int i,
const int j) const_function {
206#pragma hila loop_function
207 template <
int q = n,
int p = m, std::enable_if_t<(q == 1 || p == 1),
int> = 0>
208 inline T
e(
const int i)
const {
212 template <
int q = n,
int p = m, std::enable_if_t<(q == 1 || p == 1),
int> = 0>
213 inline T &
e(
const int i) const_function {
226#pragma hila loop_function
238 static_assert(1 == m,
"asVector() only for column arrays");
242#pragma hila loop_function
244 static_assert(1 == m,
"asVector() only for column arrays");
249 static_assert(1 == m,
"asDiagonalMatrix() only for column arrays");
253#pragma hila loop_function
255 static_assert(1 == m,
"asDiagonalMatrix() only for column arrays");
262 template <typename S, std::enable_if_t<hila::is_assignable<S &, T>::value,
int> = 0>
265 for (
int i = 0; i < n * m; i++) {
279 for (
int i = 0; i < n * m; i++) {
332 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
334 for (
int i = 0; i < n * m; i++) {
340 template <typename S, std::enable_if_t<hila::is_assignable<T &, S>::value,
int> = 0>
342 for (
int i = 0; i < n; i++)
343 for (
int j = 0; j < m; j++) {
344 e(i, j) = rhs.e(i, j);
361 template <
typename S,
int n1,
int m1>
363 if constexpr (n != n1 || m != m1)
366 for (
int i = 0; i < n; i++)
367 for (
int j = 0; j < m; j++) {
368 if (
e(i, j) != rhs.
e(i, j))
387 template <
typename S,
int n1,
int m1>
389 return !(*
this == rhs);
421 template <typename S, std::enable_if_t<std::is_convertible<S, T>::value,
int> = 0>
423 for (
int i = 0; i < n; i++)
424 for (
int j = 0; j < m; j++) {
425 e(i, j) += rhs.e(i, j);
455 template <typename S, std::enable_if_t<std::is_convertible<S, T>::value,
int> = 0>
457 for (
int i = 0; i < n; i++)
458 for (
int j = 0; j < m; j++) {
459 e(i, j) -= rhs.e(i, j);
465 template <
typename S,
466 std::enable_if_t<std::is_convertible<hila::type_plus<T, S>, T>::value,
int> = 0>
468 for (
int i = 0; i < n * m; i++) {
475 template <
typename S,
476 std::enable_if_t<std::is_convertible<hila::type_minus<T, S>, T>::value,
int> = 0>
478 for (
int i = 0; i < n * m; i++) {
510 template <
typename S,
511 std::enable_if_t<std::is_convertible<hila::type_mul<T, S>, T>::value,
int> = 0>
513 for (
int i = 0; i < n; i++)
514 for (
int j = 0; j < m; j++) {
515 e(i, j) *= rhs.e(i, j);
521 template <
typename S,
522 std::enable_if_t<std::is_convertible<hila::type_mul<T, S>, T>::value,
int> = 0>
524 for (
int i = 0; i < n * m; i++) {
556 template <
typename S,
557 std::enable_if_t<std::is_convertible<hila::type_div<T, S>, T>::value,
int> = 0>
559 for (
int i = 0; i < n; i++)
560 for (
int j = 0; j < m; j++) {
561 e(i, j) /= rhs.e(i, j);
567 template <
typename S,
568 std::enable_if_t<std::is_convertible<hila::type_div<T, S>, T>::value,
int> = 0>
570 for (
int i = 0; i < n * m; i++) {
583 for (
int i = 0; i < n * m; i++) {
595 for (
int i = 0; i < m * n; i++) {
604 for (
int i = 0; i < m * n; i++) {
612 hila::arithmetic_type<T> result = 0;
613 for (
int i = 0; i < n * m; i++) {
625 for (
int i = 0; i < n * m; i++) {
638 for (
int i = 0; i < n * m; i++) {
645 std::string
str(
int prec = 8,
char separator =
' ')
const {
646 return this->
asMatrix().str(prec, separator);
653 hila::sort order = hila::sort::ascending)
const {
654 return this->
asMatrix().sort(permutation, order).asArray();
659 return this->
asMatrix().sort(order).asArray();
673template <const
int n, const
int m,
typename T>
687template <const
int n, const
int m,
typename T>
701template <const
int n, const
int m,
typename T>
739template <
int n,
int m,
typename A,
typename B>
742 for (
int i = 0; i < n * m; i++)
743 res.c[i] = a.c[i] * b.c[i];
780template <
int n,
int m,
typename A,
typename B>
783 for (
int i = 0; i < n * m; i++)
784 res.c[i] = a.c[i] - b.c[i];
789template <
int n,
int m,
typename T,
typename S,
790 std::enable_if_t<hila::is_complex_or_arithmetic<S>::value,
int> = 0>
793 for (
int i = 0; i < n * m; i++)
794 res.c[i] = a.c[i] + b;
799template <
int n,
int m,
typename T,
typename S,
800 std::enable_if_t<hila::is_complex_or_arithmetic<S>::value,
int> = 0>
806template <
int n,
int m,
typename T,
typename S,
807 std::enable_if_t<std::is_convertible<hila::type_minus<T, S>, T>::value,
int> = 0>
810 for (
int i = 0; i < n * m; i++)
811 res.c[i] = a.c[i] - b;
816template <
int n,
int m,
typename T,
typename S,
817 std::enable_if_t<std::is_convertible<hila::type_minus<T, S>, T>::value,
int> = 0>
820 for (
int i = 0; i < n * m; i++)
821 res.c[i] = b - a.c[i];
860template <
int n,
int m,
typename T>
868template <
int n,
int m,
typename A,
typename B,
869 std::enable_if_t<!std::is_same<A, B>::value,
int> = 0>
872 using R = hila::type_mul<A, B>;
875 for (
int i = 0; i < n; i++)
876 for (
int j = 0; j < m; j++)
877 res.
e(i, j) = a.
e(i, j) * b.
e(i, j);
915template <
int n,
int m,
typename A,
typename B>
918 for (
int i = 0; i < n; i++)
919 for (
int j = 0; j < m; j++)
920 res.
e(i, j) = a.
e(i, j) / b.
e(i, j);
926template <
int n,
int m,
typename T,
typename S,
927 std::enable_if_t<hila::is_complex_or_arithmetic<S>::value,
int> = 0>
930 for (
int i = 0; i < n * m; i++)
931 res.c[i] = a.c[i] * b;
936template <
int n,
int m,
typename T,
typename S,
937 std::enable_if_t<hila::is_complex_or_arithmetic<S>::value,
int> = 0>
944template <
int n,
int m,
typename T,
typename S,
945 std::enable_if_t<hila::is_complex_or_arithmetic<S>::value,
int> = 0>
948 for (
int i = 0; i < n * m; i++)
949 res.c[i] = a.c[i] / b;
954template <
int n,
int m,
typename T,
typename S,
955 std::enable_if_t<hila::is_complex_or_arithmetic<S>::value,
int> = 0>
958 for (
int i = 0; i < n * m; i++)
959 res.c[i] = b / a.c[i];
976template <
int n,
int m,
typename T>
994template <
int n,
int m,
typename T>
999template <
int n,
int m,
typename T>
1001 return prettyprint(A.
asMatrix(), prec);
1017template <
int n,
int m,
typename T>
1038template <
int n,
int m,
typename T>
1040 for (
int i = 0; i < n * m; i++)
1041 a.c[i] =
sqrt(a.c[i]);
1048template <
int n,
int m,
typename T>
1050 for (
int i = 0; i < n * m; i++)
1051 a.c[i] =
cbrt(a.c[i]);
1058template <
int n,
int m,
typename T>
1060 for (
int i = 0; i < n * m; i++)
1061 a.c[i] =
exp(a.c[i]);
1068template <
int n,
int m,
typename T>
1070 for (
int i = 0; i < n * m; i++)
1071 a.c[i] =
log(a.c[i]);
1078template <
int n,
int m,
typename T>
1080 for (
int i = 0; i < n * m; i++)
1081 a.c[i] =
sin(a.c[i]);
1088template <
int n,
int m,
typename T>
1090 for (
int i = 0; i < n * m; i++)
1091 a.c[i] =
cos(a.c[i]);
1098template <
int n,
int m,
typename T>
1100 for (
int i = 0; i < n * m; i++)
1101 a.c[i] =
tan(a.c[i]);
1108template <
int n,
int m,
typename T>
1110 for (
int i = 0; i < n * m; i++)
1111 a.c[i] =
asin(a.c[i]);
1118template <
int n,
int m,
typename T>
1120 for (
int i = 0; i < n * m; i++)
1121 a.c[i] =
acos(a.c[i]);
1128template <
int n,
int m,
typename T>
1130 for (
int i = 0; i < n * m; i++)
1131 a.c[i] =
atan(a.c[i]);
1138template <
int n,
int m,
typename T>
1140 for (
int i = 0; i < n * m; i++)
1141 a.c[i] =
sinh(a.c[i]);
1148template <
int n,
int m,
typename T>
1150 for (
int i = 0; i < n * m; i++)
1151 a.c[i] =
cosh(a.c[i]);
1158template <
int n,
int m,
typename T>
1160 for (
int i = 0; i < n * m; i++)
1161 a.c[i] =
tanh(a.c[i]);
1168template <
int n,
int m,
typename T>
1170 for (
int i = 0; i < n * m; i++)
1171 a.c[i] =
asinh(a.c[i]);
1178template <
int n,
int m,
typename T>
1180 for (
int i = 0; i < n * m; i++)
1181 a.c[i] =
acosh(a.c[i]);
1188template <
int n,
int m,
typename T>
1190 for (
int i = 0; i < n * m; i++)
1191 a.c[i] =
atanh(a.c[i]);
1203template <
int n,
int m,
typename T>
1205 for (
int i = 0; i < n * m; i++)
1206 a.c[i] =
pow(a.c[i], b);
1210template <
int n,
int m,
typename T>
1212 for (
int i = 0; i < n * m; i++)
1213 a.c[i] =
pow(a.c[i], b);
1217template <
int n,
int m,
typename T>
1219 for (
int i = 0; i < n * m; i++)
1220 a.c[i] =
pow(a.c[i], b.c[i]);
1229template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1231 for (
int i = 0; i < n * m; i++)
1232 a.c[i] =
round(a.c[i]);
1241template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1243 for (
int i = 0; i < n * m; i++)
1244 a.c[i] =
floor(a.c[i]);
1253template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1255 for (
int i = 0; i < n * m; i++)
1256 a.c[i] =
ceil(a.c[i]);
1265template <int n, int m, typename T, std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1267 for (
int i = 0; i < n * m; i++)
1268 a.c[i] =
trunc(a.c[i]);
1287template <
typename Ntype,
typename T,
int n,
int m,
1288 std::enable_if_t<hila::is_arithmetic<T>::value,
int> = 0>
1291 for (
int i = 0; i < n * m; i++)
1292 res.c[i] = mat.c[i];
1296template <
typename Ntype,
typename T,
int n,
int m,
1297 std::enable_if_t<hila::is_complex<T>::value,
int> = 0>
1300 for (
int i = 0; i < n * m; i++)
1301 res.c[i] = cast_to<Ntype>(mat.c[i]);
1307template <
int n,
typename T =
double>
1311template <
int n,
int m,
typename T =
double>
Array< n, m, T > conj(const Array< n, m, T > &arg)
Return conjugate Array.
auto operator/(const Array< n, m, A > &a, const Array< n, m, B > &b)
Division operator.
std::ostream & operator<<(std::ostream &strm, const Array< n, m, T > &A)
Stream operator.
Array< n, m, T > floor(Array< n, m, T > a)
Floor.
Array< n, m, T > round(Array< n, m, T > a)
Rounding.
Array< n, m, T > asin(Array< n, m, T > a)
Inverse Sine.
auto operator-(const Array< n, m, A > &a, const Array< n, m, B > &b)
Subtraction operator.
Array< n, m, T > exp(Array< n, m, T > a)
Exponential.
Array< n, m, T > tanh(Array< n, m, T > a)
Hyperbolic tangent.
Array< n, m, T > trunc(Array< n, m, T > a)
Truncation.
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, T > cosh(Array< n, m, T > a)
Hyperbolic Cosine.
Array< n, m, T > tan(Array< n, m, T > a)
Tangent.
auto operator+(const Array< n, m, A > &a, const Array< n, m, B > &b)
Addition operator.
Array< n, m, T > cos(Array< n, m, T > a)
Cosine.
Array< n, m, T > cbrt(Array< n, m, T > a)
Cuberoot.
Array< n, m, T > acos(Array< n, m, T > a)
Inverse Cosine.
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 > asinh(Array< n, m, T > a)
Inverse Hyperbolic Sine.
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*(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, hila::arithmetic_type< T > > real(const Array< n, m, T > &arg)
Return real part of Array.
Array< n, m, T > atanh(Array< n, m, T > a)
Inverse Hyperbolic Tangent.
Array< n, m, T > log(Array< n, m, T > a)
Logarithm.
Array< n, m, T > & operator+=(const Array< n, m, S > &rhs) &
Add assign operator with Array or scalar.
constexpr int rows() const
Returns number of rows.
constexpr int size() const
Returns size of Vector Array or square Array.
Array< n, m, T > & operator=(const S rhs) &
Assignment operator = to assign values to Array.
std::string str(int prec=8, char separator=' ') const
Convert to string for printing.
Array< n, m, T > operator+() const
Unary + operator.
bool operator==(const Array< n1, m1, S > &rhs) const
Compare equality of Arrays.
Array< n, m, T > & operator/=(const Array< n, m, S > &rhs) &
Division assign with array or scalar.
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()=default
Construct a new Matrix object.
Array< n, m, T > & operator*=(const S rhs) &
multiply assign with scalar
Array< n, m, hila::arithmetic_type< T > > imag() const
return imaginary part
Array< n, m, T > operator-() const
Unary - operator.
Array< n, m, T > & operator-=(const Array< n, m, S > &rhs) &
Subtract assign operator with Array or scalar.
constexpr int columns() const
Returns number of columns.
T e(const int i, const int j) const
Standard array indexing operation for 2D and 1D Arrays.
bool operator!=(const Array< n1, m1, S > &rhs) const
Compare non-equality of two Arrays.
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 > conj() const
Returns element wise Complex conjugate of Array.
Matrix< n, m, T > & asMatrix()
Cast Array to Matrix.
Array< n, m, T > & random()
Fill Array with random elements.
Array< n, m, T > & operator*=(const Array< n, m, S > &rhs) &
Multiply assign scalar or array.
Array< n, m, T > & gaussian_random(double width=1.0)
Fill Array with Gaussian random elements.
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.
Implement hila::swap for gauge fields.
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