41 template<
typename ResultDataType,
typename LhsDataType,
typename LhsMatrixType>
42 void Multiply(NekMatrix<ResultDataType, StandardMatrixTag>& result,
43 const NekMatrix<LhsDataType, LhsMatrixType>&
lhs,
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;
61 NekMatrix<typename NekMatrix<LhsDataType,
LhsMatrixType>::NumberType, StandardMatrixTag>
65 typedef typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType ResultDataType;
66 NekMatrix<ResultDataType, StandardMatrixTag> result(lhs.GetRows(), lhs.GetColumns());
74 void Multiply(NekMatrix<ResultDataType, StandardMatrixTag>& result,
75 const ResultDataType&
lhs,
76 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
85 NekMatrix<typename NekMatrix<RhsDataType,
RhsMatrixType>::NumberType, StandardMatrixTag>
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);
138 const NekMatrix<LhsDataType, LhsMatrixType>& lhs,
139 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
147 const NekMatrix<LhsDataType, LhsMatrixType>& lhs,
148 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
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)
169 void AddEqual(NekMatrix<DataType, StandardMatrixTag>& result,
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>
191 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
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);
214 void Add(NekMatrix<DataType, StandardMatrixTag>& result,
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>
236 const NekMatrix<LhsDataType, LhsMatrixType>& lhs,
237 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
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);
260 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType, StandardMatrixTag>
261 Add(const NekMatrix<LhsDataType, LhsMatrixType>& lhs,
264 typedef typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType NumberType;
265 NekMatrix<NumberType, StandardMatrixTag> result(lhs.GetRows(), lhs.GetColumns());
266 Add(result, lhs, rhs);
273 void Subtract(NekMatrix<DataType, StandardMatrixTag>& result,
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>
295 const NekMatrix<LhsDataType, LhsMatrixType>& lhs,
296 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
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);
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>
341 const NekMatrix<RhsDataType, RhsMatrixType>& rhs)
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);
363 NekMatrix<typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType, StandardMatrixTag>
364 Subtract(const NekMatrix<LhsDataType, LhsMatrixType>& lhs,
367 typedef typename NekMatrix<LhsDataType, LhsMatrixType>::NumberType NumberType;
368 NekMatrix<NumberType, StandardMatrixTag> result(lhs.GetRows(), lhs.GetColumns());