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
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Timo Koch
dune-common
Commits
02d458b3
Commit
02d458b3
authored
20 years ago
by
Oliver Sander
Browse files
Options
Downloads
Patches
Plain Diff
eine Klasse für dichte dynamische Matrizen
[[Imported from SVN: r528]]
parent
f1706d8b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/matrix.hh
+138
-0
138 additions, 0 deletions
common/matrix.hh
with
138 additions
and
0 deletions
common/matrix.hh
0 → 100644
+
138
−
0
View file @
02d458b3
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_MATRIX_HH__
#define __DUNE_MATRIX_HH__
#include
<vector>
#include
<assert.h>
#include
"simplevector.hh"
namespace
Dune
{
/** \brief A generic dynamic matrix
*/
template
<
class
T
>
class
Matrix
{
public:
/** \brief Create empty matrix */
Matrix
()
:
data
(
0
),
rows_
(
0
),
cols_
(
0
)
{}
/** \brief Create uninitialized matrix of size rows x cols
*/
Matrix
(
int
rows
,
int
cols
)
:
data
(
rows
*
cols
),
rows_
(
rows
),
cols_
(
cols
)
{}
/** \brief Change the matrix size
*
* The way the data is handled is unpredictable.
*/
void
resize
(
int
rows
,
int
cols
)
{
data
.
resize
(
rows
*
cols
);
rows_
=
rows
;
cols_
=
cols
;
}
/** \brief Write a zero into all matrix entries
*/
void
clear
()
{
for
(
unsigned
int
i
=
0
;
i
<
data
.
size
();
i
++
)
data
[
i
]
=
0
;
}
/** \brief The index operator */
T
&
operator
()(
int
row
,
int
col
)
{
assert
(
0
<=
row
&&
row
<
rows_
&&
0
<=
col
&&
col
<
cols_
);
return
data
[
row
*
cols_
+
col
];
}
/** \brief The const index operator */
const
T
&
operator
()(
int
row
,
int
col
)
const
{
assert
(
0
<=
row
&&
row
<
rows_
&&
0
<=
col
&&
col
<
cols_
);
return
data
[
row
*
cols_
+
col
];
}
void
print
()
const
{
for
(
int
row
=
0
;
row
<
rows_
;
row
++
)
{
for
(
int
col
=
0
;
col
<
cols_
;
col
++
)
printf
(
"%g "
,
(
*
this
)(
row
,
col
));
printf
(
"
\n
"
);
}
}
/** \brief Return the number of rows */
int
rows
()
const
{
return
rows_
;
}
/** \brief Return the number of columns */
int
cols
()
const
{
return
cols_
;
}
/** \brief Return the transpose of the matrix */
Matrix
transpose
()
const
{
Matrix
out
(
cols
(),
rows
());
for
(
int
i
=
0
;
i
<
rows
();
i
++
)
for
(
int
j
=
0
;
j
<
cols
();
j
++
)
out
(
j
,
i
)
=
(
*
this
)(
i
,
j
);
return
out
;
}
//! Multiplication of the transposed matrix times a vector
SimpleVector
<
T
>
transposedMult
(
const
SimpleVector
<
T
>&
vec
)
{
assert
(
rows
()
==
vec
.
size
());
SimpleVector
<
T
>
out
(
cols
());
out
=
0
;
for
(
int
i
=
0
;
i
<
out
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
vec
.
size
();
j
++
)
out
[
i
]
+=
(
*
this
)(
j
,
i
)
*
vec
[
j
];
}
return
out
;
}
/// Generic matrix multiplication.
friend
Matrix
<
T
>
operator
*
(
const
Matrix
<
T
>&
m1
,
const
Matrix
<
T
>&
m2
)
{
assert
(
m1
.
cols
()
==
m2
.
rows
());
Matrix
<
T
>
out
(
m1
.
rows
(),
m2
.
cols
());
out
.
clear
();
for
(
int
i
=
0
;
i
<
out
.
rows
();
i
++
)
{
for
(
int
j
=
0
;
j
<
out
.
cols
();
j
++
)
for
(
int
k
=
0
;
k
<
m1
.
cols
();
k
++
)
out
(
i
,
j
)
+=
m1
(
i
,
k
)
*
m2
(
k
,
j
);
}
return
out
;
}
/// Generic matrix-vector multiplication.
friend
SimpleVector
<
T
>
operator
*
(
const
Matrix
<
T
>&
m
,
const
SimpleVector
<
T
>&
vec
)
{
assert
(
m
.
cols
()
==
vec
.
size
());
SimpleVector
<
T
>
out
(
m
.
rows
());
out
=
0
;
for
(
int
i
=
0
;
i
<
out
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
vec
.
size
();
j
++
)
out
[
i
]
+=
m
(
i
,
j
)
*
vec
[
j
];
}
return
out
;
}
protected
:
std
::
vector
<
T
>
data
;
int
rows_
;
int
cols_
;
};
}
// end namespace Dune
#endif
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