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
5e74ef3e
Commit
5e74ef3e
authored
3 weeks ago
by
Simon Praetorius
Browse files
Options
Downloads
Patches
Plain Diff
Fix for DiagonalMatrix * OtherMatrix
parent
95b4edaa
No related branches found
Branches containing commit
No related tags found
1 merge request
!1479
Fix for DiagonalMatrix * OtherMatrix
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dune/common/diagonalmatrix.hh
+61
-1
61 additions, 1 deletion
dune/common/diagonalmatrix.hh
dune/common/test/diagonalmatrixtest.cc
+15
-0
15 additions, 0 deletions
dune/common/test/diagonalmatrixtest.cc
dune/common/test/transposetest.cc
+2
-2
2 additions, 2 deletions
dune/common/test/transposetest.cc
with
78 additions
and
3 deletions
dune/common/diagonalmatrix.hh
+
61
−
1
View file @
5e74ef3e
...
...
@@ -20,10 +20,13 @@
#include
<dune/common/boundschecking.hh>
#include
<dune/common/densematrix.hh>
#include
<dune/common/dynmatrix.hh>
#include
<dune/common/exceptions.hh>
#include
<dune/common/fmatrix.hh>
#include
<dune/common/ftraits.hh>
#include
<dune/common/fvector.hh>
#include
<dune/common/genericiterator.hh>
#include
<dune/common/matrixconcepts.hh>
#include
<dune/common/typetraits.hh>
...
...
@@ -473,7 +476,39 @@ namespace Dune {
return
result
;
}
/**
* \brief Multiply a diagonal matrix with a dense matrix.
*
* The result of this multiplication is either a `FieldMatrix` if the
* `matrixB` is a matrix with static size, or a `DynamicMatrix`. This
* overload is deactivated for `matrixB` being a `FieldMatrix` since this
* is already covered by the corresponding overload of the `operator*` in
* the `FieldMatrix` class.
*/
template
<
class
OtherMatrix
,
std
::
enable_if_t
<
(
Impl
::
IsDenseMatrix
<
OtherMatrix
>
::
value
),
int
>
=
0
,
std
::
enable_if_t
<
(
not
Impl
::
IsFieldMatrix
<
OtherMatrix
>::
value
),
int
>
=
0
>
friend
auto
operator
*
(
const
DiagonalMatrix
&
matrixA
,
const
OtherMatrix
&
matrixB
)
{
using
OtherField
=
typename
FieldTraits
<
OtherMatrix
>::
field_type
;
using
F
=
typename
PromotionTraits
<
field_type
,
OtherField
>::
PromotedType
;
auto
result
=
[
&
]{
if
constexpr
(
Impl
::
IsStaticSizeMatrix_v
<
OtherMatrix
>
)
{
static_assert
(
n
==
OtherMatrix
::
rows
);
return
FieldMatrix
<
F
,
n
,
OtherMatrix
::
cols
>
{};
}
else
{
assert
(
n
==
matrixB
.
N
());
return
DynamicMatrix
<
F
>
{
n
,
matrixB
.
M
()};
}
}();
for
(
int
i
=
0
;
i
<
result
.
N
();
++
i
)
for
(
int
j
=
0
;
j
<
result
.
M
();
++
j
)
result
[
i
][
j
]
=
matrixA
.
diagonal
(
i
)
*
matrixB
[
i
][
j
];
return
result
;
}
//===== sizes
...
...
@@ -640,6 +675,31 @@ namespace Dune {
return
DiagonalMatrix
<
typename
PromotionTraits
<
K
,
OtherScalar
>::
PromotedType
,
1
>
{
matrixA
.
diagonal
(
0
)
*
matrixB
.
diagonal
(
0
)};
}
template
<
class
OtherMatrix
,
std
::
enable_if_t
<
(
Impl
::
IsDenseMatrix
<
OtherMatrix
>
::
value
),
int
>
=
0
,
std
::
enable_if_t
<
(
not
Impl
::
IsFieldMatrix
<
OtherMatrix
>::
value
),
int
>
=
0
>
friend
auto
operator
*
(
const
DiagonalMatrix
&
matrixA
,
const
OtherMatrix
&
matrixB
)
{
using
OtherField
=
typename
FieldTraits
<
OtherMatrix
>::
field_type
;
using
F
=
typename
PromotionTraits
<
K
,
OtherField
>::
PromotedType
;
auto
result
=
[
&
]{
if
constexpr
(
Impl
::
IsStaticSizeMatrix_v
<
OtherMatrix
>
)
{
static_assert
(
1
==
OtherMatrix
::
rows
);
return
FieldMatrix
<
F
,
1
,
OtherMatrix
::
cols
>
{};
}
else
{
assert
(
1
==
matrixB
.
N
());
return
DynamicMatrix
<
F
>
{
1
,
matrixB
.
M
()};
}
}();
for
(
int
i
=
0
;
i
<
result
.
N
();
++
i
)
for
(
int
j
=
0
;
j
<
result
.
M
();
++
j
)
result
[
i
][
j
]
=
matrixA
.
diagonal
(
i
)
*
matrixB
[
i
][
j
];
return
result
;
}
};
#endif
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/diagonalmatrixtest.cc
+
15
−
0
View file @
5e74ef3e
...
...
@@ -9,9 +9,11 @@
#include
<iostream>
#include
<algorithm>
#include
<dune/common/dynmatrix.hh>
#include
<dune/common/exceptions.hh>
#include
<dune/common/fvector.hh>
#include
<dune/common/diagonalmatrix.hh>
#include
<dune/common/transpose.hh>
#include
"checkmatrixinterface.hh"
...
...
@@ -64,6 +66,19 @@ void test_matrix()
DiagonalMatrix
<
K
,
n
>
AT
=
A
.
transposed
();
if
(
AT
!=
A
)
DUNE_THROW
(
FMatrixError
,
"Return value of DiagoalMatrix::transposed() incorrect!"
);
// check matrix-matrix multiplication
[[
maybe_unused
]]
auto
AA
=
A
*
A
;
[[
maybe_unused
]]
auto
AF
=
A
*
AFM
;
[[
maybe_unused
]]
auto
FA
=
AFM
*
A
;
[[
maybe_unused
]]
auto
AFt
=
A
*
transposedView
(
AFM
);
[[
maybe_unused
]]
auto
FtA
=
transposedView
(
AFM
)
*
A
;
Dune
::
DynamicMatrix
<
K
>
ADM
(
n
,
n
);
[[
maybe_unused
]]
auto
AD
=
A
*
ADM
;
// [[maybe_unused]] auto DA = ADM * A;
[[
maybe_unused
]]
auto
ADt
=
A
*
transposedView
(
ADM
);
// [[maybe_unused]] auto DtA = transposedView(ADM) * A;
}
template
<
class
K
,
int
n
>
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/transposetest.cc
+
2
−
2
View file @
5e74ef3e
...
...
@@ -260,7 +260,7 @@ int main()
testFillDense
(
b
);
checkTranspose
(
suite
,
a
);
checkTranspose
(
suite
,
b
);
//
checkTransposeProduct(suite,a,b);
checkTransposeProduct
(
suite
,
a
,
b
);
}
{
...
...
@@ -270,7 +270,7 @@ int main()
testFillDense
(
b
);
checkTranspose
(
suite
,
a
);
checkTranspose
(
suite
,
b
);
//
checkTransposeProduct(suite,a,b);
checkTransposeProduct
(
suite
,
a
,
b
);
}
{
...
...
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