-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port alpaka phi functions to DataFormats
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef DataFormats_Math_alpaka_deltaPhi_h | ||
#define DataFormats_Math_alpaka_deltaPhi_h | ||
|
||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
|
||
namespace cms::alpakatools { | ||
|
||
// reduce to [-pi,pi] | ||
template <typename TAcc, typename T> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T reduceRange(TAcc const& acc, T x) { | ||
constexpr T o2pi = 1. / (2. * M_PI); | ||
if (alpaka::math::abs(acc, x) <= T(M_PI)) | ||
return x; | ||
T n = alpaka::math::round(acc, x * o2pi); | ||
return x - n * T(2. * M_PI); | ||
} | ||
|
||
template <typename TAcc, typename T> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T phi(TAcc const& acc, T x, T y) { | ||
return reduceRange(acc, M_PI + alpaka::math::atan2(acc, -y, -x)); | ||
} | ||
|
||
template <typename TAcc, typename T> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T deltaPhi(TAcc const& acc, T x1, T y1, T x2, T y2) { | ||
return reduceRange(acc, alpaka::math::atan2(acc, -y2, -x2) - alpaka::math::atan2(acc, -y1, -x1)); | ||
} | ||
|
||
template <typename TAcc, typename T> | ||
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr T deltaPhi(T phi1, T phi2) { | ||
return reduceRange(phi1 - phi2); | ||
} | ||
|
||
} // namespace cms::alpakatools | ||
|
||
#endif |