41 template<
typename ResultDataType,
typename LhsDataType,
typename LhsMatrixType>
44 const ResultDataType& rhs)
47 int n = lhs.GetRows();
48 int m = lhs.GetColumns();
49 for(
unsigned int i = 0; i < n; ++i)
51 for(
unsigned int j = 0; j < m; ++j)
53 result(i,j) =
lhs(i,j)*rhs;
75 const ResultDataType&
lhs,
76 const
NekMatrix<RhsDataType, RhsMatrixType>& rhs)
97 typename boost::call_traits<LhsDataType>::const_reference rhs)
100 for( iterator iter = lhs.begin(); iter != lhs.end(); ++iter)
108 template<typename ResultType, typename LhsDataType, typename
RhsDataType,
111 const
NekMatrix<LhsDataType, LhsMatrixType>& lhs,
114 ASSERTL1(lhs.GetColumns() == rhs.GetRows(), std::string(
"A left side matrix with column count ") +
115 boost::lexical_cast<std::string>(lhs.GetColumns()) +
116 std::string(
" and a right side matrix with row count ") +
117 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be multiplied."));
119 for(
unsigned int i = 0; i < result.GetRows(); ++i)
121 for(
unsigned int j = 0; j < result.GetColumns(); ++j)
123 ResultType t = ResultType(0);
126 for(
unsigned int k = 0; k < lhs.GetColumns(); ++k)
128 t +=
lhs(i,k)*rhs(k,j);
150 ASSERTL1(lhs.GetColumns() == rhs.GetRows(), std::string(
"A left side matrix with column count ") +
151 boost::lexical_cast<std::string>(lhs.GetColumns()) +
152 std::string(
" and a right side matrix with row count ") +
153 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be multiplied."));
155 result.
SetSize(lhs.GetRows(), rhs.GetColumns());
156 if( lhs.GetType() ==
eFULL && rhs.GetType() ==
eFULL)
168 template<typename DataType, typename RhsDataType, typename
RhsMatrixType>
172 ASSERTL1(result.GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
173 boost::lexical_cast<std::string>(result.GetRows()) + std::string(
" and ") +
174 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be added."));
175 ASSERTL1(result.GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
176 boost::lexical_cast<std::string>(result.GetColumns()) + std::string(
" and ") +
177 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be added."));
179 for(
unsigned int i = 0; i < rhs.GetRows(); ++i)
181 for(
unsigned int j = 0; j < rhs.GetColumns(); ++j)
183 result(i,j) += rhs(i,j);
189 template<
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
193 ASSERTL1(result.
GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
194 boost::lexical_cast<std::string>(result.
GetRows()) + std::string(
" and ") +
195 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be added."));
196 ASSERTL1(result.
GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
197 boost::lexical_cast<std::string>(result.
GetColumns()) + std::string(
" and ") +
198 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be added."));
200 for(
unsigned int i = 0; i < rhs.GetRows(); ++i)
202 for(
unsigned int j = 0; j < rhs.GetColumns(); ++j)
204 result(i,j) = -result(i,j) + rhs(i,j);
213 template<typename DataType, typename LhsDataType, typename LhsMatrixType, typename RhsDataType, typename
RhsMatrixType>
215 const
NekMatrix<LhsDataType, LhsMatrixType>& lhs,
218 ASSERTL1(lhs.GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
219 boost::lexical_cast<std::string>(lhs.GetRows()) + std::string(
" and ") +
220 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be added."));
221 ASSERTL1(lhs.GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
222 boost::lexical_cast<std::string>(lhs.GetColumns()) + std::string(
" and ") +
223 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be added."));
225 for(
unsigned int i = 0; i < lhs.GetRows(); ++i)
227 for(
unsigned int j = 0; j < lhs.GetColumns(); ++j)
229 result(i,j) =
lhs(i,j) + rhs(i,j);
234 template<
typename DataType,
typename LhsDataType,
typename LhsMatrixType,
typename RhsDataType,
typename RhsMatrixType>
239 ASSERTL1(lhs.GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
240 boost::lexical_cast<std::string>(lhs.GetRows()) + std::string(
" and ") +
241 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be added."));
242 ASSERTL1(lhs.GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
243 boost::lexical_cast<std::string>(lhs.GetColumns()) + std::string(
" and ") +
244 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be added."));
246 for(
unsigned int i = 0; i < lhs.GetRows(); ++i)
248 for(
unsigned int j = 0; j < lhs.GetColumns(); ++j)
250 result(i,j) = -
lhs(i,j) + rhs(i,j);
259 template<typename LhsDataType, typename LhsMatrixType, typename RhsDataType, typename
RhsMatrixType>
260 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType, StandardMatrixTag>
266 Add(result, lhs, rhs);
272 template<typename DataType, typename LhsDataType, typename LhsMatrixType, typename RhsDataType, typename
RhsMatrixType>
274 const
NekMatrix<LhsDataType, LhsMatrixType>& lhs,
277 ASSERTL1(lhs.GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
278 boost::lexical_cast<std::string>(lhs.GetRows()) + std::string(
" and ") +
279 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be subtracted."));
280 ASSERTL1(lhs.GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
281 boost::lexical_cast<std::string>(lhs.GetColumns()) + std::string(
" and ") +
282 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be subtracted."));
284 for(
unsigned int i = 0; i < lhs.GetRows(); ++i)
286 for(
unsigned int j = 0; j < lhs.GetColumns(); ++j)
288 result(i,j) =
lhs(i,j) - rhs(i,j);
293 template<
typename DataType,
typename LhsDataType,
typename LhsMatrixType,
typename RhsDataType,
typename RhsMatrixType>
298 ASSERTL1(lhs.GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
299 boost::lexical_cast<std::string>(lhs.GetRows()) + std::string(
" and ") +
300 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be subtracted."));
301 ASSERTL1(lhs.GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
302 boost::lexical_cast<std::string>(lhs.GetColumns()) + std::string(
" and ") +
303 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be subtracted."));
305 for(
unsigned int i = 0; i < lhs.GetRows(); ++i)
307 for(
unsigned int j = 0; j < lhs.GetColumns(); ++j)
309 result(i,j) = -
lhs(i,j) - rhs(i,j);
319 template<typename DataType, typename RhsDataType, typename
RhsMatrixType>
323 ASSERTL1(result.GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
324 boost::lexical_cast<std::string>(result.GetRows()) + std::string(
" and ") +
325 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be subtracted."));
326 ASSERTL1(result.GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
327 boost::lexical_cast<std::string>(result.GetColumns()) + std::string(
" and ") +
328 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be subtracted."));
330 for(
unsigned int i = 0; i < rhs.GetRows(); ++i)
332 for(
unsigned int j = 0; j < rhs.GetColumns(); ++j)
334 result(i,j) -= rhs(i,j);
339 template<
typename DataType,
typename RhsDataType,
typename RhsMatrixType>
343 ASSERTL1(result.
GetRows() == rhs.GetRows(), std::string(
"Matrices with different row counts ") +
344 boost::lexical_cast<std::string>(result.
GetRows()) + std::string(
" and ") +
345 boost::lexical_cast<std::string>(rhs.GetRows()) + std::string(
" can't be subtracted."));
346 ASSERTL1(result.
GetColumns() == rhs.GetColumns(), std::string(
"Matrices with different column counts ") +
347 boost::lexical_cast<std::string>(result.
GetColumns()) + std::string(
" and ") +
348 boost::lexical_cast<std::string>(rhs.GetColumns()) + std::string(
" can't be subtracted."));
350 for(
unsigned int i = 0; i < rhs.GetRows(); ++i)
352 for(
unsigned int j = 0; j < rhs.GetColumns(); ++j)
354 result(i,j) = -result(i,j) - rhs(i,j);
362 template<typename LhsDataType, typename LhsMatrixType, typename RhsDataType, typename
RhsMatrixType>
363 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType, StandardMatrixTag>
void SubtractNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void MultiplyEqual(NekMatrix< LhsDataType, StandardMatrixTag > &lhs, typename boost::call_traits< LhsDataType >::const_reference rhs)
NEKTAR_GENERATE_EXPLICIT_FUNCTION_INSTANTIATION_TWO_MATRICES(Multiply, NEKTAR_ALL_MATRIX_TYPES, NEKTAR_ALL_MATRIX_TYPES,(1,(void)),(1,(DNekMat &)),(0,())) template< typename DataType
void NekMultiplyFullMatrixFullMatrix(NekMatrix< ResultType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
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)
void SubtractEqualNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
NekMatrix< NekDouble, StandardMatrixTag > DNekMat
void AddNegatedLhs(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
RhsMatrixType void NekMultiplyDefaultImpl(NekMatrix< ResultType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
unsigned int GetRows() const
void SetSize(unsigned int rows, unsigned int cols)
NEKTAR_GENERATE_EXPLICIT_FUNCTION_INSTANTIATION_SINGLE_MATRIX(Multiply, NEKTAR_ALL_MATRIX_TYPES,(1,(void)),(1,(DNekMat &)),(1,(const NekDouble &))) template< typename DataType
DNekMat void Add(NekMatrix< DataType, StandardMatrixTag > &result, const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &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...