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>
81 NekVector<double> &result,
83 NekMatrix<NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>,
85 const NekVector<double> &rhs);
90 NekMatrix<NekMatrix<NekSingle, StandardMatrixTag>, ScaledMatrixTag>,
97 template <
typename ResultDataType,
typename LhsDataType,
typename LhsMatrixType>
98 void Multiply(NekMatrix<ResultDataType, StandardMatrixTag> &result,
99 const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
100 const ResultDataType &rhs);
102 template <
typename DataType,
typename LhsDataType,
typename LhsMatrixType>
103 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
105 Multiply(
const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
const DataType &rhs);
107 template <
typename RhsDataType,
typename RhsMatrixType,
typename ResultDataType>
108 void Multiply(NekMatrix<ResultDataType, StandardMatrixTag> &result,
109 const ResultDataType &lhs,
110 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
112 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
113 NekMatrix<typename NekMatrix<RhsDataType, RhsMatrixType>::NumberType,
115 Multiply(
const DataType &lhs,
const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
117 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
118 NekMatrix<typename NekMatrix<RhsDataType, RhsMatrixType>::NumberType,
125 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
126 NekMatrix<typename NekMatrix<RhsDataType, RhsMatrixType>::NumberType,
133 template <
typename LhsDataType>
135 NekMatrix<LhsDataType, StandardMatrixTag> &lhs,
136 typename boost::call_traits<LhsDataType>::const_reference rhs);
142 template <
typename LhsDataType,
typename RhsDataType,
typename LhsMatrixType,
143 typename RhsMatrixType>
148 typename std::enable_if<
153 boost::ignore_unused(
p);
156 "Only full matrices are supported.");
158 unsigned int M = lhs.GetRows();
159 unsigned int N = rhs.GetColumns();
160 unsigned int K = lhs.GetColumns();
162 unsigned int LDA = M;
163 if (lhs.GetTransposeFlag() ==
'T')
168 unsigned int LDB = K;
169 if (rhs.GetTransposeFlag() ==
'T')
174 Blas::Gemm(lhs.GetTransposeFlag(), rhs.GetTransposeFlag(), M, N, K,
175 lhs.Scale() * rhs.Scale(), lhs.GetRawPtr(), LDA, rhs.GetRawPtr(),
176 LDB, 0.0, result.GetRawPtr(), result.GetRows());
179 template <
typename LhsDataType,
typename RhsDataType,
typename DataType,
180 typename LhsMatrixType,
typename RhsMatrixType>
181 void Multiply(NekMatrix<DataType, StandardMatrixTag> &result,
182 const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
183 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
185 template <
typename RhsInnerType,
typename RhsMatrixType>
189 typename std::enable_if<
191 RhsMatrixType>::NumberType>,
192 RhsInnerType>::value &&
196 boost::ignore_unused(t);
198 "Only full matrices supported.");
199 unsigned int M = result.GetRows();
200 unsigned int N = rhs.GetColumns();
201 unsigned int K = result.GetColumns();
203 unsigned int LDA = M;
204 if (result.GetTransposeFlag() ==
'T')
209 unsigned int LDB = K;
210 if (rhs.GetTransposeFlag() ==
'T')
214 RhsInnerType scale = rhs.Scale();
216 Blas::Gemm(result.GetTransposeFlag(), rhs.GetTransposeFlag(), M, N, K,
217 scale, result.GetRawPtr(), LDA, rhs.GetRawPtr(), LDB, 0.0,
218 buf.data(), result.GetRows());
219 result.SetSize(result.GetRows(), rhs.GetColumns());
220 result.SwapTempAndDataBuffers();
223 template <
typename DataType,
typename RhsInnerType,
typename RhsMatrixType>
227 typename std::enable_if<
229 RhsMatrixType>::NumberType>,
234 boost::ignore_unused(t);
236 std::string(
"A left side matrix with column count ") +
238 std::string(
" and a right side matrix with row count ") +
239 std::to_string(rhs.GetRows()) +
240 std::string(
" can't be multiplied."));
244 for (
unsigned int i = 0; i < result.
GetRows(); ++i)
246 for (
unsigned int j = 0; j < result.
GetColumns(); ++j)
248 DataType t = DataType(0);
251 for (
unsigned int k = 0; k < result.
GetColumns(); ++k)
253 t += result(i, k) * rhs(k, j);
262 template <
typename LhsDataType,
typename RhsDataType,
typename LhsMatrixType,
263 typename RhsMatrixType>
264 NekMatrix<
typename std::remove_const<
265 typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType>::type,
270 typedef typename std::remove_const<
279 template <
typename LhsDataType,
typename RhsDataType,
typename LhsMatrixType,
280 typename RhsMatrixType>
281 NekMatrix<
typename std::remove_const<
282 typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType>::type,
294 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
295 void AddEqual(NekMatrix<DataType, StandardMatrixTag> &result,
296 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
298 template <
typename DataType,
typename LhsDataType,
typename LhsMatrixType,
299 typename RhsDataType,
typename RhsMatrixType>
300 void Add(NekMatrix<DataType, StandardMatrixTag> &result,
301 const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
302 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
304 template <
typename LhsDataType,
typename LhsMatrixType,
typename RhsDataType,
305 typename RhsMatrixType>
306 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
308 Add(
const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
309 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
311 template <
typename LhsDataType,
typename LhsMatrixType,
typename RhsDataType,
312 typename RhsMatrixType>
313 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
318 return Add(lhs, rhs);
321 template <
typename DataType,
typename LhsDataType,
typename LhsMatrixType,
322 typename RhsDataType,
typename RhsMatrixType>
323 void AddNegatedLhs(NekMatrix<DataType, StandardMatrixTag> &result,
324 const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
325 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
327 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
329 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
334 template <
typename DataType,
typename LhsDataType,
typename LhsMatrixType,
335 typename RhsDataType,
typename RhsMatrixType>
336 void Subtract(NekMatrix<DataType, StandardMatrixTag> &result,
337 const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
338 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
340 template <
typename DataType,
typename LhsDataType,
typename LhsMatrixType,
341 typename RhsDataType,
typename RhsMatrixType>
343 const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
344 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
346 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
347 void SubtractEqual(NekMatrix<DataType, StandardMatrixTag> &result,
348 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
350 template <
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
352 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
354 template <
typename LhsDataType,
typename LhsMatrixType,
typename RhsDataType,
355 typename RhsMatrixType>
356 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
358 Subtract(
const NekMatrix<LhsDataType, LhsMatrixType> &lhs,
359 const NekMatrix<RhsDataType, RhsMatrixType> &rhs);
361 template <
typename LhsDataType,
typename LhsMatrixType,
typename RhsDataType,
362 typename RhsMatrixType>
363 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType,
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define LIB_UTILITIES_EXPORT
unsigned int GetRows() const
unsigned int GetColumns() const
static void Gemm(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 op(A)[m x k], op(B)[k x n], C[m x n] DGEMM perfo...
The above copyright notice and this permission notice shall be included.
SNekMat SNekMat void SubtractEqual(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
NekVector< DataType > operator*(const NekMatrix< LhsDataType, MatrixType > &lhs, const NekVector< DataType > &rhs)
void AddEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
SNekMat void AddEqual(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void Subtract(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
Array< OneD, DataType > operator+(const Array< OneD, DataType > &lhs, typename Array< OneD, DataType >::size_type offset)
void Multiply(NekMatrix< ResultDataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const ResultDataType &rhs)
void NekMultiplyFullMatrixFullMatrix(NekMatrix< ResultType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void AddNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void DiagonalBlockFullScalMatrixMultiply(NekVector< double > &result, const NekMatrix< NekMatrix< NekMatrix< NekDouble, StandardMatrixTag >, ScaledMatrixTag >, BlockMatrixTag > &lhs, const NekVector< double > &rhs)
void SubtractEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
typename RawType< T >::type RawType_t
const NekSingle void MultiplyEqual(NekMatrix< LhsDataType, StandardMatrixTag > &lhs, typename boost::call_traits< LhsDataType >::const_reference rhs)
void SubtractNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
NekMatrix< typename NekMatrix< LhsDataType, LhsMatrixType >::NumberType, StandardMatrixTag > operator-(const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
SNekMat SNekMat void Add(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)