Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
usadelndsoc
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JYU Condensed Matter Theory
usadelndsoc
Commits
16ab933a
Commit
16ab933a
authored
2 years ago
by
patavirt
Browse files
Options
Downloads
Patches
Plain Diff
array: deal with alignment
parent
787e93a4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/array.hpp
+34
-2
34 additions, 2 deletions
src/array.hpp
src/main.cpp
+1
-1
1 addition, 1 deletion
src/main.cpp
with
35 additions
and
3 deletions
src/array.hpp
+
34
−
2
View file @
16ab933a
...
...
@@ -181,7 +181,7 @@ namespace detail
/*! Simple data-by-reference strided array class a la Fortran
*/
template
<
typename
Scalar
,
typename
Shape
>
template
<
typename
Scalar
,
typename
Shape
,
size_t
Alignment
=
0
>
class
Array
:
public
std
::
conditional_t
<
Shape
::
fixed
,
detail
::
fixed_base
<
Shape
>
,
detail
::
dynamic_base
<
Shape
>
>
{
private:
...
...
@@ -196,12 +196,28 @@ private:
return
(
n
==
Dynamic
)
?
Eigen
::
Dynamic
:
n
;
}
static
constexpr
int
eigen_alignment
()
{
switch
(
alignment
())
{
case
128
:
return
Eigen
::
Aligned128
;
case
64
:
return
Eigen
::
Aligned64
;
case
32
:
return
Eigen
::
Aligned32
;
case
16
:
return
Eigen
::
Aligned16
;
case
8
:
return
Eigen
::
Aligned8
;
default:
return
Eigen
::
Unaligned
;
}
};
public
:
Array
(
Scalar
*
data
,
size_t
size
,
const
std
::
array
<
size_t
,
Shape
::
ndim
>
shape
)
:
Base
(
shape
),
data_
(
data
)
{
static_assert
(
!
Shape
::
fixed
,
"array shape must not be compile-time fixed"
);
Base
::
data_bounds_check
(
size
);
#ifndef NO_BOUNDS_CHECK
if
(
reinterpret_cast
<
intptr_t
>
(
data
)
%
alignment
()
!=
0
)
throw
std
::
runtime_error
(
"data is not aligned"
);
#endif
}
Array
(
Scalar
*
data
,
size_t
size
)
...
...
@@ -209,6 +225,10 @@ public:
{
static_assert
(
Shape
::
fixed
,
"array shape must be compile-time fixed"
);
Base
::
data_bounds_check
(
size
);
#ifndef NO_BOUNDS_CHECK
if
(
reinterpret_cast
<
intptr_t
>
(
data
)
%
alignment
()
!=
0
)
throw
std
::
runtime_error
(
"data is not aligned"
);
#endif
}
template
<
typename
...
Idx
>
...
...
@@ -229,6 +249,18 @@ public:
Scalar
*
data
()
{
return
data_
;
}
static
constexpr
int
alignment
()
{
if
(
Alignment
>
0
)
return
Alignment
;
else
if
(
sizeof
(
Scalar
)
%
16
==
0
)
return
16
;
else
if
(
sizeof
(
Scalar
)
%
8
==
0
)
return
8
;
else
return
1
;
};
template
<
typename
...
Idx
>
size_t
index
(
Idx
...
idxs
)
const
{
...
...
@@ -281,7 +313,7 @@ public:
}
typedef
Eigen
::
Matrix
<
Scalar
,
eigen_shape
<
0
>
(),
eigen_shape
<
1
>
(),
Eigen
::
RowMajor
>
EigenMatrix
;
typedef
Eigen
::
Map
<
EigenMatrix
>
EigenMap
;
typedef
Eigen
::
Map
<
EigenMatrix
,
eigen_alignment
()
>
EigenMap
;
EigenMap
matrix
()
const
{
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
1
−
1
View file @
16ab933a
...
...
@@ -38,7 +38,7 @@ int main()
mat
=
mat
*
mat
*
mat
;
static_assert
(
std
::
is_same
<
decltype
(
mat
),
Eigen
::
Map
<
Eigen
::
Matrix
<
double
,
2
,
2
,
Eigen
::
RowMajor
>
>
>::
value
,
"wrong type"
);
static_assert
(
std
::
is_same
<
decltype
(
mat
),
Eigen
::
Map
<
Eigen
::
Matrix
<
double
,
2
,
2
,
Eigen
::
RowMajor
>
,
Eigen
::
Aligned8
>
>::
value
,
"wrong type"
);
dump
(
Q0
);
return
0
;
...
...
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