Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
a0cd3b5f
Commit
a0cd3b5f
authored
5 years ago
by
Oliver Sander
Browse files
Options
Downloads
Patches
Plain Diff
Implement matrix-matrix multiplication for FieldMatrix
parent
bb1c92df
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!705
Add various binary operators to DenseVector and DenseMatrix
Pipeline
#21282
passed
5 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
dune/common/fmatrix.hh
+33
-0
33 additions, 0 deletions
dune/common/fmatrix.hh
dune/common/test/fmatrixtest.cc
+15
-0
15 additions, 0 deletions
dune/common/test/fmatrixtest.cc
with
49 additions
and
0 deletions
CHANGELOG.md
+
1
−
0
View file @
a0cd3b5f
...
...
@@ -40,6 +40,7 @@
-
Matrix = Scalar
*
Matrix
-
Matrix = Matrix
*
Scalar
-
Matrix = Matrix / Scalar
-
Matrix = Matrix
*
Matrix
Note that the operators
-
Vector = Vector + Vector
-
Vector = Vector - Vector
...
...
This diff is collapsed.
Click to expand it.
dune/common/fmatrix.hh
+
33
−
0
View file @
a0cd3b5f
...
...
@@ -193,6 +193,25 @@ namespace Dune
return
result
;
}
/** \brief Matrix-matrix multiplication
*/
template
<
class
OtherScalar
,
int
otherCols
>
friend
auto
operator
*
(
const
FieldMatrix
&
matrixA
,
const
FieldMatrix
<
OtherScalar
,
COLS
,
otherCols
>&
matrixB
)
{
FieldMatrix
<
typename
PromotionTraits
<
K
,
OtherScalar
>::
PromotedType
,
ROWS
,
otherCols
>
result
;
for
(
size_type
i
=
0
;
i
<
matrixA
.
mat_rows
();
++
i
)
for
(
size_type
j
=
0
;
j
<
matrixB
.
mat_cols
();
++
j
)
{
result
[
i
][
j
]
=
0
;
for
(
size_type
k
=
0
;
k
<
matrixA
.
mat_cols
();
++
k
)
result
[
i
][
j
]
+=
matrixA
[
i
][
k
]
*
matrixB
[
k
][
j
];
}
return
result
;
}
//! Multiplies M from the left to this matrix, this matrix is not modified
template
<
int
l
>
FieldMatrix
<
K
,
l
,
cols
>
leftmultiplyany
(
const
FieldMatrix
<
K
,
l
,
rows
>&
M
)
const
...
...
@@ -398,6 +417,20 @@ namespace Dune
//===== solve
/** \brief Matrix-matrix multiplication
*/
template
<
class
OtherScalar
,
int
otherCols
>
friend
auto
operator
*
(
const
FieldMatrix
&
matrixA
,
const
FieldMatrix
<
OtherScalar
,
1
,
otherCols
>&
matrixB
)
{
FieldMatrix
<
typename
PromotionTraits
<
K
,
OtherScalar
>::
PromotedType
,
1
,
otherCols
>
result
;
for
(
size_type
j
=
0
;
j
<
matrixB
.
mat_cols
();
++
j
)
result
[
0
][
j
]
=
matrixA
[
0
][
0
]
*
matrixB
[
0
][
j
];
return
result
;
}
//! Multiplies M from the left to this matrix, this matrix is not modified
template
<
int
l
>
FieldMatrix
<
K
,
l
,
1
>
leftmultiplyany
(
const
FieldMatrix
<
K
,
l
,
1
>&
M
)
const
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/fmatrixtest.cc
+
15
−
0
View file @
a0cd3b5f
...
...
@@ -469,6 +469,21 @@ void test_matrix()
DUNE_THROW
(
FMatrixError
,
"Return value of operator-(matrix) incorrect!"
);
}
// Matrix * Matrix
{
auto
transposed
=
[](
const
FM
&
A
)
{
FieldMatrix
<
typename
FM
::
field_type
,
FM
::
cols
,
FM
::
rows
>
AT
;
for
(
int
i
=
0
;
i
<
AT
.
rows
;
i
++
)
for
(
int
j
=
0
;
j
<
AT
.
cols
;
j
++
)
AT
[
i
][
j
]
=
A
[
j
][
i
];
return
AT
;
};
DUNE_UNUSED
auto
product
=
transposed
(
A
)
*
A
;
}
}
{
using
std
::
abs
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment