-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SmallMatrix: Matrix class with compile time size
Add amrex::SmallMatrix class with compile time size.
- Loading branch information
1 parent
6d9c25b
commit 5c6ce39
Showing
12 changed files
with
683 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef AMREX_CONSTEXPR_FOR_H_ | ||
#define AMREX_CONSTEXPR_FOR_H_ | ||
#include <AMReX_Config.H> | ||
|
||
#include <AMReX_GpuQualifiers.H> | ||
#include <AMReX_Extension.H> | ||
|
||
#include <type_traits> | ||
|
||
namespace amrex { | ||
|
||
// Implementation of "constexpr for" based on | ||
// https://artificial-mind.net/blog/2020/10/31/constexpr-for | ||
// | ||
// Approximates what one would get from a compile-time | ||
// unrolling of the loop | ||
// for (int i = 0; i < N; ++i) { | ||
// f(i); | ||
// } | ||
// | ||
// The mechanism is recursive: we evaluate f(i) at the current | ||
// i and then call the for loop at i+1. f() is a lambda function | ||
// that provides the body of the loop and takes only an integer | ||
// i as its argument. | ||
|
||
template<auto I, auto N, class F> | ||
AMREX_GPU_HOST_DEVICE AMREX_INLINE | ||
constexpr void constexpr_for (F const& f) | ||
{ | ||
if constexpr (I < N) { | ||
f(std::integral_constant<decltype(I), I>()); | ||
constexpr_for<I+1, N>(f); | ||
} | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.