35 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_OPERATIONS_DECLARATIONS_HPP 36 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_OPERATIONS_DECLARATIONS_HPP 38 #include <boost/core/ignore_unused.hpp> 52 #include <type_traits> 59 template <
typename DataType,
typename LhsDataType,
typename MatrixType>
60 NekVector<DataType>
Multiply(
const NekMatrix<LhsDataType, MatrixType> &
lhs,
61 const NekVector<DataType> &
rhs);
63 template <
typename DataType,
typename LhsDataType,
typename MatrixType>
64 void Multiply(NekVector<DataType> &result,
65 const NekMatrix<LhsDataType, MatrixType> &
lhs,
66 const NekVector<DataType> &
rhs);
68 template <
typename DataType,
typename LhsInnerMatrixType>
69 void Multiply(NekVector<DataType> &result,
70 const NekMatrix<LhsInnerMatrixType, BlockMatrixTag> &
lhs,
71 const NekVector<DataType> &
rhs);
73 template <
typename DataType,
typename LhsDataType,
typename MatrixType>
90 template <
typename ResultDataType,
typename LhsDataType,
typename LhsMatrixType>
93 const ResultDataType &rhs);
95 template <
typename DataType,
typename LhsDataType,
typename LhsMatrixType>
100 template <
typename RhsDataType,
typename RhsMatrixType,
typename ResultDataType>
102 const ResultDataType &lhs,
105 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
110 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
118 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
126 template <
typename LhsDataType>
129 typename boost::call_traits<LhsDataType>::const_reference rhs);
141 typename std::enable_if<
146 boost::ignore_unused(
p);
149 "Only full matrices are supported.");
151 unsigned int M = lhs.GetRows();
152 unsigned int N = rhs.GetColumns();
153 unsigned int K = lhs.GetColumns();
155 unsigned int LDA = M;
156 if (lhs.GetTransposeFlag() ==
'T')
161 unsigned int LDB = K;
162 if (rhs.GetTransposeFlag() ==
'T')
167 Blas::Dgemm(lhs.GetTransposeFlag(), rhs.GetTransposeFlag(), M, N, K,
168 lhs.Scale() * rhs.Scale(), lhs.GetRawPtr(), LDA,
169 rhs.GetRawPtr(), LDB, 0.0, result.GetRawPtr(),
179 template <
typename RhsInnerType,
typename RhsMatrixType>
183 typename std::enable_if<
190 boost::ignore_unused(t);
192 "Only full matrices supported.");
193 unsigned int M = result.GetRows();
194 unsigned int N = rhs.GetColumns();
195 unsigned int K = result.GetColumns();
197 unsigned int LDA = M;
198 if (result.GetTransposeFlag() ==
'T')
203 unsigned int LDB = K;
204 if (rhs.GetTransposeFlag() ==
'T')
208 double scale = rhs.Scale();
210 Blas::Dgemm(result.GetTransposeFlag(), rhs.GetTransposeFlag(), M, N, K,
211 scale, result.GetRawPtr(), LDA, rhs.GetRawPtr(), LDB, 0.0,
212 buf.data(), result.GetRows());
213 result.SetSize(result.GetRows(), rhs.GetColumns());
214 result.SwapTempAndDataBuffers();
217 template <
typename DataType,
typename RhsInnerType,
typename RhsMatrixType>
221 typename std::enable_if<
228 boost::ignore_unused(t);
230 std::string(
"A left side matrix with column count ") +
232 std::string(
" and a right side matrix with row count ") +
233 std::to_string(rhs.GetRows()) +
234 std::string(
" can't be multiplied."));
238 for (
unsigned int i = 0; i < result.
GetRows(); ++i)
240 for (
unsigned int j = 0; j < result.
GetColumns(); ++j)
242 DataType t = DataType(0);
245 for (
unsigned int k = 0; k < result.
GetColumns(); ++k)
247 t += result(i, k) *
rhs(k, j);
264 typedef typename std::remove_const<
288 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
307 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
312 return Add(lhs, rhs);
321 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
340 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
344 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
350 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
357 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
void SubtractNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
#define ASSERTL0(condition, msg)
void DiagonalBlockFullScalMatrixMultiply(NekVector< double > &result, const NekMatrix< NekMatrix< NekMatrix< NekDouble, StandardMatrixTag >, ScaledMatrixTag >, BlockMatrixTag > &lhs, const NekVector< double > &rhs)
void MultiplyEqual(NekMatrix< LhsDataType, StandardMatrixTag > &lhs, typename boost::call_traits< LhsDataType >::const_reference rhs)
void NekMultiplyFullMatrixFullMatrix(NekMatrix< ResultType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
static void Dgemm(const char &transa, const char &transb, const int &m, const int &n, const int &k, const double &alpha, const double *a, const int &lda, const double *b, const int &ldb, const double &beta, double *c, const int &ldc)
BLAS level 3: Matrix-matrix multiply C = A x B where A[m x n], B[n x k], C[m x k].
RhsMatrixType void AddEqual(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void Multiply(NekMatrix< ResultDataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const ResultDataType &rhs)
unsigned int GetColumns() const
void AddEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
DNekMat void SubtractEqual(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
NekVector< DataType > operator*(const NekMatrix< LhsDataType, MatrixType > &lhs, const NekVector< DataType > &rhs)
void SubtractEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
#define LIB_UTILITIES_EXPORT
void AddNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
unsigned int GetRows() const
NekMatrix< typename NekMatrix< LhsDataType, LhsMatrixType >::NumberType, StandardMatrixTag > operator-(const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
DNekMat void Add(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
RhsMatrixType void Subtract(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Array< OneD, DataType > operator+(const Array< OneD, DataType > &lhs, size_t offset)
typename RawType< T >::type RawType_t