10#if !defined(MiniTensor_Matrix_h)
11#define MiniTensor_Matrix_h
19#include <Kokkos_Core.hpp>
30template<
typename T, Index M, Index N>
36template<
typename T, Index M = DYNAMIC, Index N = DYNAMIC>
111 template<
class ArrayT>
125 template<
class ArrayT>
141 template<
class ArrayT>
159 template<
class ArrayT>
179 template<
class ArrayT>
201 template<
class ArrayT>
221 template<
class ArrayT>
239 template<
class ArrayT>
259 template<
class ArrayT>
281 template<
class ArrayT>
305 template<
class ArrayT>
331 template<
class ArrayT>
351 Matrix(T
const * data_ptr);
397 std::pair<Index, Index>
442template<
typename S,
typename T, Index M, Index N>
444Matrix<typename Promote<S, T>::type, M, N>
445operator+(Matrix<S, M, N>
const & A, Matrix<T, M, N>
const & B);
451template<
typename S,
typename T, Index M, Index N>
453Matrix<typename Promote<S, T>::type, M, N>
454operator-(Matrix<S, M, N>
const & A, Matrix<T, M, N>
const & B);
460template<
typename T, Index M, Index N>
470template<
typename T, Index M, Index N>
473operator==(Matrix<T, M, N>
const & A, Matrix<T, M, N>
const & B);
480template<
typename T, Index M, Index N>
483operator!=(Matrix<T, M, N>
const & A, Matrix<T, M, N>
const & B);
491template<
typename S,
typename T, Index M, Index N>
493Vector<typename Promote<S, T>::type, M>
494operator*(Matrix<T, M, N>
const & A, Vector<S, N>
const & u);
502template<
typename S,
typename T, Index M, Index N>
504Vector<typename Promote<S, T>::type, N>
505operator*(Vector<S, M>
const & u, Matrix<T, M, N>
const & A);
513template<
typename S,
typename T, Index M, Index N>
515Matrix<typename Promote<S, T>::type, M, N>
516operator*(Matrix<T, M, N>
const & A, Tensor<S, N>
const & B);
524template<
typename S,
typename T, Index M, Index N>
526Matrix<typename Promote<S, T>::type, M, N>
527operator*(Tensor<S, M>
const & A, Matrix<T, M, N>
const & B);
533template<
typename S,
typename T, Index M, Index P, Index N>
535Matrix<typename Promote<S, T>::type, M, N>
536operator*(Matrix<S, M, P>
const & A, Matrix<T, P, N>
const & B);
544template<
typename S,
typename T, Index M, Index N>
546typename lazy_disable_if<order_1234<S>, apply_matrix<Promote<S, T>, M, N>>::type
547operator*(S
const & s, Matrix<T, M, N>
const & A);
555template<
typename S,
typename T, Index M, Index N>
557typename lazy_disable_if<order_1234<S>, apply_matrix<Promote<S, T>, M, N>>::type
558operator*(Matrix<T, M, N>
const & A, S
const & s);
566template<
typename S,
typename T, Index M, Index N>
568Matrix<typename Promote<S, T>::type, M, N>
569operator/(Matrix<T, M, N>
const & A, S
const & s);
577template<
typename S,
typename T, Index M, Index N>
579Matrix<typename Promote<S, T>::type, M, N>
580operator/(S
const & s, Matrix<T, M, N>
const & A);
588template<
typename T, Index M, Index N>
590operator>>(std::istream & is, Matrix<T, M, N> & A);
598template<
typename T, Index M, Index N>
600operator<<(std::ostream & os, Matrix<T, M, N>
const & A);
608template<
typename T, Index M, Index N>
611row(Matrix<T, M, N>
const & A,
Index const i);
619template<
typename T, Index M, Index N>
622col(Matrix<T, M, N>
const & A,
Index const j);
630template<
typename S,
typename T, Index M, Index N>
632Vector<typename Promote<S, T>::type, M>
633dot(Matrix<T, M, N>
const & A, Vector<S, N>
const & u);
641template<
typename S,
typename T, Index M, Index N>
643Vector<typename Promote<S, T>::type, N>
644dot(Vector<S, M>
const & u, Matrix<T, M, N>
const & A);
652template<
typename S,
typename T, Index M, Index N>
654Matrix<typename Promote<S, T>::type, M, N>
655dot(Matrix<T, M, N>
const & A, Tensor<S, N>
const & B);
663template<
typename S,
typename T, Index M, Index N>
665Matrix<typename Promote<S, T>::type, M, N>
666dot(Tensor<S, M>
const & A, Matrix<T, M, N>
const & B);
674template<
typename S,
typename T, Index M, Index P, Index N>
676Matrix<typename Promote<S, T>::type, M, N>
677dot(Matrix<S, M, P>
const & A, Matrix<T, P, N>
const & B);
685template<
typename S,
typename T, Index M, Index P, Index N>
687Matrix<typename Promote<S, T>::type, M, N>
688t_dot(Matrix<S, P, M>
const & A, Matrix<T, P, N>
const & B);
696template<
typename S,
typename T, Index M, Index P, Index N>
698Matrix<typename Promote<S, T>::type, M, N>
699dot_t(Matrix<S, M, P>
const & A, Matrix<T, N, P>
const & B);
707template<
typename S,
typename T, Index M, Index P, Index N>
709Matrix<typename Promote<S, T>::type, M, N>
710t_dot_t(Matrix<S, P, M>
const & A, Matrix<T, N, P>
const & B);
718template<
typename S,
typename T, Index M, Index N>
720typename Promote<S, T>::type
721dotdot(Matrix<S, M, N>
const & A, Matrix<T, M, N>
const & B);
729template<
typename S,
typename T, Index M, Index N>
731Matrix<typename Promote<S, T>::type, M, N>
732matrix(Vector<S, M>
const & u, Vector<T, N>
const & v);
737template<
typename T, Index M, Index N>
745template<
typename T, Index M, Index N>
757template<
typename T, Index M, Index N>
766template<
typename T, Index M, Index N>
770 rows_(rows), cols_(cols)
778template<
typename T, Index M, Index N>
786template<
typename T, Index M, Index N>
793 rows_(rows), cols_(cols)
802template<
typename T, Index M, Index N>
803template<
class ArrayT>
814template<
typename T, Index M, Index N>
815template<
class ArrayT>
827template<
typename T, Index M, Index N>
828template<
class ArrayT>
841template<
typename T, Index M, Index N>
842template<
class ArrayT>
863template<
typename T, Index M, Index N>
864template<
class ArrayT>
887template<
typename T, Index M, Index N>
888template<
class ArrayT>
913template<
typename T, Index M, Index N>
914template<
class ArrayT>
923 rows_(rows), cols_(cols)
928template<
typename T, Index M, Index N>
929template<
class ArrayT>
939 rows_(rows), cols_(cols)
944template<
typename T, Index M, Index N>
945template<
class ArrayT>
962 rows_(rows), cols_(cols)
967template<
typename T, Index M, Index N>
968template<
class ArrayT>
987 rows_(rows), cols_(cols)
992template<
typename T, Index M, Index N>
993template<
class ArrayT>
1014 rows_(rows), cols_(cols)
1019template<
typename T, Index M, Index N>
1020template<
class ArrayT>
1043 rows_(rows), cols_(cols)
1048template<
typename T, Index M, Index N>
1056template<
typename T, Index M, Index N>
1061 T
const * data_ptr) :
1063 rows_(rows), cols_(cols)
1071template<
typename T, Index M, Index N>
1075 rows_(A.get_num_rows()), cols_(A.get_num_cols())
1083template<
typename T, Index M, Index N>
1093template<
typename T, Index M, Index N>
1095std::pair<Index, Index>
1098 return std::make_pair(rows_, cols_);
1104template<
typename T, Index M, Index N>
1115template<
typename T, Index M, Index N>
1126template<
typename T, Index M, Index N>
1141template<
typename T, Index M, Index N>
1152 return self[i * num_cols + j];
1158template<
typename T, Index M, Index N>
1169 return self[i * num_cols + j];
1175template<
typename T, Index M, Index N>
1188 for (
Index j = 0; j < num_cols; ++j) {
1211template<
typename T, Index M, Index N>
1224 for (
Index i = 0; i < num_rows; ++i) {
1247template<
typename S,
typename T, Index M, Index N>
1249Matrix<typename Promote<S, T>::type, M, N>
1263template<
typename S,
typename T, Index M, Index N>
1265Matrix<typename Promote<S, T>::type, M, N>
1279template<
typename T, Index M, Index N>
1295template<
typename T, Index M, Index N>
1306template<
typename T, Index M, Index N>
1317template<
typename S,
typename T, Index M, Index N>
1320lazy_disable_if<order_1234<S>, apply_matrix<Promote<S, T>, M, N>>::type
1334template<
typename S,
typename T, Index M, Index N>
1337lazy_disable_if<order_1234<S>, apply_matrix<Promote<S, T>, M, N>>::type
1351template<
typename S,
typename T, Index M, Index N>
1353Matrix<typename Promote<S, T>::type, M, N>
1367template<
typename S,
typename T, Index M, Index N>
1369Matrix<typename Promote<S, T>::type, M, N>
1383template<
typename S,
typename T, Index M, Index N>
1385Vector<typename Promote<S, T>::type, M>
1394template<
typename S,
typename T, Index M, Index N>
1396Vector<typename Promote<S, T>::type, N>
1405template<
typename S,
typename T, Index M, Index N>
1407Matrix<typename Promote<S, T>::type, M, N>
1416template<
typename S,
typename T, Index M, Index N>
1418Matrix<typename Promote<S, T>::type, M, N>
1427template<
typename S,
typename T, Index M, Index P, Index N>
1429Matrix<typename Promote<S, T>::type, M, N>
1438template<
typename S,
typename T, Index M, Index N>
1440Vector<typename Promote<S, T>::type, M>
1454 for (
Index i = 0; i < num_rows; ++i) {
1456 typename Promote<S, T>::type
1459 for (
Index p = 0; p < num_cols; ++p) {
1460 s += A(i, p) * u(p);
1471template<
typename S,
typename T, Index M, Index N>
1473Vector<typename Promote<S, T>::type, N>
1487 for (
Index i = 0; i < num_cols; ++i) {
1489 typename Promote<S, T>::type
1492 for (
Index p = 0; p < num_rows; ++p) {
1493 s += A(p, i) * u(p);
1504template<
typename S,
typename T, Index M, Index N>
1506Matrix<typename Promote<S, T>::type, M, N>
1518 C(num_rows, num_cols);
1520 for (
Index i = 0; i < num_rows; ++i) {
1521 for (
Index j = 0; j < num_cols; ++j) {
1523 typename Promote<S, T>::type
1526 for (
Index p = 0; p < num_cols; ++p) {
1527 s += A(i, p) * B(p, j);
1539template<
typename S,
typename T, Index M, Index N>
1541Matrix<typename Promote<S, T>::type, M, N>
1553 C(num_rows, num_cols);
1555 for (
Index i = 0; i < num_rows; ++i) {
1556 for (
Index j = 0; j < num_cols; ++j) {
1558 typename Promote<S, T>::type
1561 for (
Index p = 0; p < num_rows; ++p) {
1562 s += A(i, p) * B(p, j);
1574template<
typename S,
typename T, Index M, Index P, Index N>
1576Matrix<typename Promote<S, T>::type, M, N>
1591 C(num_rows, num_cols);
1593 for (
Index i = 0; i < num_rows; ++i) {
1594 for (
Index j = 0; j < num_cols; ++j) {
1596 typename Promote<S, T>::type
1599 for (
Index p = 0; p < dimension; ++p) {
1600 s += A(i, p) * B(p, j);
1612template<
typename S,
typename T, Index M, Index P, Index N>
1614Matrix<typename Promote<S, T>::type, M, N>
1629 C(num_rows, num_cols);
1631 for (
Index i = 0; i < num_rows; ++i) {
1632 for (
Index j = 0; j < num_cols; ++j) {
1634 typename Promote<S, T>::type
1637 for (
Index p = 0; p < dimension; ++p) {
1638 s += A(p, i) * B(p, j);
1650template<
typename S,
typename T, Index M, Index P, Index N>
1652Matrix<typename Promote<S, T>::type, M, N>
1667 C(num_rows, num_cols);
1669 for (
Index i = 0; i < num_rows; ++i) {
1670 for (
Index j = 0; j < num_cols; ++j) {
1672 typename Promote<S, T>::type
1675 for (
Index p = 0; p < dimension; ++p) {
1676 s += A(i, p) * B(j, p);
1691template<
typename S,
typename T, Index M, Index P, Index N>
1693Matrix<typename Promote<S, T>::type, M, N>
1708 C(num_rows, num_cols);
1710 for (
Index i = 0; i < num_rows; ++i) {
1711 for (
Index j = 0; j < num_cols; ++j) {
1713 typename Promote<S, T>::type
1716 for (
Index p = 0; p < dimension; ++p) {
1717 s += A(p, i) * B(j, p);
1729template<
typename S,
typename T, Index M, Index N>
1731typename Promote<S, T>::type
1743 typename Promote<S, T>::type
1746 for (
Index p = 0; p < num_rows; ++p) {
1747 for (
Index q = 0; q < num_cols; ++q) {
1748 s += A(p, q) * B(p, q);
1758template<
typename S,
typename T, Index M, Index N>
1760Matrix<typename Promote<S, T>::type, M, N>
1770 A(num_rows, num_cols);
1772 for (
Index i = 0; i < num_rows; ++i) {
1774 typename Promote<S, T>::type
const
1777 for (
Index j = 0; j < num_cols; ++j) {
1788template<
typename T, Index M, Index N>
1800 B(num_rows, num_cols);
1802 for (
Index i = 0; i < num_rows; ++i) {
1803 for (
Index j = i + 1; j < num_cols; ++j) {
1817template<
typename T, Index M, Index N>
1827 for (
Index i = 0; i < num_rows; ++i) {
1828 for (
Index j = 0; j < num_cols; ++j) {
1839template<
typename T, Index M, Index N>
1850 dimension = num_rows * num_cols;
1852 if (dimension == 0) {
1856 os << std::scientific << std::setprecision(17);
1858 for (
Index i = 0; i < num_rows; ++i) {
1860 os << std::setw(24) << A(i,0);
1862 for (
Index j = 1; j < num_cols; ++j) {
1863 os <<
"," << std::setw(24) << A(i,j);
#define KOKKOS_INLINE_FUNCTION
static KOKKOS_INLINE_FUNCTION constexpr Index get_order()
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > operator+(Matrix< S, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION void minus(TensorBase< T, ST > const &A, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > operator-(Matrix< S, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION T const & operator()(Index const i, Index const j) const
std::ostream & operator<<(std::ostream &os, Matrix< T, M, N > const &A)
KOKKOS_INLINE_FUNCTION void add(TensorBase< R, SR > const &A, TensorBase< S, SS > const &B, TensorBase< T, ST > &C)
KOKKOS_INLINE_FUNCTION Matrix()
static constexpr bool IS_DYNAMIC
std::istream & operator>>(std::istream &is, Matrix< T, M, N > &A)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > operator/(Matrix< T, M, N > const &A, S const &s)
KOKKOS_INLINE_FUNCTION Vector< typename Promote< S, T >::type, M > operator*(Matrix< T, M, N > const &A, Vector< S, N > const &u)
KOKKOS_INLINE_FUNCTION Promote< S, T >::type dotdot(Matrix< S, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > t_dot_t(Matrix< S, P, M > const &A, Matrix< T, N, P > const &B)
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION bool equal(TensorBase< T, ST > const &A, TensorBase< T, ST > const &B)
KOKKOS_INLINE_FUNCTION Vector< T, M > col(Matrix< T, M, N > const &A, Index const j)
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > dot_t(Matrix< S, M, P > const &A, Matrix< T, N, P > const &B)
static constexpr Index ORDER
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > matrix(Vector< S, M > const &u, Vector< T, N > const &v)
KOKKOS_INLINE_FUNCTION void scale(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION bool operator!=(Matrix< T, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Matrix< T, M, N > adjoint(Matrix< T, N, M > const &A)
KOKKOS_INLINE_FUNCTION void set_dimensions(Index const rows, Index const cols)
KOKKOS_INLINE_FUNCTION bool operator==(Matrix< T, M, N > const &A, Matrix< T, M, N > const &B)
KOKKOS_INLINE_FUNCTION Vector< typename Promote< S, T >::type, M > dot(Matrix< T, M, N > const &A, Vector< S, N > const &u)
KOKKOS_INLINE_FUNCTION Index get_num_cols() const
KOKKOS_INLINE_FUNCTION void split(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION Index get_num_rows() const
std::pair< Index, Index > get_dimensions() const
KOKKOS_INLINE_FUNCTION Matrix< typename Promote< S, T >::type, M, N > t_dot(Matrix< S, P, M > const &A, Matrix< T, P, N > const &B)
KOKKOS_INLINE_FUNCTION bool not_equal(TensorBase< T, ST > const &A, TensorBase< T, ST > const &B)
KOKKOS_INLINE_FUNCTION void set_dimension(Index const dimension, Index const order)
KOKKOS_INLINE_FUNCTION Matrix< T, M, N > transpose(Matrix< T, N, M > const &A)
virtual KOKKOS_INLINE_FUNCTION ~Matrix()
KOKKOS_INLINE_FUNCTION void divide(TensorBase< R, SR > const &A, S const &s, TensorBase< T, ST > &B)
KOKKOS_INLINE_FUNCTION Vector< T, N > row(Matrix< T, M, N > const &A, Index const i)
KOKKOS_INLINE_FUNCTION void subtract(TensorBase< R, SR > const &A, TensorBase< S, SS > const &B, TensorBase< T, ST > &C)
uint32_t Index
Indexing type.
constexpr Index DYNAMIC
Indicator for dynamic storage.