Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
amdis-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
amdis
amdis-core
Merge requests
!94
Added flat matrix and vector used for ElementMatrix and ElementVector
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Added flat matrix and vector used for ElementMatrix and ElementVector
feature/flat_mat_vec
into
master
Overview
2
Commits
2
Changes
7
All threads resolved!
Hide all comments
Merged
Praetorius, Simon
requested to merge
feature/flat_mat_vec
into
master
5 years ago
Overview
2
Commits
2
Changes
4
All threads resolved!
Hide all comments
Expand
1
0
Merge request reports
Compare
version 1
version 1
98bd9edc
5 years ago
master (base)
and
latest version
latest version
e3ca2799
2 commits,
5 years ago
version 1
98bd9edc
1 commit,
5 years ago
Show latest version
4 files
+
150
−
39
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/amdis/common/FlatMatrix.hpp
+
47
−
36
Options
#pragma once
#include
<type_traits>
#include
<vector>
namespace
AMDiS
{
/// Dense matrix with row
wise storage in flat data vector
template
<
class
T
>
/// Dense matrix with row
-
wise storage in flat data vector
template
<
class
T
,
class
Allocator
=
std
::
allocator
<
T
>
>
class
FlatMatrix
:
public
std
::
vector
<
T
,
Allocator
>
{
using
Super
=
std
::
vector
<
T
,
Allocator
>
;
public:
using
value_type
=
T
;
using
size_type
=
std
::
size_t
;
using
size_type
=
typename
Super
::
size_type
;
using
reference
=
typename
Super
::
reference
;
using
const_reference
=
typename
Super
::
const_reference
;
private:
template
<
class
Self
>
/// Accessor to a row of the matrix.
template
<
class
Vector
>
struct
AccessProxy
{
template
<
class
S
=
Self
,
std
::
enable_if_t
<
not
std
::
is_const
<
S
>
::
value
,
int
>
=
0
>
value_type
&
operator
[](
size_type
col
)
/// Access the column entry `col` of the row `row_` of this accessor.
/// @{
template
<
class
V
=
Vector
,
std
::
enable_if_t
<
not
std
::
is_const
<
V
>
::
value
,
int
>
=
0
>
reference
operator
[](
size_type
col
)
{
return
self_
->
data_
[
row_
*
self_
->
cols_
+
col
];
return
(
*
vector_
)[
row_
*
cols_
+
col
];
}
value_type
const
&
operator
[](
size_type
col
)
const
const_reference
operator
[](
size_type
col
)
const
{
return
self_
->
data_
[
row_
*
self_
->
cols_
+
col
];
return
(
*
vector_
)[
row_
*
cols_
+
col
];
}
// @}
Self
*
self
_
;
Vector
*
vector
_
;
size_type
row_
;
size_type
cols_
;
};
public
:
/// Default constructor, creates an empty 0x0 matrix.
FlatMatrix
()
=
default
;
/// Construct a new matrix with rows `r` and columns `c` and all values
/// initialized by copies of value `v`.
FlatMatrix
(
size_type
r
,
size_type
c
,
value_type
v
=
{})
:
data_
(
r
*
c
,
v
)
:
Super
(
r
*
c
,
v
)
,
rows_
(
r
)
,
cols_
(
c
)
{}
/// Assign value `s` to all entries of the matrix
FlatMatrix
&
operator
=
(
value_type
s
)
{
data_
.
assign
(
data_
.
size
(),
s
);
Super
::
assign
(
Super
::
size
(),
s
);
return
*
this
;
}
/// Resizes the container to contain r x c elements.
/**
* If the current `rows*cols` is greater than `r*c`, the container is reduced
* to its first `r*c` elements. If the current `rows*cols` is less than `r*c`,
* additional copies of value `v` are appended.
**/
void
resize
(
size_type
r
,
size_type
c
,
value_type
v
=
{})
{
data_
.
resize
(
r
*
c
,
v
);
Super
::
resize
(
r
*
c
,
v
);
rows_
=
r
;
cols_
=
c
;
}
size_type
rows
()
const
/// Return the number of rows of the matrix
size_type
rows
()
const
noexcept
{
return
rows_
;
}
size_type
cols
()
const
/// Return the number of columns of the matrix
size_type
cols
()
const
noexcept
{
return
cols_
;
}
size_type
size
()
const
{
return
data_
.
size
();
}
/// Return the number of entries in the matrix, i.e. `rows*cols`.
using
Super
::
size
;
AccessProxy
<
FlatMatrix
>
operator
[](
size_type
row
)
/// Return accessor to the `row` of the matrix, see \ref AccessProxy
/// @{
AccessProxy
<
Super
>
operator
[](
size_type
row
)
{
return
AccessProxy
<
FlatMatrix
>
{
this
,
row
};
return
AccessProxy
<
Super
>
{
static_cast
<
Super
*>
(
this
)
,
row
,
cols_
};
}
AccessProxy
<
FlatMatrix
const
>
operator
[](
size_type
row
)
const
AccessProxy
<
Super
const
>
operator
[](
size_type
row
)
const
{
return
AccessProxy
<
FlatMatrix
const
>
{
this
,
row
};
return
AccessProxy
<
Super
const
>
{
static_cast
<
Super
const
*>
(
this
)
,
row
,
cols_
};
}
T
const
*
data
()
const
noexcept
{
return
data_
.
data
();
}
T
*
data
()
noexcept
{
return
data_
.
data
();
}
auto
const
begin
()
const
{
return
data_
.
begin
();
}
auto
begin
()
{
return
data_
.
begin
();
}
auto
const
end
()
const
{
return
data_
.
end
();
}
auto
end
()
{
return
data_
.
end
();
}
auto
cbegin
()
{
return
data_
.
cbegin
();
}
auto
cend
()
{
return
data_
.
cend
();
}
/// @}
private
:
std
::
vector
<
value_type
>
data_
;
size_type
rows_
=
0
;
size_type
cols_
=
0
;
};
Loading