Skip to content

Commit cd41845

Browse files
authored
[Type] MatSym: Generalize matrix multiplication functions for non-square matrices (#5765)
[Type] Generalize matrix multiplication functions for non-square matrices
1 parent 0648009 commit cd41845

File tree

1 file changed

+12
-9
lines changed
  • Sofa/framework/Type/src/sofa/type

1 file changed

+12
-9
lines changed

Sofa/framework/Type/src/sofa/type/MatSym.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,14 @@ class MatSym : public VecNoInit<D * (D + 1) / 2, real>
236236
}
237237

238238
//Multiplication by a non symmetric matrix on the right
239-
[[nodiscard]] Mat<D,D,real> SymMatMultiply(const Mat<D,D,real>& m) const
239+
template<sofa::Size C>
240+
[[nodiscard]] Mat<D,C,real> SymMatMultiply(const Mat<D,C,real>& m) const
240241
{
241-
Mat<D,D,real> r(NOINIT);
242+
Mat<D,C,real> r(NOINIT);
242243

243244
for (sofa::Size i = 0; i < D; i++)
244245
{
245-
for (sofa::Size j = 0; j < D; j++)
246+
for (sofa::Size j = 0; j < C; j++)
246247
{
247248
r(i,j) = (*this)(i, 0) * m(0,j);
248249
for (sofa::Size k = 1; k < D; k++)
@@ -254,17 +255,19 @@ class MatSym : public VecNoInit<D * (D + 1) / 2, real>
254255
return r;
255256
}
256257

257-
Mat<D,D,real> operator*(const Mat<D,D,real>& m) const
258+
template<sofa::Size C>
259+
Mat<D,C,real> operator*(const Mat<D,C,real>& m) const
258260
{
259261
return SymMatMultiply(m);
260262
}
261263

262264
//Multiplication by a non symmetric matrix on the left
263-
Mat<D, D, real> MatSymMultiply(const Mat<D, D, real>& m) const
265+
template<sofa::Size L>
266+
Mat<L, D, real> MatSymMultiply(const Mat<L, D, real>& m) const
264267
{
265-
Mat<D, D, real> r(NOINIT);
268+
Mat<L, D, real> r(NOINIT);
266269

267-
for (sofa::Size i = 0; i < D; i++)
270+
for (sofa::Size i = 0; i < L; i++)
268271
{
269272
for (sofa::Size j = 0; j < D; j++)
270273
{
@@ -415,8 +418,8 @@ class MatSym : public VecNoInit<D * (D + 1) / 2, real>
415418
}
416419
};
417420

418-
template <sofa::Size D, class real>
419-
Mat<D, D, real> operator*(const Mat<D, D, real>& a, const MatSym<D, real>& b)
421+
template <sofa::Size L, sofa::Size D, class real>
422+
Mat<L, D, real> operator*(const Mat<L, D, real>& a, const MatSym<D, real>& b)
420423
{
421424
return b.MatSymMultiply(a);
422425
}

0 commit comments

Comments
 (0)