-
Notifications
You must be signed in to change notification settings - Fork 366
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 (#4176)
Add amrex::SmallMatrix class with compile time size. Useful for, e.g.: - ECP-WarpX/impactx#714 - ECP-WarpX/impactx#702
- Loading branch information
1 parent
f3514e4
commit 4ec03b8
Showing
12 changed files
with
700 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.