10#if !defined(MiniTensor_TensorBase_h)
11#define MiniTensor_TensorBase_h
60template<
typename T,
typename ST>
116 template<
class ArrayT>
119 Index const dimension,
132 template<
class ArrayT>
135 Index const dimension,
150 template<
class ArrayT>
153 Index const dimension,
170 template<
class ArrayT>
173 Index const dimension,
192 template<
class ArrayT>
195 Index const dimension,
216 template<
class ArrayT>
219 Index const dimension,
297 template<
class ArrayT>
310 template<
class ArrayT>
325 template<
class ArrayT>
342 template<
class ArrayT>
361 template<
class ArrayT>
382 template<
class ArrayT>
415 template<
typename S,
typename SS>
424 template<
typename S,
typename SS>
494template<
typename T,
typename ST>
497norm_f(TensorBase<T, ST>
const & X);
502template<
typename T,
typename ST>
510template<
typename R,
typename S,
typename T,
typename SR,
typename SS,
515 TensorBase<R, SR>
const & A,
516 TensorBase<S, SS>
const & B,
517 TensorBase<T, ST> & C);
522template<
typename R,
typename S,
typename T,
typename SR,
typename SS,
527 TensorBase<R, SR>
const & A,
528 TensorBase<S, SS>
const & B,
529 TensorBase<T, ST> & C);
534template<
typename T,
typename ST>
537minus(TensorBase<T, ST>
const & A, TensorBase<T, ST> & B);
542template<
typename T,
typename ST>
545equal(TensorBase<T, ST>
const & A, TensorBase<T, ST>
const & B);
550template<
typename T,
typename ST>
553not_equal(TensorBase<T, ST>
const & A, TensorBase<T, ST>
const & B);
558template<
typename R,
typename S,
typename T,
typename SR,
typename ST>
561scale(TensorBase<R, SR>
const & A, S
const & s, TensorBase<T, ST> & B);
566template<
typename R,
typename S,
typename T,
typename SR,
typename ST>
569divide(TensorBase<R, SR>
const & A, S
const & s, TensorBase<T, ST> & B);
574template<
typename R,
typename S,
typename T,
typename SR,
typename ST>
577split(TensorBase<R, SR>
const & A, S
const & s, TensorBase<T, ST> & B);
587template<
typename T,
typename ST>
592 static_size = ST::static_size();
594 set_number_components(static_size);
603template<
typename T,
typename ST>
607 set_dimension(dimension, order);
615template<
typename T,
typename ST>
618 Index const dimension,
622 set_dimension(dimension, order);
630template<
typename T,
typename ST>
633 Index const dimension,
637 set_dimension(dimension, order);
645template<
typename T,
typename ST>
646template<
class ArrayT>
649 Index const dimension,
654 set_dimension(dimension, order);
659template<
typename T,
typename ST>
660template<
class ArrayT>
663 Index const dimension,
669 set_dimension(dimension, order);
670 fill(data, index1, index2);
674template<
typename T,
typename ST>
675template<
class ArrayT>
678 Index const dimension,
685 set_dimension(dimension, order);
686 fill(data, index1, index2, index3);
690template<
typename T,
typename ST>
691template<
class ArrayT>
694 Index const dimension,
702 set_dimension(dimension, order);
703 fill(data, index1, index2, index3, index4);
707template<
typename T,
typename ST>
708template<
class ArrayT>
711 Index const dimension,
720 set_dimension(dimension, order);
721 fill(data, index1, index2, index3, index4, index5);
725template<
typename T,
typename ST>
726template<
class ArrayT>
729 Index const dimension,
739 set_dimension(dimension, order);
740 fill(data, index1, index2, index3, index4, index5, index6);
744template<
typename T,
typename ST>
747 Index const dimension,
751 set_dimension(dimension, order);
759template<
typename T,
typename ST>
762 dimension_(X.dimension_)
769 for (
Index i = 0; i < number_components; ++i) {
779template<
typename T,
typename ST>
784 if (
this == &X)
return *
this;
791 set_number_components(number_components);
793 for (
Index i = 0; i < number_components; ++i) {
803template<
typename T,
typename ST>
814template<
typename T,
typename ST>
819 dimension_ = dimension;
824 set_number_components(number_components);
832template<
typename T,
typename ST>
837 return components_[i];
843template<
typename T,
typename ST>
848 return components_[i];
854template<
typename T,
typename ST>
859 return components_.size();
865template<
typename T,
typename ST>
870 using S =
typename Sacado::ScalarType<T>::type;
873 old_size = get_number_components();
876 new_size = number_components;
878 if (new_size < old_size) {
879 for (
auto i = new_size; i < old_size; ++i) {
880 auto & entry = (*this)[i];
881 fill_AD<T>(entry, not_a_number<S>());
882 entry = not_a_number<T>();
886 components_.resize(number_components);
888 if (new_size > old_size) {
889 for (
auto i = old_size; i < new_size; ++i) {
890 auto & entry = (*this)[i];
891 fill_AD<T>(entry, not_a_number<S>());
892 entry = not_a_number<T>();
902template<
typename T,
typename ST>
907 using S =
typename Sacado::ScalarType<T>::type;
910 number_components = get_number_components();
915 for (
Index i = 0; i < number_components; ++i) {
916 auto & entry = (*this)[i];
917 fill_AD<T>(entry, S(0));
923 for (
Index i = 0; i < number_components; ++i) {
924 auto & entry = (*this)[i];
925 fill_AD<T>(entry, S(0));
931 for (
Index i = 0; i < number_components; ++i) {
932 auto & entry = (*this)[i];
933 fill_AD<T>(entry, S(0));
934 entry =
static_cast<S
>(i);
939 for (
Index i = 0; i < number_components; ++i) {
940 auto & entry = (*this)[i];
941 fill_AD<T>(entry, not_a_number<S>());
942 entry = not_a_number<S>();
948 for (
Index i = 0; i < number_components; ++i) {
949 auto & entry = (*this)[i];
950 fill_AD<T>(entry, S(0));
955 KOKKOS_IF_ON_DEVICE((
961 for (
Index i = 0; i < number_components; ++i) {
962 auto & entry = (*this)[i];
963 fill_AD<T>(entry, S(0));
964 entry = random_uniform<S>();
968 KOKKOS_IF_ON_DEVICE((
974 for (
Index i = 0; i < number_components; ++i) {
975 auto & entry = (*this)[i];
976 fill_AD<T>(entry, S(0));
977 entry = random_normal<S>();
981 KOKKOS_IF_ON_DEVICE((
986 MT_ERROR_EXIT(
"Unknown or undefined (in execution space) specification of "
987 "value for filling components.");
997template<
typename T,
typename ST>
1002 using S =
typename Sacado::ScalarType<T>::type;
1005 number_components = get_number_components();
1007 for (
Index i = 0; i < number_components; ++i) {
1008 auto & entry = (*this)[i];
1009 fill_AD<T>(entry, S(0));
1019template<
typename T,
typename ST>
1020template<
class ArrayT>
1027 assert(index1 == 0);
1030 number_components = get_number_components();
1033 rank = number_components / data.extent(0);
1042 for (
Index i = 0; i < number_components; ++i) {
1043 (*this)[i] = data(i);
1051template<
typename T,
typename ST>
1052template<
class ArrayT>
1060 assert(index2 == 0);
1063 number_components = get_number_components();
1069 sub_dimension = number_components;
1072 dim = data.extent(1);
1074 while (sub_dimension != 1) {
1076 sub_dimension /= dim;
1079 assert(sub_dimension >= 1);
1090 for (
Index j = 0; j < number_components; ++j) {
1091 (*this)[j] = data(index1, j);
1096 for (
Index i = 0; i < dim; ++i) {
1097 for (
Index j = 0; j < dim; ++j) {
1098 (*this)[dim * i + j] = data(i, j);
1107template<
typename T,
typename ST>
1108template<
class ArrayT>
1117 assert(index3 == 0);
1120 number_components = get_number_components();
1123 dim = data.extent(2);
1129 sub_dimension = number_components;
1131 while (sub_dimension != 1) {
1133 sub_dimension /= dim;
1136 assert(sub_dimension >= 1);
1147 for (
Index k = 0; k < number_components; ++k) {
1148 (*this)[k] = data(index1, index2, k);
1153 for (
Index j = 0; j < dim; ++j) {
1154 for (
Index k = 0; k < dim; ++k) {
1155 (*this)[dim * j + k] = data(index1, j, k);
1161 for (
Index i = 0; i < dim; ++i) {
1162 for (
Index j = 0; j < dim; ++j) {
1163 for (
Index k = 0; k < dim; ++k) {
1164 (*this)[dim * (dim * i + j) + k] = data(i, j, k);
1174template<
typename T,
typename ST>
1175template<
class ArrayT>
1185 assert(index4 == 0);
1188 number_components = get_number_components();
1191 dim = data.extent(2);
1197 sub_dimension = number_components;
1199 while (sub_dimension != 1) {
1201 sub_dimension /= dim;
1204 assert(sub_dimension >= 1);
1215 for (
Index l = 0; l < number_components; ++l) {
1216 (*this)[l] = data(index1, index2, index3, l);
1221 for (
Index k = 0; k < dim; ++k) {
1222 for (
Index l = 0; l < dim; ++l) {
1223 (*this)[dim * k + l] = data(index1, index2, k, l);
1229 for (
Index j = 0; j < dim; ++j) {
1230 for (
Index k = 0; k < dim; ++k) {
1231 for (
Index l = 0; l < dim; ++l) {
1232 (*this)[dim * (dim * j + k) + l] = data(index1, j, k, l);
1239 for (
Index i = 0; i < dim; ++i) {
1240 for (
Index j = 0; j < dim; ++j) {
1241 for (
Index k = 0; k < dim; ++k) {
1242 for (
Index l = 0; l < dim; ++l) {
1243 (*this)[dim * (dim * (dim * i + j) + k) + l] =
1255template<
typename T,
typename ST>
1256template<
class ArrayT>
1267 assert(index5 == 0);
1270 number_components = get_number_components();
1273 dim = data.extent(2);
1279 sub_dimension = number_components;
1281 while (sub_dimension != 1) {
1283 sub_dimension /= dim;
1286 assert(sub_dimension >= 1);
1297 for (
Index m = 0; m < number_components; ++m) {
1298 (*this)[m] = data(index1, index2, index3, index4, m);
1303 for (
Index l = 0; l < dim; ++l) {
1304 for (
Index m = 0; m < dim; ++m) {
1305 (*this)[dim * l + m] = data(index1, index2, index3, l, m);
1311 for (
Index k = 0; k < dim; ++k) {
1312 for (
Index l = 0; l < dim; ++l) {
1313 for (
Index m = 0; m < dim; ++m) {
1314 (*this)[dim * (dim * k + l) + m] = data(index1, index2, k, l, m);
1321 for (
Index j = 0; j < dim; ++j) {
1322 for (
Index k = 0; k < dim; ++k) {
1323 for (
Index l = 0; l < dim; ++l) {
1324 for (
Index m = 0; m < dim; ++m) {
1325 (*this)[dim * (dim * (dim * j + k) + l) + m] =
1326 data(index1, j, k, l, m);
1334 for (
Index i = 0; i < dim; ++i) {
1335 for (
Index j = 0; j < dim; ++j) {
1336 for (
Index k = 0; k < dim; ++k) {
1337 for (
Index l = 0; l < dim; ++l) {
1338 for (
Index m = 0; m < dim; ++m) {
1339 (*this)[dim * (dim * (dim * (dim * i + j) + k) + l) + m] =
1340 data(i, j, k, l, m);
1352template<
typename T,
typename ST>
1353template<
class ArrayT>
1365 assert(index6 == 0);
1368 number_components = get_number_components();
1371 dim = data.extent(2);
1377 sub_dimension = number_components;
1379 while (sub_dimension != 1) {
1381 sub_dimension /= dim;
1384 assert(sub_dimension >= 1);
1395 for (
Index n = 0; n < number_components; ++n) {
1396 (*this)[n] = data(index1, index2, index3, index4, index5, n);
1401 for (
Index m = 0; m < dim; ++m) {
1402 for (
Index n = 0; n < dim; ++n) {
1403 (*this)[dim * m + n] = data(index1, index2, index3, index4, m, n);
1409 for (
Index l = 0; l < dim; ++l) {
1410 for (
Index m = 0; m < dim; ++m) {
1411 for (
Index n = 0; n < dim; ++n) {
1412 (*this)[dim * (dim * l + m) + n] =
1413 data(index1, index2, index3, l, m, n);
1420 for (
Index k = 0; k < dim; ++k) {
1421 for (
Index l = 0; l < dim; ++l) {
1422 for (
Index m = 0; m < dim; ++m) {
1423 for (
Index n = 0; n < dim; ++n) {
1424 (*this)[dim * (dim * (dim * k + l) + m) + n] =
1425 data(index1, index2, k, l, m, n);
1433 for (
Index j = 0; j < dim; ++j) {
1434 for (
Index k = 0; k < dim; ++k) {
1435 for (
Index l = 0; l < dim; ++l) {
1436 for (
Index m = 0; m < dim; ++m) {
1437 for (
Index n = 0; n < dim; ++n) {
1438 (*this)[dim * (dim * (dim * (dim * j + k) + l) + m) + n] =
1439 data(index1, j, k, l, m, n);
1448 for (
Index i = 0; i < dim; ++i) {
1449 for (
Index j = 0; j < dim; ++j) {
1450 for (
Index k = 0; k < dim; ++k) {
1451 for (
Index l = 0; l < dim; ++l) {
1452 for (
Index m = 0; m < dim; ++m) {
1453 for (
Index n = 0; n < dim; ++n) {
1454 (*this)[dim * (dim * (dim * (dim * (dim *
1455 i + j) + k) + l) + m) + n] = data(i, j, k, l, m, n);
1467template<
typename T,
typename ST>
1472 assert(data_ptr != NULL);
1475 number_components = get_number_components();
1477 for (
Index i = 0; i < number_components; ++i) {
1478 (*this)[i] = data_ptr[i];
1487template<
typename T,
typename ST>
1494 assert(data_ptr != NULL);
1502 switch (number_components) {
1505 self.
fill(data_ptr);
1510 switch (component_order) {
1513 self.
fill(data_ptr);
1520 self[0] = data_ptr[0];
1521 self[4] = data_ptr[1];
1522 self[8] = data_ptr[2];
1524 self[1] = data_ptr[3];
1525 self[5] = data_ptr[4];
1526 self[6] = data_ptr[5];
1528 self[3] = data_ptr[6];
1529 self[7] = data_ptr[7];
1530 self[2] = data_ptr[8];
1534 self[0] = data_ptr[0];
1535 self[4] = data_ptr[1];
1536 self[8] = data_ptr[2];
1538 self[1] = data_ptr[3];
1539 self[5] = data_ptr[4];
1540 self[6] = data_ptr[5];
1542 self[3] = data_ptr[3];
1543 self[7] = data_ptr[4];
1544 self[2] = data_ptr[5];
1562template<
typename T,
typename ST>
1563template<
typename S,
typename SS>
1569 number_components = get_number_components();
1573 for (
Index i = 0; i < number_components; ++i) {
1583template<
typename T,
typename ST>
1584template<
typename S,
typename SS>
1590 number_components = get_number_components();
1594 for (
Index i = 0; i < number_components; ++i) {
1604template<
typename T,
typename ST>
1611 number_components = get_number_components();
1613 for (
Index i = 0; i < number_components; ++i) {
1622template<
typename T,
typename ST>
1629 number_components = get_number_components();
1631 for (
Index i = 0; i < number_components; ++i) {
1640template<
typename T,
typename ST>
1652template<
typename T,
typename ST>
1670template<
typename T,
typename ST>
1678 if (s > 0.0)
return std::sqrt(s);
1686template<
typename R,
typename S,
typename T,
typename SR,
typename SS,
1702 for (
Index i = 0; i < number_components; ++i) {
1712template<
typename R,
typename S,
typename T,
typename SR,
typename SS,
1727 for (
Index i = 0; i < number_components; ++i) {
1737template<
typename T,
typename ST>
1747 for (
Index i = 0; i < number_components; ++i) {
1757template<
typename T,
typename ST>
1767 for (
Index i = 0; i < number_components; ++i) {
1768 if (A[i] != B[i])
return false;
1777template<
typename T,
typename ST>
1782 return !(
equal(A, B));
1788template<
typename R,
typename S,
typename T,
typename SR,
typename ST>
1798 for (
Index i = 0; i < number_components; ++i) {
1808template<
typename R,
typename S,
typename T,
typename SR,
typename ST>
1818 for (
Index i = 0; i < number_components; ++i) {
1828template<
typename R,
typename S,
typename T,
typename SR,
typename ST>
1838 for (
Index i = 0; i < number_components; ++i) {
#define KOKKOS_INLINE_FUNCTION
#define MT_ERROR_EXIT(...)
KOKKOS_INLINE_FUNCTION void clear()
KOKKOS_INLINE_FUNCTION TensorBase< T, ST > & operator*=(S const &X)
KOKKOS_INLINE_FUNCTION void minus(TensorBase< T, ST > const &A, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION void fill(ArrayT &data, Index index1, Index index2, Index index3, Index index4, Index index5, Index index6)
KOKKOS_INLINE_FUNCTION void fill(ArrayT &data, Index index1, Index index2, Index index3, Index index4)
KOKKOS_INLINE_FUNCTION void set_number_components(Index const number_components)
KOKKOS_INLINE_FUNCTION void fill(ArrayT &data, Index index1, Index index2, Index index3, Index index4, Index index5)
KOKKOS_INLINE_FUNCTION void add(TensorBase< R, SR > const &A, TensorBase< S, SS > const &B, TensorBase< T, ST > &C)
KOKKOS_INLINE_FUNCTION T const & operator[](Index const i) const
KOKKOS_INLINE_FUNCTION void fill(T const *data_ptr, ComponentOrder const component_order)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, ArrayT &data, Index index1, Index index2, Index index3, Index index4, Index index5)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, ArrayT &data, Index index1, Index index2)
KOKKOS_INLINE_FUNCTION T norm_f(TensorBase< T, ST > const &X)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, ArrayT &data, Index index1, Index index2, Index index3, Index index4)
KOKKOS_INLINE_FUNCTION bool equal(TensorBase< T, ST > const &A, TensorBase< T, ST > const &B)
KOKKOS_INLINE_FUNCTION void fill(T const &s)
KOKKOS_INLINE_FUNCTION TensorBase< T, ST > & operator-=(TensorBase< S, SS > const &X)
KOKKOS_INLINE_FUNCTION void fill(ArrayT &data, Index index1, Index index2)
KOKKOS_INLINE_FUNCTION void fill(ArrayT &data, Index index1, Index index2, Index index3)
KOKKOS_INLINE_FUNCTION Index get_dimension(Index const order) const
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, ArrayT &data, Index index1)
KOKKOS_INLINE_FUNCTION void fill(T const *data_ptr)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, ArrayT &data, Index index1, Index index2, Index index3)
KOKKOS_INLINE_FUNCTION void fill(Filler const value)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order)
KOKKOS_INLINE_FUNCTION T norm_f_square(TensorBase< T, ST > const &X)
KOKKOS_INLINE_FUNCTION TensorBase()
KOKKOS_INLINE_FUNCTION void scale(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, T const *data_ptr)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, T const &s)
KOKKOS_INLINE_FUNCTION TensorBase< T, ST > & operator/=(S const &X)
KOKKOS_INLINE_FUNCTION TensorBase< T, ST > & operator=(TensorBase< T, ST > const &X)
KOKKOS_INLINE_FUNCTION T & operator[](Index const i)
KOKKOS_INLINE_FUNCTION void split(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION TensorBase(TensorBase< T, ST > const &X)
KOKKOS_INLINE_FUNCTION TensorBase< T, ST > & operator+=(TensorBase< S, SS > const &X)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, Filler const value)
KOKKOS_INLINE_FUNCTION bool not_equal(TensorBase< T, ST > const &A, TensorBase< T, ST > const &B)
KOKKOS_INLINE_FUNCTION Index get_number_components() const
KOKKOS_INLINE_FUNCTION void set_dimension(Index const dimension, Index const order)
KOKKOS_INLINE_FUNCTION TensorBase(Index const dimension, Index const order, ArrayT &data, Index index1, Index index2, Index index3, Index index4, Index index5, Index index6)
KOKKOS_INLINE_FUNCTION void divide(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION void fill(ArrayT &data, Index index1)
KOKKOS_INLINE_FUNCTION void subtract(TensorBase< R, SR > const &A, TensorBase< S, SS > const &B, TensorBase< T, ST > &C)
uint32_t Index
Indexing type.
KOKKOS_INLINE_FUNCTION T integer_power(T const &X, Index const exponent)